# Path: punch/version.py
# class Version():
#     def __init__(self):
#     def keys(self):
#     def values(self):
#     def __eq__(self, other):
#     def add_part(self, part):
#     def create_part(self, name, value,
#                     cls=vpart.IntegerVersionPart, *args, **kwds):
#     def add_part_from_dict(self, dic):
#     def get_part(self, name):
#     def _reset_following_parts(self, name):
#     def inc(self, name):
#     def set(self, adict):
#     def set_and_reset(self, name, value):
#     def copy(self):
#     def as_dict(self):
#     def as_list(self):
#     def to_file(self, version_filepath):
#     def from_file(cls, version_filepath, version_description):
#     def _get_version_part(cls, version_module,
#                           version_part, version_part_name):
# 
# Path: punch/version_part.py
# def _strftime(fmt):
# def strftime(fmt):
#     def from_dict(cls, dic):
#     def __init__(self, name, value=None, start_value=None):
#     def inc(self):
#     def set(self, value):
#     def reset(self):
#     def copy(self):
#     def __init__(self, name, value, allowed_values):
#     def set(self, value):
#     def inc(self):
#     def reset(self):
#     def copy(self):
#     def __init__(self, name, value, fmt):
#     def reset(self):
#     def inc(self):
#     def copy(self):
# class VersionPart(object):
# class IntegerVersionPart(VersionPart):
# class ValueListVersionPart(VersionPart):
# class DateVersionPart(VersionPart):
# 
# Path: punch/actions/conditional_reset.py
# class ConditionalResetAction(object):
#     def __init__(self, adict):
#     def process_version(self, version):


import pytest
from punch import version as ver
from punch import version_part as vp
from punch.actions import conditional_reset


def test_conditional_reset_init_with_no_field():
    with pytest.raises(KeyError):
        conditional_reset.ConditionalResetAction({})


def test_conditional_reset_process_version_checks_all_update_fields(mocker):
    mocker.patch('punch.version_part.DateVersionPart.inc')
    v = ver.Version()
    part_year = vp.DateVersionPart('year', 2016, '%Y')
    part_month = vp.DateVersionPart('month', 1, '%m')
    part_build = vp.IntegerVersionPart('build')
    v.add_part(part_year)
    v.add_part(part_month)
    v.add_part(part_build)

    a = conditional_reset.ConditionalResetAction({
        'field': 'build',
        'update_fields': ['year', 'month']
    })

    a.process_version(v)

    assert part_year.inc.called
    assert part_month.inc.called


def test_conditional_reset_process_version_calls_reset_on_field(mocker):
    mocker.patch('punch.version_part.IntegerVersionPart.reset')

# Path: punch/version.py
# class Version():
#     def __init__(self):
#     def keys(self):
#     def values(self):
#     def __eq__(self, other):
#     def add_part(self, part):
#     def create_part(self, name, value,
#                     cls=vpart.IntegerVersionPart, *args, **kwds):
#     def add_part_from_dict(self, dic):
#     def get_part(self, name):
#     def _reset_following_parts(self, name):
#     def inc(self, name):
#     def set(self, adict):
#     def set_and_reset(self, name, value):
#     def copy(self):
#     def as_dict(self):
#     def as_list(self):
#     def to_file(self, version_filepath):
#     def from_file(cls, version_filepath, version_description):
#     def _get_version_part(cls, version_module,
#                           version_part, version_part_name):
# 
# Path: punch/version_part.py
# def _strftime(fmt):
# def strftime(fmt):
#     def from_dict(cls, dic):
#     def __init__(self, name, value=None, start_value=None):
#     def inc(self):
#     def set(self, value):
#     def reset(self):
#     def copy(self):
#     def __init__(self, name, value, allowed_values):
#     def set(self, value):
#     def inc(self):
#     def reset(self):
#     def copy(self):
#     def __init__(self, name, value, fmt):
#     def reset(self):
#     def inc(self):
#     def copy(self):
# class VersionPart(object):
# class IntegerVersionPart(VersionPart):
# class ValueListVersionPart(VersionPart):
# class DateVersionPart(VersionPart):
# 
# Path: punch/actions/conditional_reset.py
# class ConditionalResetAction(object):
#     def __init__(self, adict):
#     def process_version(self, version):


# Path: tests/actions/test_conditional_reset.py
import pytest
from punch import version as ver
from punch import version_part as vp
from punch.actions import conditional_reset



def test_conditional_reset_init_with_no_field():
    with pytest.raises(KeyError):
        conditional_reset.ConditionalResetAction({})


def test_conditional_reset_process_version_checks_all_update_fields(mocker):
    mocker.patch('punch.version_part.DateVersionPart.inc')
    v = ver.Version()
    part_year = vp.DateVersionPart('year', 2016, '%Y')
    part_month = vp.DateVersionPart('month', 1, '%m')
    part_build = vp.IntegerVersionPart('build')
    v.add_part(part_year)
    v.add_part(part_month)
    v.add_part(part_build)

    a = conditional_reset.ConditionalResetAction({
        'field': 'build',
        'update_fields': ['year', 'month']
    })

    a.process_version(v)

    assert part_year.inc.called
    assert part_month.inc.called


def test_conditional_reset_process_version_calls_reset_on_field(mocker):
    mocker.patch('punch.version_part.IntegerVersionPart.reset')

    v = ver.Version()