From 0c439c0c028243d923b9a46c8d28d62eae86c6aa Mon Sep 17 00:00:00 2001 From: "Daniel M. Capella" Date: Tue, 17 Sep 2019 20:00:58 -0400 Subject: [PATCH] Add space to separate comments from tokens https://yaml.org/spec/1.2/spec.html#id2780069 --- borgmatic/config/generate.py | 4 ++-- tests/integration/config/test_generate.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/borgmatic/config/generate.py b/borgmatic/config/generate.py index 0f34364..179e660 100644 --- a/borgmatic/config/generate.py +++ b/borgmatic/config/generate.py @@ -45,10 +45,10 @@ def _comment_out_line(line): # Comment out the names of optional sections. one_indent = ' ' * INDENT if not line.startswith(one_indent): - return '#' + line + return '# ' + line # Otherwise, comment out the line, but insert the "#" after the first indent for aesthetics. - return '#'.join((one_indent, line[INDENT:])) + return '# '.join((one_indent, line[INDENT:])) REQUIRED_KEYS = {'source_directories', 'repositories', 'keep_daily'} diff --git a/tests/integration/config/test_generate.py b/tests/integration/config/test_generate.py index cf399cb..8c4376e 100644 --- a/tests/integration/config/test_generate.py +++ b/tests/integration/config/test_generate.py @@ -31,17 +31,17 @@ def test_comment_out_line_skips_already_commented_out_line(): def test_comment_out_line_comments_section_name(): line = 'figgy-pudding:' - assert module._comment_out_line(line) == '#' + line + assert module._comment_out_line(line) == '# ' + line def test_comment_out_line_comments_indented_option(): line = ' enabled: true' - assert module._comment_out_line(line) == ' #enabled: true' + assert module._comment_out_line(line) == ' # enabled: true' def test_comment_out_optional_configuration_comments_optional_config_only(): - flexmock(module)._comment_out_line = lambda line: '#' + line + flexmock(module)._comment_out_line = lambda line: '# ' + line config = ''' foo: bar: @@ -57,17 +57,17 @@ location: ''' expected_config = ''' -#foo: -# bar: -# - baz -# - quux -# +# foo: +# bar: +# - baz +# - quux +# location: repositories: - one - two -# -# other: thing +# +# other: thing ''' assert module._comment_out_optional_configuration(config.strip()) == expected_config.strip()