示例#1
0
    def test_iterate_multiple_files(self):

        def _test(replaced_value, initial_value):
            for version_file in self.version_files_without_excluded:
                with open(version_file) as f:
                    self.assertIn(replaced_value, f.read())
            for version_file in self.excluded_files:
                with open(version_file) as f:
                    self.assertIn(initial_value, f.read())

        # TODO: This is some stupid thing related to formatting on windows
        # The direct invocation with click doesn't work on windows..
        # probably due to some string formatting of the command.
        if os.name == 'nt':
            variables = {'preversion': '3.1.0-m2', 'version': '3.1.0-m3'}
            repex.iterate(MOCK_MULTIPLE_FILES, variables=variables)
        else:
            fd, tmp = tempfile.mkstemp()
            os.close(fd)
            with open(tmp, 'w') as f:
                f.write("version: '3.1.0-m3'")
            try:
                _invoke(
                    "from_config {0} --vars-file={1} "
                    "--var='preversion'='3.1.0-m2'".format(
                        MOCK_MULTIPLE_FILES, tmp))
            finally:
                os.remove(tmp)

        _test('"version": "3.1.0-m3"', '"version": "3.1.0-m2"')
        variables = {'preversion': '3.1.0-m3', 'version': '3.1.0-m2'}
        repex.iterate(MOCK_MULTIPLE_FILES, variables=variables)
        _test('"version": "3.1.0-m2"', '"version": "3.1.0-m2"')
示例#2
0
 def test_iterate_with_vars(self):
     variables = {'version': '3.1.0-m3'}
     repex.iterate(
         config_file_path=MOCK_SINGLE_FILE,
         variables=variables)
     with open(self.single_file_output_file) as f:
         self.assertIn('3.1.0-m3', f.read())
示例#3
0
 def test_no_changes(self):
     variables = {'version': '3.1.0-m2'}
     repex.iterate(
         config_file_path=MOCK_SINGLE_FILE,
         variables=variables,
         with_diff=True)
     assert not os.path.exists(self.diff_dir)
示例#4
0
 def test_iterate_user_tags_no_path_tags(self):
     tags = ['test_tag']
     variables = {'version': '3.1.0-m3'}
     repex.iterate(
         config_file_path=MOCK_SINGLE_FILE,
         variables=variables,
         tags=tags)
     assert not os.path.isfile(self.single_file_output_file)
示例#5
0
    def test_validator(self):
        variables = {'version': '3.1.0-m3'}

        try:
            repex.iterate(
                config=self.validation_config,
                variables=variables)
        finally:
            os.remove(self.single_file_output_file)
示例#6
0
 def test_iterate_path_tags_no_user_tags(self):
     tags = ['test_tag']
     self.single_file_config['paths'][0]['tags'] = tags
     variables = {'version': '3.1.0-m3'}
     repex.iterate(
         config=self.single_file_config,
         variables=variables,
         verbose=True)
     self.assertFalse(os.path.isfile(self.single_file_output_file))
示例#7
0
 def test_iterate_path_tags_user_tags(self):
     tags = ['test_tag']
     self.single_file_config['paths'][0]['tags'] = tags
     variables = {'version': '3.1.0-m3'}
     repex.iterate(
         config=self.single_file_config,
         variables=variables,
         tags=tags)
     with open(self.single_file_output_file) as f:
         assert '3.1.0-m3' in f.read()
示例#8
0
 def test_env_var_based_replacement(self):
     variables = {'version': '3.1.0-m3'}
     os.environ['REPEX_VAR_VERSION'] = '3.1.0-m9'
     try:
         repex.iterate(
             config_file_path=MOCK_SINGLE_FILE,
             variables=variables)
         with open(self.single_file_output_file) as f:
             self.assertIn('3.1.0-m9', f.read())
     finally:
         os.environ.pop('REPEX_VAR_VERSION')
示例#9
0
 def test_iterate_any_tag(self):
     tags = ['test_tag']
     any_tag = ['any']
     self.single_file_config['paths'][0]['tags'] = tags
     variables = {'version': '3.1.0-m3'}
     repex.iterate(
         config=self.single_file_config,
         variables=variables,
         verbose=True,
         tags=any_tag)
     with open(self.single_file_output_file) as f:
         self.assertIn('3.1.0-m3', f.read())
示例#10
0
    def test_single_file(self):
        variables = {'version': '3.1.0-m3'}

        try:
            repex.iterate(
                config_file_path=MOCK_SINGLE_FILE,
                variables=variables,
                with_diff=True)
            self._test()
        finally:
            variables = {'version': '3.1.0-m2'}
            repex.iterate(
                config_file_path=MOCK_SINGLE_FILE,
                variables=variables)
