Remove sections (#721).
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -84,7 +84,6 @@ def test_prune_archives_command_does_not_duplicate_flags_or_raise():
|
||||
False,
|
||||
'repo',
|
||||
{},
|
||||
{},
|
||||
'2.3.4',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
argparse.Namespace(log_json=False),
|
||||
|
||||
@@ -13,43 +13,43 @@ def test_insert_newline_before_comment_does_not_raise():
|
||||
config = module.yaml.comments.CommentedMap([(field_name, 33)])
|
||||
config.yaml_set_comment_before_after_key(key=field_name, before='Comment')
|
||||
|
||||
module._insert_newline_before_comment(config, field_name)
|
||||
module.insert_newline_before_comment(config, field_name)
|
||||
|
||||
|
||||
def test_comment_out_line_skips_blank_line():
|
||||
line = ' \n'
|
||||
|
||||
assert module._comment_out_line(line) == line
|
||||
assert module.comment_out_line(line) == line
|
||||
|
||||
|
||||
def test_comment_out_line_skips_already_commented_out_line():
|
||||
line = ' # foo'
|
||||
|
||||
assert module._comment_out_line(line) == line
|
||||
assert module.comment_out_line(line) == 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_line_comments_twice_indented_option():
|
||||
line = ' - item'
|
||||
|
||||
assert module._comment_out_line(line) == ' # - item'
|
||||
assert module.comment_out_line(line) == ' # - item'
|
||||
|
||||
|
||||
def test_comment_out_optional_configuration_comments_optional_config_only():
|
||||
# The "# COMMENT_OUT" comment is a sentinel used to express that the following key is optional.
|
||||
# It's stripped out of the final output.
|
||||
flexmock(module)._comment_out_line = lambda line: '# ' + line
|
||||
flexmock(module).comment_out_line = lambda line: '# ' + line
|
||||
config = '''
|
||||
# COMMENT_OUT
|
||||
foo:
|
||||
@@ -84,7 +84,7 @@ location:
|
||||
# other: thing
|
||||
'''
|
||||
|
||||
assert module._comment_out_optional_configuration(config.strip()) == expected_config.strip()
|
||||
assert module.comment_out_optional_configuration(config.strip()) == expected_config.strip()
|
||||
|
||||
|
||||
def test_render_configuration_converts_configuration_to_yaml_string():
|
||||
@@ -204,10 +204,10 @@ def test_generate_sample_configuration_does_not_raise():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
builtins.should_receive('open').with_args('schema.yaml').and_return('')
|
||||
flexmock(module.yaml).should_receive('round_trip_load')
|
||||
flexmock(module).should_receive('_schema_to_sample_configuration')
|
||||
flexmock(module).should_receive('schema_to_sample_configuration')
|
||||
flexmock(module).should_receive('merge_source_configuration_into_destination')
|
||||
flexmock(module).should_receive('render_configuration')
|
||||
flexmock(module).should_receive('_comment_out_optional_configuration')
|
||||
flexmock(module).should_receive('comment_out_optional_configuration')
|
||||
flexmock(module).should_receive('write_configuration')
|
||||
|
||||
module.generate_sample_configuration(False, None, 'dest.yaml', 'schema.yaml')
|
||||
@@ -219,10 +219,10 @@ def test_generate_sample_configuration_with_source_filename_does_not_raise():
|
||||
flexmock(module.yaml).should_receive('round_trip_load')
|
||||
flexmock(module.load).should_receive('load_configuration')
|
||||
flexmock(module.normalize).should_receive('normalize')
|
||||
flexmock(module).should_receive('_schema_to_sample_configuration')
|
||||
flexmock(module).should_receive('schema_to_sample_configuration')
|
||||
flexmock(module).should_receive('merge_source_configuration_into_destination')
|
||||
flexmock(module).should_receive('render_configuration')
|
||||
flexmock(module).should_receive('_comment_out_optional_configuration')
|
||||
flexmock(module).should_receive('comment_out_optional_configuration')
|
||||
flexmock(module).should_receive('write_configuration')
|
||||
|
||||
module.generate_sample_configuration(False, 'source.yaml', 'dest.yaml', 'schema.yaml')
|
||||
@@ -232,10 +232,10 @@ def test_generate_sample_configuration_with_dry_run_does_not_write_file():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
builtins.should_receive('open').with_args('schema.yaml').and_return('')
|
||||
flexmock(module.yaml).should_receive('round_trip_load')
|
||||
flexmock(module).should_receive('_schema_to_sample_configuration')
|
||||
flexmock(module).should_receive('schema_to_sample_configuration')
|
||||
flexmock(module).should_receive('merge_source_configuration_into_destination')
|
||||
flexmock(module).should_receive('render_configuration')
|
||||
flexmock(module).should_receive('_comment_out_optional_configuration')
|
||||
flexmock(module).should_receive('comment_out_optional_configuration')
|
||||
flexmock(module).should_receive('write_configuration').never()
|
||||
|
||||
module.generate_sample_configuration(True, None, 'dest.yaml', 'schema.yaml')
|
||||
|
||||
@@ -40,35 +40,32 @@ def mock_config_and_schema(config_yaml, schema_yaml=None):
|
||||
def test_parse_configuration_transforms_file_into_mapping():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
- /etc
|
||||
source_directories:
|
||||
- /home
|
||||
- /etc
|
||||
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
|
||||
retention:
|
||||
keep_minutely: 60
|
||||
keep_hourly: 24
|
||||
keep_daily: 7
|
||||
keep_minutely: 60
|
||||
keep_hourly: 24
|
||||
keep_daily: 7
|
||||
|
||||
consistency:
|
||||
checks:
|
||||
- name: repository
|
||||
- name: archives
|
||||
checks:
|
||||
- name: repository
|
||||
- name: archives
|
||||
'''
|
||||
)
|
||||
|
||||
config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml')
|
||||
|
||||
assert config == {
|
||||
'location': {
|
||||
'source_directories': ['/home', '/etc'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
},
|
||||
'retention': {'keep_daily': 7, 'keep_hourly': 24, 'keep_minutely': 60},
|
||||
'consistency': {'checks': [{'name': 'repository'}, {'name': 'archives'}]},
|
||||
'source_directories': ['/home', '/etc'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'keep_daily': 7,
|
||||
'keep_hourly': 24,
|
||||
'keep_minutely': 60,
|
||||
'checks': [{'name': 'repository'}, {'name': 'archives'}],
|
||||
}
|
||||
assert logs == []
|
||||
|
||||
@@ -78,22 +75,19 @@ def test_parse_configuration_passes_through_quoted_punctuation():
|
||||
|
||||
mock_config_and_schema(
|
||||
f'''
|
||||
location:
|
||||
source_directories:
|
||||
- "/home/{escaped_punctuation}"
|
||||
source_directories:
|
||||
- "/home/{escaped_punctuation}"
|
||||
|
||||
repositories:
|
||||
- path: test.borg
|
||||
repositories:
|
||||
- path: test.borg
|
||||
'''
|
||||
)
|
||||
|
||||
config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml')
|
||||
|
||||
assert config == {
|
||||
'location': {
|
||||
'source_directories': [f'/home/{string.punctuation}'],
|
||||
'repositories': [{'path': 'test.borg'}],
|
||||
}
|
||||
'source_directories': [f'/home/{string.punctuation}'],
|
||||
'repositories': [{'path': 'test.borg'}],
|
||||
}
|
||||
assert logs == []
|
||||
|
||||
@@ -101,26 +95,22 @@ def test_parse_configuration_passes_through_quoted_punctuation():
|
||||
def test_parse_configuration_with_schema_lacking_examples_does_not_raise():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
source_directories:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
''',
|
||||
'''
|
||||
map:
|
||||
location:
|
||||
source_directories:
|
||||
required: true
|
||||
map:
|
||||
source_directories:
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
repositories:
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
seq:
|
||||
- type: scalar
|
||||
repositories:
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
''',
|
||||
)
|
||||
|
||||
@@ -130,12 +120,11 @@ def test_parse_configuration_with_schema_lacking_examples_does_not_raise():
|
||||
def test_parse_configuration_inlines_include():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
source_directories:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
|
||||
retention:
|
||||
!include include.yaml
|
||||
@@ -154,25 +143,25 @@ def test_parse_configuration_inlines_include():
|
||||
config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml')
|
||||
|
||||
assert config == {
|
||||
'location': {'source_directories': ['/home'], 'repositories': [{'path': 'hostname.borg'}]},
|
||||
'retention': {'keep_daily': 7, 'keep_hourly': 24},
|
||||
'source_directories': ['/home'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'keep_daily': 7,
|
||||
'keep_hourly': 24,
|
||||
}
|
||||
assert logs == []
|
||||
assert len(logs) == 1
|
||||
|
||||
|
||||
def test_parse_configuration_merges_include():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
source_directories:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
|
||||
retention:
|
||||
keep_daily: 1
|
||||
<<: !include include.yaml
|
||||
keep_daily: 1
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
@@ -188,8 +177,10 @@ def test_parse_configuration_merges_include():
|
||||
config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml')
|
||||
|
||||
assert config == {
|
||||
'location': {'source_directories': ['/home'], 'repositories': [{'path': 'hostname.borg'}]},
|
||||
'retention': {'keep_daily': 1, 'keep_hourly': 24},
|
||||
'source_directories': ['/home'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'keep_daily': 1,
|
||||
'keep_hourly': 24,
|
||||
}
|
||||
assert logs == []
|
||||
|
||||
@@ -218,10 +209,9 @@ def test_parse_configuration_raises_for_syntax_error():
|
||||
def test_parse_configuration_raises_for_validation_error():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories: yes
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
source_directories: yes
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
'''
|
||||
)
|
||||
|
||||
@@ -232,14 +222,13 @@ def test_parse_configuration_raises_for_validation_error():
|
||||
def test_parse_configuration_applies_overrides():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
source_directories:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
repositories:
|
||||
- path: hostname.borg
|
||||
|
||||
local_path: borg1
|
||||
local_path: borg1
|
||||
'''
|
||||
)
|
||||
|
||||
@@ -248,11 +237,9 @@ def test_parse_configuration_applies_overrides():
|
||||
)
|
||||
|
||||
assert config == {
|
||||
'location': {
|
||||
'source_directories': ['/home'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'local_path': 'borg2',
|
||||
}
|
||||
'source_directories': ['/home'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'local_path': 'borg2',
|
||||
}
|
||||
assert logs == []
|
||||
|
||||
@@ -274,10 +261,8 @@ def test_parse_configuration_applies_normalization():
|
||||
config, logs = module.parse_configuration('/tmp/config.yaml', '/tmp/schema.yaml')
|
||||
|
||||
assert config == {
|
||||
'location': {
|
||||
'source_directories': ['/home'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'exclude_if_present': ['.nobackup'],
|
||||
}
|
||||
'source_directories': ['/home'],
|
||||
'repositories': [{'path': 'hostname.borg'}],
|
||||
'exclude_if_present': ['.nobackup'],
|
||||
}
|
||||
assert logs
|
||||
|
||||
Reference in New Issue
Block a user