From 9140335ad5fcae65dbc20d23f7d137ec18d6fe12 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: Mon, 30 Nov 2020 18:42:05 +0300 Subject: [PATCH] Spaces in raw format was fixed #24 --- calculate/templates/format/raw_format.py | 6 +++--- tests/templates/format/test_raw.py | 18 ++++++++++++------ tests/templates/test_directory_processor.py | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/calculate/templates/format/raw_format.py b/calculate/templates/format/raw_format.py index 9753438..dbac590 100644 --- a/calculate/templates/format/raw_format.py +++ b/calculate/templates/format/raw_format.py @@ -32,7 +32,7 @@ class RawFormat(Format): @property def document_text(self): - return '{}{}'.format(self.header, self._document_text) + return '{}{}\n'.format(self.header, self._document_text) def join_template(self, template): if self._before: @@ -44,9 +44,9 @@ class RawFormat(Format): else: self._document_text = '{0}{1}{2}'.format( self._document_text, - "" if template._document_text. + "" if self._document_text. endswith("\n") else "\n", template._document_text) def __bool__(self): - return bool(self.document_text) + return bool(self.document_text.strip()) diff --git a/tests/templates/format/test_raw.py b/tests/templates/format/test_raw.py index 3a5eb8e..fab090d 100644 --- a/tests/templates/format/test_raw.py +++ b/tests/templates/format/test_raw.py @@ -18,7 +18,8 @@ parameter-5 = e;''' parameter-2 = b; parameter-3 = c; parameter-4 = d; -parameter-5 = e;''' +parameter-5 = e; +''' raw_document_1 = RawFormat(original, 'path/to/template') raw_document_2 = RawFormat(template, 'path/to/template') @@ -38,7 +39,8 @@ parameter-5 = e;''' parameter-5 = e; parameter-1 = a; parameter-2 = b; -parameter-3 = c;''' +parameter-3 = c; +''' raw_document_1 = RawFormat(document_1, 'path/to/template', join_before=True) @@ -65,7 +67,8 @@ parameter-1 = a; parameter-2 = b; parameter-3 = c; parameter-4 = d; -parameter-5 = e;''' +parameter-5 = e; +''' raw_document_1 = RawFormat(document_1, 'path/to/template', add_header=True, parameters=parameters) @@ -93,7 +96,8 @@ parameter-4 = d; parameter-5 = e; parameter-1 = a; parameter-2 = b; -parameter-3 = c;''' +parameter-3 = c; +''' raw_document_1 = RawFormat(document_1, 'path/to/template', join_before=True, add_header=True, @@ -125,7 +129,8 @@ parameter-2 = b; parameter-3 = c; parameter-4 = d; parameter-5 = e; -parameter-6 = f;''' +parameter-6 = f; +''' original_1 = RawFormat(original_text, 'path/to/template_1', add_header=True, @@ -160,7 +165,8 @@ parameter-2 = b; parameter-3 = c; parameter-4 = d; parameter-5 = e; -parameter-6 = f;''' +parameter-6 = f; +''' original_1 = RawFormat(original_text, 'path/to/template_1', add_header=True, diff --git a/tests/templates/test_directory_processor.py b/tests/templates/test_directory_processor.py index 32a6313..b5262e3 100644 --- a/tests/templates/test_directory_processor.py +++ b/tests/templates/test_directory_processor.py @@ -1427,7 +1427,7 @@ class TestDirectoryProcessor: '/etc/dir_61/._cfg0000_file_0'), 'r') as new_file: new_text = new_file.read() - assert new_text == '\nnew content' + assert new_text == '\nnew content\n' def test_current_template_variable(self): datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, @@ -1439,7 +1439,7 @@ class TestDirectoryProcessor: '# Processed template files:\n' + f'# {template_path}\n' + '#' + '-' * 79 + - f'\n\ntemplate = {template_path}') + f'\n\ntemplate = {template_path}\n') directory_processor = DirectoryProcessor( 'install', datavars_module=datavars,