From 24bd7b3e6319847c03c1164d42d22beca13c7209 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: Wed, 13 Jan 2021 12:53:21 +0300 Subject: [PATCH] Now regex templates with parameter comment = '' do not add calculate comment. fixed #70 --- calculate/templates/format/base_format.py | 1 + calculate/templates/format/regex_format.py | 3 ++ tests/templates/format/test_regex.py | 58 ++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/calculate/templates/format/base_format.py b/calculate/templates/format/base_format.py index 430c8db..eca6212 100644 --- a/calculate/templates/format/base_format.py +++ b/calculate/templates/format/base_format.py @@ -370,6 +370,7 @@ class Format(): return header, document_text def _make_header(self, template_paths: list): + print('making header...') if not self.comment_symbol: return "" elif self.comment_symbol in ("xml", "XML"): diff --git a/calculate/templates/format/regex_format.py b/calculate/templates/format/regex_format.py index cebbf0e..dd3476c 100644 --- a/calculate/templates/format/regex_format.py +++ b/calculate/templates/format/regex_format.py @@ -29,6 +29,9 @@ class RegexFormat(Format): self._multiline_flag = parameters.multiline self._dotall_flag = parameters.dotall + if parameters.comment is not False: + self.comment_symbol = parameters.comment + print(f'comment symbol is set to: "{self.comment_symbol}"') self._parsed_patch = None if add_header and not ignore_comments: diff --git a/tests/templates/format/test_regex.py b/tests/templates/format/test_regex.py index 1aae65e..152aaba 100644 --- a/tests/templates/format/test_regex.py +++ b/tests/templates/format/test_regex.py @@ -320,6 +320,64 @@ WorldWWWW Testing +''' + + original_object = RegexFormat(original_text, '/path/to/template', + add_header=True, already_changed=True, + parameters=parameters) + template_object = RegexFormat(template_text, '/path/to/template', + parameters=parameters) + original_object.join_template(template_object) + assert original_object.document_text == join_result + + def test_format_with_empty_comment_parameter(self): + parameters = ParametersContainer({'multiline': True, + 'dotall': True, + 'comment': ''}) + original_text = ''' +Hello +''' + + template_text = r''' +Hello + +''' + + join_result = ''' + +''' + + original_object = RegexFormat(original_text, '/path/to/template', + add_header=True, already_changed=True, + parameters=parameters) + template_object = RegexFormat(template_text, '/path/to/template', + parameters=parameters) + original_object.join_template(template_object) + assert original_object.document_text == join_result + + def test_format_with_empty_comment_parameter_and_with_header_in_original_document(self): + parameters = ParametersContainer({'multiline': True, + 'dotall': True, + 'comment': ''}) + original_text = '''#------------------------------------------------------------------------------- +# Modified by Calculate Utilities 4.0 +# Processed template files: +# /path/to/ancient/template +#------------------------------------------------------------------------------- +Hello +''' + + template_text = r''' +Hello + +''' + + join_result = '''#------------------------------------------------------------------------------- +# Modified by Calculate Utilities 4.0 +# Processed template files: +# /path/to/ancient/template +#------------------------------------------------------------------------------- + ''' original_object = RegexFormat(original_text, '/path/to/template',