示例#1
0
def test_constructor_version_not_found(workspace):
    config = Config({
        'file': 'fake.py'
    })
    workspace.write('fake.py', '')
    with pytest.raises(BumprError):
        Releaser(config)
示例#2
0
def test_prepare(workspace, mocker):
    config = Config({
        'file': 'fake.py',
        'files': [str(workspace.readme)],
        'prepare': {
            'part': Version.PATCH,
            'suffix': 'dev',
        }
    })
    releaser = Releaser(config)
    hook = mocker.MagicMock()
    mocker.patch.object(releaser, 'hooks', [hook])
    commit = mocker.patch.object(releaser, 'commit')
    tag = mocker.patch.object(releaser, 'tag')

    releaser.prepare()

    assert not commit.called
    assert not tag.called
    assert hook.prepare.called

    for file in workspace.module, workspace.readme:
        with file.open() as f:
            content = f.read()
            assert '1.2.4.dev' in content
            assert '1.2.3' not in content
示例#3
0
def main():
    import sys
    from bumpr import log
    log.init()

    from bumpr.config import Config, ValidationError
    from bumpr.releaser import Releaser
    from bumpr.helpers import BumprError
    from logging import DEBUG, INFO, getLogger

    config = Config.parse_args()
    getLogger().setLevel(DEBUG if config.verbose else INFO)
    logger = getLogger(__name__)

    try:
        config.validate()
    except ValidationError as e:
        msg = 'Invalid configuration: {0}'.format(e)
        logger.error(msg)
        sys.exit(1)

    try:
        releaser = Releaser(config)
        releaser.release()
    except BumprError as error:
        logger.error(str(error))
        sys.exit(1)
示例#4
0
def test_constructor_version_bad_format(workspace):
    config = Config({
        'file': 'fake.py',
    })
    workspace.write('fake.py', '__badversion__ = "1.2.3"')
    with pytest.raises(BumprError):
        Releaser(config)
示例#5
0
 def test_from_dict(self):
     '''It can take a dictionnay as parameter but keeps defaults'''
     config_dict = {
         'module': 'test_module',
         'attribute': 'VERSION',
         'commit': True,
         'tag': True,
         'dryrun': True,
         'files': ['anyfile.py'],
         'bump': {
             'suffix': 'final',
             'message': 'Version {version}',
         },
         'prepare': {
             'part': 'minor',
             'suffix': 'dev',
             'message': 'Update to version {version}',
         },
     }
     config = Config(config_dict)
     expected = deepcopy(DEFAULTS)
     for key, value in config_dict.items():
         if isinstance(value, dict):
             for nested_key, nested_value in value.items():
                 expected[key][nested_key] = nested_value
         else:
             expected[key] = value
     for hook in HOOKS:
         expected[hook.key] = False
     self.assertDictEqual(config, expected)
示例#6
0
 def test_defaults(self):
     '''It should initialize with default values'''
     config = Config()
     expected = deepcopy(DEFAULTS)
     for hook in HOOKS:
         expected[hook.key] = False
     self.assertDictEqual(config, expected)
示例#7
0
 def test_defaults(self):
     """It should initialize with default values"""
     config = Config()
     expected = deepcopy(DEFAULTS)
     for hook in HOOKS:
         expected[hook.key] = False
     assert config == expected
示例#8
0
def test_prepare(workspace, mocker):
    config = Config({
        "file": "fake.py",
        "files": [str(workspace.readme)],
        "prepare": {
            "part": Version.PATCH,
            "suffix": "dev",
        },
    })
    releaser = Releaser(config)
    hook = mocker.MagicMock()
    mocker.patch.object(releaser, "hooks", [hook])
    commit = mocker.patch.object(releaser, "commit")
    tag = mocker.patch.object(releaser, "tag")

    releaser.prepare()

    assert not commit.called
    assert not tag.called
    assert hook.prepare.called

    for file in workspace.module, workspace.readme:
        with file.open() as f:
            content = f.read()
            assert "1.2.4.dev" in content
            assert "1.2.3" not in content
示例#9
0
    def test_override_from_setup_cfg(self):
        with io.open("setup.cfg", "w") as cfg:
            cfg.write(
                "\n".join(
                    [
                        "[bumpr]",
                        "file = test.py",
                        "files = README",
                        "push = true",
                        "[bumpr:bump]",
                        "message = test",
                    ]
                )
            )

        expected = deepcopy(DEFAULTS)
        expected["file"] = "test.py"
        expected["files"] = ["README"]
        expected["push"] = True
        expected["bump"]["message"] = "test"
        for hook in HOOKS:
            expected[hook.key] = False

        config = Config()
        assert config == expected