示例#11
0
    def test_failed_validator_per_file(self):
        variables = {'version': '3.1.0-m3'}

        self.with_validator_config['paths'][0]['validator']['function'] = \
            'fail_validate'

        try:
            with pytest.raises(repex.RepexError) as ex:
                repex.iterate(
                    config=self.with_validator_config,
                    variables=variables)
            assert repex.ERRORS['validation_failed'] in str(ex)

            with open(self.single_file_output_file) as f:
                assert '3.1.0-m3' in f.read()
        finally:
            os.remove(self.single_file_output_file)
示例#12
0
    def test_that_replacement_is_only_done_within_match(self):
        """Test that an expression is matched and replacement
        occurs within it alone.

        See `match_replace_*` files for more info.

        The match should include the three first lines in th file.
        The replacement could occur in all four lines.
        Additionally, the match in the first three lines includes
        everything after the version (-1, -2, -3).

        For this test to pass, we expect that not only the fourth line
        remains the same, but that the replacement occurs only according
        to the replacement expression and not the matching expression.
        """
        repex.iterate(config=self.config)
        with open(self.output_file) as f:
            content = f.read().splitlines()
        assert '/something-2.9-1' == content[0]
        assert '/something-2.9-2' == content[1]
        assert '/something-2.9-3' == content[2]
        assert '/something_else-1.3.1-1' == content[3]
示例#13
0
    def test_iterate_multiple_files(self):
        # Note that this also tests expanding variables in variables
        # as the variable declared in the `mock_multiple_files.yaml`
        # is being expanded itself and then used.

        def _test(replaced_value, initial_value):
            for version_file in self.version_files_without_excluded:
                with open(version_file) as f:
                    assert replaced_value in f.read()
            for version_file in self.excluded_files:
                with open(version_file) as f:
                    assert initial_value in f.read()

        # TODO: This is some stupid thing related to formatting on windows
        # The direct invocation with click doesn't work on windows..
        # probably due to some string formatting of the command.
        if os.name == 'nt':
            variables = {'preversion': '3.1.0-m2', 'version': '3.1.0-m3'}
            repex.iterate(MOCK_MULTIPLE_FILES, variables=variables)
        else:
            fd, tmp = tempfile.mkstemp()
            os.close(fd)
            with open(tmp, 'w') as f:
                f.write("version: '3.1.0-m3'")
            try:
                _invoke(
                    "-c {0} --vars-file={1} "
                    "--var='preversion'='3.1.0-m2'".format(
                        MOCK_MULTIPLE_FILES, tmp))
            finally:
                os.remove(tmp)

        _test('"version": "3.1.0-m3"', '"version": "3.1.0-m2"')
        variables = {'preversion': '3.1.0-m3', 'version': '3.1.0-m2'}
        repex.iterate(MOCK_MULTIPLE_FILES, variables=variables)
        _test('"version": "3.1.0-m2"', '"version": "3.1.0-m2"')
示例#14
0
 def test_tags_not_list(self):
     tags = 'x'
     with pytest.raises(TypeError) as ex:
         repex.iterate(config=self.single_file_config, tags=tags)
     assert repex.ERRORS['tags_not_list'] in str(ex)
示例#15
0
 def test_iterate_with_vars_in_config(self):
     repex.iterate(config_file_path=MOCK_SINGLE_FILE)
     with open(self.single_file_output_file) as f:
         self.assertIn('3.1.0-m4', f.read())
示例#16
0
 def test_iterate_no_config_supplied(self):
     with pytest.raises(repex.RepexError) as ex:
         repex.iterate()
     assert repex.ERRORS['no_config_supplied'] in str(ex)
示例#17
0
 def test_iterate_no_files(self):
     with pytest.raises(repex.RepexError) as ex:
         repex.iterate(config_file_path=EMPTY_CONFIG_FILE, variables={})
     assert "'paths' is a required property" in str(ex)
示例#18
0
 def test_iterate_variables_not_dict(self):
     with pytest.raises(TypeError) as ex:
         repex.iterate(config_file_path=MOCK_SINGLE_FILE, variables='x')
     assert repex.ERRORS['variables_not_dict'] in str(ex)
示例#19
0
 def test_invalid_validator_type(self):
     self.validator_config.update({'type': 'bad_type'})
     with pytest.raises(repex.RepexError) as ex:
         repex.iterate(config=self.with_validator_config)
     assert "bad_type' is not one of ['per_type', 'per_file']" in str(ex)