From cb199776dab64463c8a87259a2ac19d10f880a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Thu, 19 Nov 2020 12:23:28 +0300 Subject: [PATCH] ._cfg files counting is changed. --- calculate/templates/template_processor.py | 7 ++--- tests/templates/test_directory_processor.py | 16 +++++----- tests/templates/test_template_executor.py | 10 +++--- tests/templates/test_template_wrapper.py | 34 ++++++++++----------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index b804e97..5af409c 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -561,11 +561,10 @@ class TemplateWrapper: last_cfg_name = os.path.basename(self.cfg_list[-1]) slice_value = len('._cfg') - cfg_number = int(last_cfg_name[slice_value: slice_value + 4]) + cfg_number = int(last_cfg_name[slice_value: slice_value + 4]) + 1 + cfg_number = str(cfg_number) else: - cfg_number = 0 - - cfg_number = str(cfg_number + 1) + cfg_number = '0' if len(cfg_number) < 4: cfg_number = '0' * (4 - len(cfg_number)) + cfg_number diff --git a/tests/templates/test_directory_processor.py b/tests/templates/test_directory_processor.py index 7cd38d4..3da945c 100644 --- a/tests/templates/test_directory_processor.py +++ b/tests/templates/test_directory_processor.py @@ -386,15 +386,15 @@ class TestDirectoryProcessor: + ";\n};\n")) assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_2')) - assert os.path.exists(join_paths(CHROOT_PATH, '/etc/._cfg0001_file_2')) + assert os.path.exists(join_paths(CHROOT_PATH, '/etc/._cfg0000_file_2')) test_package = Package(new_package_name, chroot_path=CHROOT_PATH) assert '/etc/file_2' in test_package with open(join_paths(CHROOT_PATH, - '/etc/._cfg0001_file_2'), 'r') as output_file: + '/etc/._cfg0000_file_2'), 'r') as output_file: output_file_text = output_file.read() assert output_file_text == output_text - assert test_package.check_contents_data('/etc/._cfg0001_file_2', + assert test_package.check_contents_data('/etc/._cfg0000_file_2', hashlib.md5( output_text.encode()).hexdigest()) @@ -426,15 +426,15 @@ class TestDirectoryProcessor: + ";\n};\n")) assert not os.path.exists(join_paths(CHROOT_PATH, '/etc/file_3')) - assert os.path.exists(join_paths(CHROOT_PATH, '/etc/._cfg0001_file_3')) + assert os.path.exists(join_paths(CHROOT_PATH, '/etc/._cfg0000_file_3')) test_package = Package(new_package_name, chroot_path=CHROOT_PATH) assert '/etc/file_3' in test_package with open(join_paths(CHROOT_PATH, - '/etc/._cfg0001_file_3'), 'r') as output_file: + '/etc/._cfg0000_file_3'), 'r') as output_file: output_file_text = output_file.read() assert output_file_text == output_text - assert test_package.check_contents_data('/etc/._cfg0001_file_3', + assert test_package.check_contents_data('/etc/._cfg0000_file_3', hashlib.md5( output_text.encode()).hexdigest()) @@ -974,8 +974,8 @@ class TestDirectoryProcessor: def test_if_templates_contain_a_template_file_with_a_target_path_to_a_file_with_some_cfg_files_and_changes_in_the_template_is_the_same_as_in_the_last_cfg_file__the_directory_processor_does_nothing(self): datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, 'templates_28') - cfg_path_1 = os.path.join(CHROOT_PATH, 'etc/._cfg0001_file_12') - cfg_path_2 = os.path.join(CHROOT_PATH, 'etc/._cfg0002_file_12') + cfg_path_1 = os.path.join(CHROOT_PATH, 'etc/._cfg0000_file_12') + cfg_path_2 = os.path.join(CHROOT_PATH, 'etc/._cfg0001_file_12') directory_processor = DirectoryProcessor('install', datavars_module=datavars) diff --git a/tests/templates/test_template_executor.py b/tests/templates/test_template_executor.py index a70d175..96670de 100644 --- a/tests/templates/test_template_executor.py +++ b/tests/templates/test_template_executor.py @@ -1456,7 +1456,7 @@ class TestTemplateExecutor: config_archive_path=CONFIG_ARCHIVE_PATH) template_executor._append_join_file(template_wrapper) assert os.path.exists(os.path.join(os.path.dirname(target_path), - '._cfg0001_file_1')) + '._cfg0000_file_1')) assert not os.path.exists(join_paths( CONFIG_ARCHIVE_PATH, '/etc/append_join_file_testfiles/file_1')) @@ -1558,7 +1558,7 @@ class TestTemplateExecutor: 'chown': chown_value, 'chmod': chmod_value}) output_path = os.path.join(os.path.dirname(target_path), - '._cfg0001_file_4') + '._cfg0000_file_4') header = ('#' + '-' * 79 + '\n' + '# Modified by Calculate Utilities 4.0\n' + '# Processed template files:\n' + @@ -1672,7 +1672,7 @@ class TestTemplateExecutor: CHROOT_PATH, '/etc/append_join_file_testfiles/file_7') output_path = os.path.join(os.path.dirname(target_path), - '._cfg0001_file_7') + '._cfg0000_file_7') parameters_object = ParametersContainer({'package': test_package_name, 'append': 'join', @@ -1707,7 +1707,7 @@ class TestTemplateExecutor: CHROOT_PATH, '/etc/append_join_file_testfiles/file_8') output_path = os.path.join(os.path.dirname(target_path), - '._cfg0001_file_8') + '._cfg0000_file_8') chown_value = {'uid': os.getuid(), 'gid': os.getgid()} chmod_value = int(0o777) @@ -2464,7 +2464,7 @@ class TestTemplateExecutor: '/etc/append_link_file_testfiles/file_3') output_path = join_paths( CHROOT_PATH, - '/etc/append_link_file_testfiles/._cfg0001_link_file_3') + '/etc/append_link_file_testfiles/._cfg0000_link_file_3') parameters_object = ParametersContainer({'package': test_package_name, 'append': 'link', diff --git a/tests/templates/test_template_wrapper.py b/tests/templates/test_template_wrapper.py index adea8bd..abecf77 100644 --- a/tests/templates/test_template_wrapper.py +++ b/tests/templates/test_template_wrapper.py @@ -585,7 +585,7 @@ class TestTemplateWrapper: pytest.fail("Unexpected exception: {}".format(str(error))) cfg_name = template_wrapper._get_cfg_path(template_wrapper.target_path) - assert cfg_name == join_paths(CHROOT_PATH, '/etc/dir_0/._cfg0001_file') + assert cfg_name == join_paths(CHROOT_PATH, '/etc/dir_0/._cfg0000_file') def test_if_a_target_file_directory_contains_some_cfg_files_including_the_first_one__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one(self): parameters_object = ParametersContainer({'append': 'bind'}) @@ -877,7 +877,7 @@ class TestTemplateWrapper: '/etc/dir_0/file') assert template_wrapper.output_path == join_paths( CHROOT_PATH, - '/etc/dir_0/._cfg0001_file') + '/etc/dir_0/._cfg0000_file') def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_contains_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self): source = join_paths(CHROOT_PATH, '/etc/file') @@ -919,7 +919,7 @@ class TestTemplateWrapper: assert template_wrapper.input_path == source assert template_wrapper.output_path == join_paths( CHROOT_PATH, - '/etc/dir_0/._cfg0001_file') + '/etc/dir_0/._cfg0000_file') # Тестируем поведение, если формат исполняемый. def test_if_a_target_path_is_FILE_and_a_template_is_executable__the_target_path_is_replaced_with_the_path_to_the_cwd_directory_and_there_is_no_package_type_conflicts_and_other_checks(self): @@ -1203,20 +1203,20 @@ class TestTemplateWrapper: target_package # Тестируем особенности поведения при различных значениях параметров. - def test_if_mirror_parameter_is_set_and_target_file_does_not_exist__a_TemplateWrapper_object_throws_TemplateExecutorError(self): - source = join_paths(CHROOT_PATH, '/etc/file') - parameters_object = ParametersContainer({'package': test_package_name, - 'append': 'join', - 'format': 'bind', - 'source': source, - 'mirror': True}) - - with pytest.raises(TemplateExecutorError): - TemplateWrapper(join_paths(CHROOT_PATH, '/etc/dir/none'), - parameters_object, FILE, - '/path/to/template', - chroot_path=CHROOT_PATH, - config_archive_path=CONFIG_ARCHIVE_PATH) + # def test_if_mirror_parameter_is_set_and_target_file_does_not_exist__a_TemplateWrapper_object_throws_TemplateExecutorError(self): + # source = join_paths(CHROOT_PATH, '/etc/file') + # parameters_object = ParametersContainer({'package': test_package_name, + # 'append': 'join', + # 'format': 'bind', + # 'source': source, + # 'mirror': True}) + + # with pytest.raises(TemplateExecutorError): + # TemplateWrapper(join_paths(CHROOT_PATH, '/etc/dir/none'), + # parameters_object, FILE, + # '/path/to/template', + # chroot_path=CHROOT_PATH, + # config_archive_path=CONFIG_ARCHIVE_PATH) def test_if_mirror_parameter_is_set_and_file_from_the_source_parameter_does_not_exist__a_TemplateWrapper_object_sets_remove_original_flag_as_True(self): parameters_object = ParametersContainer({'package': test_package_name,