示例#10
0
    def test_override_args_keeps_config_values(self):
        bumprrc = '''\
        [bumpr]
        files = README
        [bump]
        message = test
        [prepare]
        part = minor
        '''

        with mock_ini(bumprrc) as mock:
            with patch('bumpr.config.exists', return_value=True):
                config = Config.parse_args(['test.py', '-M', '-v', '-s', 'test-suffix', '-c', 'test.rc'])

        expected = deepcopy(DEFAULTS)
        expected['file'] = 'test.py'
        expected['bump']['part'] = Version.MAJOR
        expected['bump']['suffix'] = 'test-suffix'
        expected['verbose'] = True

        expected['files'] = ['README']
        expected['bump']['message'] = 'test'
        expected['prepare']['part'] = Version.MINOR

        for hook in HOOKS:
            expected[hook.key] = False

        self.assertDictEqual(config, expected)
示例#11
0
 def test_from_dict(self):
     """It can take a dictionnay as parameter but keeps defaults"""
     config_dict = {
         "module": "test_module",
         "attribute": "VERSION",
         "commit": True,
         "tag": True,
         "dryrun": True,
         "files": ["anyfile.py"],
         "bump": {
             "suffix": "final",
             "message": "Version {version}",
         },
         "prepare": {
             "part": "minor",
             "suffix": "dev",
             "message": "Update to version {version}",
         },
     }
     config = Config(config_dict)
     expected = deepcopy(DEFAULTS)
     for key, value in config_dict.items():
         if isinstance(value, dict):
             for nested_key, nested_value in value.items():
                 expected[key][nested_key] = nested_value
         else:
             expected[key] = value
     for hook in HOOKS:
         expected[hook.key] = False
     assert config == expected
示例#12
0
    def test_override_args_keeps_config_values(self):
        bumprrc = '''\
        [bumpr]
        files = README
        [bump]
        message = test
        [prepare]
        part = minor
        '''

        with mock_ini(bumprrc) as mock:
            with patch('bumpr.config.exists', return_value=True):
                config = Config.parse_args([
                    'test.py', '-M', '-v', '-s', 'test-suffix', '-c', 'test.rc'
                ])

        expected = deepcopy(DEFAULTS)
        expected['file'] = 'test.py'
        expected['bump']['part'] = Version.MAJOR
        expected['bump']['suffix'] = 'test-suffix'
        expected['verbose'] = True

        expected['files'] = ['README']
        expected['bump']['message'] = 'test'
        expected['prepare']['part'] = Version.MINOR

        for hook in HOOKS:
            expected[hook.key] = False

        self.assertDictEqual(config, expected)
示例#13
0
 def setUp(self, mocker):
     self.releaser = mocker.MagicMock()
     self.releaser.prev_version = Version.parse("1.2.3.dev")
     self.releaser.version = Version.parse("1.2.3")
     self.releaser.next_version = Version.parse("1.2.4.dev")
     self.releaser.timestamp = datetime.now()
     self.releaser.tag_label = "v1.2.3"
     self.releaser.config = Config()
示例#14
0
    def test_commit(self):
        config = Config({'file': 'fake.py', 'vcs': 'fake'})
        with workspace('fake') as wksp:
            releaser = Releaser(config)

        with patch.object(releaser, 'vcs') as vcs:
            releaser.commit('message')
            vcs.commit.assert_called_with('message')
示例#15
0
def test_push_disabled_by_default(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake'})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.push()

    assert not vcs.push.called
示例#16
0
def test_push(workspace, mocker):
    config = Config({"file": "fake.py", "vcs": "fake", "push": True})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, "vcs")

    releaser.push()

    assert vcs.push.called
示例#17
0
def test_tag_no_tag(workspace, mocker):
    config = Config({"file": "fake.py", "vcs": "fake", "tag": False})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, "vcs")

    releaser.tag()

    assert not vcs.tag.called
示例#18
0
def test_commit(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake'})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.commit('message')

    vcs.commit.assert_called_with('message')
示例#19
0
def test_commit_no_commit(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake', 'commit': False})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.commit('message')

    assert not vcs.commit.called
示例#20
0
def test_tag(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake'})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.tag()

    vcs.tag.assert_called_with(str(releaser.version))
示例#21
0
def test_tag_no_tag(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake', 'tag': False})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.tag()

    assert not vcs.tag.called
示例#22
0
def test_tag_custom_pattern(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake', 'tag_format': 'v{version}'})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.tag()

    vcs.tag.assert_called_with('v{0}'.format(releaser.version))
示例#23
0
def test_commit(workspace, mocker):
    config = Config({"file": "fake.py", "vcs": "fake"})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, "vcs")

    releaser.commit("message")

    vcs.commit.assert_called_with("message")
示例#24
0
    def test_tag(self):
        config = Config({'file': 'fake.py', 'vcs': 'fake'})
        with workspace('fake') as wksp:
            releaser = Releaser(config)

        with patch.object(releaser, 'vcs') as vcs:
            releaser.tag()
            vcs.tag.assert_called_with(str(releaser.version))
示例#25
0
def test_tag(workspace, mocker):
    config = Config({"file": "fake.py", "vcs": "fake"})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, "vcs")

    releaser.tag()

    vcs.tag.assert_called_with(str(releaser.version))
示例#26
0
def test_push_no_commit(workspace, mocker):
    config = Config({'file': 'fake.py', 'vcs': 'fake', 'push': True, 'commit': False})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, 'vcs')

    releaser.push()

    assert not vcs.push.called
示例#27
0
def test_push_disabled_by_default(workspace, mocker):
    config = Config({"file": "fake.py", "vcs": "fake"})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, "vcs")

    releaser.push()

    assert not vcs.push.called
示例#28
0
def test_commit_no_commit(workspace, mocker):
    config = Config({"file": "fake.py", "vcs": "fake", "commit": False})
    releaser = Releaser(config)
    vcs = mocker.patch.object(releaser, "vcs")

    releaser.commit("message")

    assert not vcs.commit.called
示例#29
0
def currentBranchAsTag(ctx, branch_name=None, config_file='bumpr.rc'):
    # don't put at module level to avoid the requirements for other tasks
    from bumpr.config import Config
    from bumpr.releaser import Releaser
    import os

    if not branch_name:
        branch_name = os.environ.get('TRAVIS_BRANCH', None)
    if not branch_name:
        ret = ctx.run('git rev-parse --abbrev-ref HEAD | grep -v ^HEAD$ || '
                      'git rev-parse HEAD')
        if not ret.ok:
            raise RuntimeError("Can't get current branch")
        branch_name = ret.stdout.replace('\n', '')
    config = Config()
    config.override_from_config(config_file)
    releaser = Releaser(config)
    releaser.bump_files([(str(releaser.version), branch_name)])
示例#30
0
    def test_force_push_from_args(self):
        config = Config.parse_args(['-c', 'test.rc', '--push'])

        expected = deepcopy(DEFAULTS)
        expected['push'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#31
0
    def test_do_not_override_push_when_not_in_args(self, mocker, mock_ini):
        config = Config.parse_args(['-c', 'test.rc'])

        expected = deepcopy(DEFAULTS)
        expected['push'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#32
0
    def test_do_override_commit(self):
        config = Config.parse_args(['-c', 'test.rc', '-nc'])

        expected = deepcopy(DEFAULTS)
        expected['commit'] = False

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#33
0
    def test_skip_tests_from_args(self):
        config = Config.parse_args(['-c', 'test.rc', '--skip-tests'])

        expected = deepcopy(DEFAULTS)
        expected['skip_tests'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#34
0
    def test_skip_tests_from_args(self):
        config = Config.parse_args(['-c', 'test.rc', '--skip-tests'])

        expected = deepcopy(DEFAULTS)
        expected['skip_tests'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#35
0
    def test_do_override_commit(self):
        config = Config.parse_args(['-c', 'test.rc', '-nc'])

        expected = deepcopy(DEFAULTS)
        expected['commit'] = False

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#36
0
    def test_do_not_override_prepare_only_when_not_in_args(self):
        config = Config.parse_args(['-c', 'test.rc'])

        expected = deepcopy(DEFAULTS)
        expected['prepare_only'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#37
0
    def test_override_hook_from_config(self):
        tested_hook = ReadTheDocHook
        bumprrc = '''\
        [{0}]
        bump = test
        '''.format(tested_hook.key)

        expected = deepcopy(DEFAULTS)
        for hook in HOOKS:
            if hook is tested_hook:
                expected[hook.key] = hook.defaults
                expected[hook.key]['bump'] = 'test'
            else:
                expected[hook.key] = False

        config = Config()
        with mock_ini(bumprrc) as mock:
            config.override_from_config('test.rc')

        mock.assert_called_once_with('test.rc')
        self.assertDictEqual(config, expected)
示例#38
0
    def test_override_from_args(self):
        config = Config.parse_args(['test.py', '-M', '-v', '-s', 'test-suffix', '-c', 'fake'])

        expected = deepcopy(DEFAULTS)
        expected['file'] = 'test.py'
        expected['bump']['part'] = Version.MAJOR
        expected['bump']['suffix'] = 'test-suffix'
        expected['verbose'] = True
        for hook in HOOKS:
            expected[hook.key] = False

        self.assertDictEqual(config, expected)
示例#39
0
    def test_override_from_config(self):
        bumprrc = '''\
        [bumpr]
        file = test.py
        files = README
        [bump]
        message = test
        '''

        expected = deepcopy(DEFAULTS)
        expected['file'] = 'test.py'
        expected['files'] = ['README']
        expected['bump']['message'] = 'test'
        for hook in HOOKS:
            expected[hook.key] = False

        config = Config()
        with mock_ini(bumprrc) as mock:
            config.override_from_config('test.rc')

        mock.assert_called_once_with('test.rc')
        self.assertDictEqual(config, expected)
示例#40
0
    def test_override_from_config(self, mock_ini):
        bumprrc = '''\
        [bumpr]
        file = test.py
        files = README
        push = true
        [bump]
        message = test
        '''

        expected = deepcopy(DEFAULTS)
        expected['file'] = 'test.py'
        expected['files'] = ['README']
        expected['push'] = True
        expected['bump']['message'] = 'test'
        for hook in HOOKS:
            expected[hook.key] = False

        config = Config()
        mock = mock_ini(bumprrc)
        config.override_from_config('test.rc')

        mock.assert_called_once_with('test.rc')
        assert config == expected
示例#41
0
    def test_skip_tests_from_args(self):
        bumprrc = '''\
        [bumpr]
        '''

        with mock_ini(bumprrc):
            with patch('bumpr.config.exists', return_value=True):
                config = Config.parse_args(['-c', 'test.rc', '--skip-tests'])

        expected = deepcopy(DEFAULTS)
        expected['skip_tests'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#42
0
    def test_override_args_keeps_config_values(self):
        config = Config.parse_args(['test.py', '-M', '-v', '-s', 'test-suffix', '-c', 'test.rc'])

        expected = deepcopy(DEFAULTS)
        expected['file'] = 'test.py'
        expected['bump']['part'] = Version.MAJOR
        expected['bump']['suffix'] = 'test-suffix'
        expected['verbose'] = True

        expected['files'] = ['README']
        expected['bump']['message'] = 'test'
        expected['prepare']['part'] = Version.MINOR

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#43
0
    def test_override_push_from_args(self):
        bumprrc = '''\
        [bumpr]
        push = true
        '''

        with mock_ini(bumprrc):
            with patch('bumpr.config.exists', return_value=True):
                config = Config.parse_args(['-c', 'test.rc', '--no-push'])

        expected = deepcopy(DEFAULTS)
        expected['push'] = False

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#44
0
    def test_do_not_override_prepare_only_when_not_in_args(self):
        bumprrc = '''\
        [bumpr]
        prepare_only = True
        '''

        with mock_ini(bumprrc):
            with patch('bumpr.config.exists', return_value=True):
                config = Config.parse_args(['-c', 'test.rc'])

        expected = deepcopy(DEFAULTS)
        expected['prepare_only'] = True

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#45
0
    def test_do_override_commit(self):
        bumprrc = '''\
        [bumpr]
        commit = True
        '''

        with mock_ini(bumprrc):
            with patch('bumpr.config.exists', return_value=True):
                config = Config.parse_args(['-c', 'test.rc', '-nc'])

        expected = deepcopy(DEFAULTS)
        expected['commit'] = False

        for hook in HOOKS:
            expected[hook.key] = False

        assert config == expected
示例#46
0
def main():
    import sys
    from bumpr import log
    log.init()

    from bumpr.config import Config
    from bumpr.releaser import Releaser
    from bumpr.helpers import BumprError
    from logging import DEBUG, INFO, getLogger

    config = Config.parse_args()
    getLogger().setLevel(DEBUG if config.verbose else INFO)
    try:
        releaser = Releaser(config)
        releaser.release()
    except BumprError as error:
        getLogger(__name__).error(error.message)
        sys.exit(1)
示例#47
0
 def test_validate_file_missing(self):
     config = Config()
     with pytest.raises(ValidationError):
         config.validate()
示例#48
0
 def test_validate_file_missing(self):
     config = Config()
     with self.assertRaises(ValidationError):
         config.validate()
示例#49
0
 def test_validate(self):
     config = Config({'file': 'version.py'})
     config.validate()