diff options
Diffstat (limited to '_test/test_indentation.py')
-rw-r--r-- | _test/test_indentation.py | 152 |
1 files changed, 68 insertions, 84 deletions
diff --git a/_test/test_indentation.py b/_test/test_indentation.py index 9d5fc96..c6131f1 100644 --- a/_test/test_indentation.py +++ b/_test/test_indentation.py @@ -19,89 +19,73 @@ def rt(s): ).strip() + '\n' -def test_roundtrip_inline_list(): - s = 'a: [a, b, c]\n' - output = rt(s) - assert s == output - - -def test_roundtrip_mapping_of_inline_lists(): - s = dedent("""\ - a: [a, b, c] - j: [k, l, m] - """) - output = rt(s) - assert s == output - - -def test_roundtrip_mapping_of_inline_lists_comments(): - s = dedent("""\ - # comment A - a: [a, b, c] - # comment B - j: [k, l, m] - """) - output = rt(s) - assert s == output - - -def test_roundtrip_mapping_of_inline_sequence_eol_comments(): - s = dedent("""\ - # comment A - a: [a, b, c] # comment B - j: [k, l, m] # comment C - """) - output = rt(s) - assert s == output - - -# first test by explicitly setting flow style -def test_added_inline_list(): - s1 = dedent(""" - a: - - b - - c - - d - """) - s = 'a: [b, c, d]\n' - data = ruamel.yaml.load(s1, Loader=ruamel.yaml.RoundTripLoader) - val = data['a'] - val.fa.set_flow_style() - # print(type(val), '_yaml_format' in dir(val)) - output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) - assert s == output - -# ############ flow mappings - - -def test_roundtrip_flow_mapping(): - s = dedent("""\ - - {a: 1, b: hallo} - - {j: fka, k: 42} - """) - data = ruamel.yaml.load(s, Loader=ruamel.yaml.RoundTripLoader) - output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) - assert s == output - - -def test_roundtrip_sequence_of_inline_mappings_eol_comments(): - s = dedent("""\ - # comment A - - {a: 1, b: hallo} # comment B - - {j: fka, k: 42} # comment C - """) - output = rt(s) - assert s == output +class TestIndent: + def test_roundtrip_inline_list(self): + s = 'a: [a, b, c]\n' + output = rt(s) + assert s == output + + def test_roundtrip_mapping_of_inline_lists(self): + s = dedent("""\ + a: [a, b, c] + j: [k, l, m] + """) + output = rt(s) + assert s == output + + def test_roundtrip_mapping_of_inline_lists_comments(self): + s = dedent("""\ + # comment A + a: [a, b, c] + # comment B + j: [k, l, m] + """) + output = rt(s) + assert s == output + + def test_roundtrip_mapping_of_inline_sequence_eol_comments(self): + s = dedent("""\ + # comment A + a: [a, b, c] # comment B + j: [k, l, m] # comment C + """) + output = rt(s) + assert s == output + + # first test by explicitly setting flow style + def test_added_inline_list(self): + s1 = dedent(""" + a: + - b + - c + - d + """) + s = 'a: [b, c, d]\n' + data = ruamel.yaml.load(s1, Loader=ruamel.yaml.RoundTripLoader) + val = data['a'] + val.fa.set_flow_style() + # print(type(val), '_yaml_format' in dir(val)) + output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) + assert s == output + + # ############ flow mappings + + def test_roundtrip_flow_mapping(self): + s = dedent("""\ + - {a: 1, b: hallo} + - {j: fka, k: 42} + """) + data = ruamel.yaml.load(s, Loader=ruamel.yaml.RoundTripLoader) + output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) + assert s == output + + def test_roundtrip_sequence_of_inline_mappings_eol_comments(self): + s = dedent("""\ + # comment A + - {a: 1, b: hallo} # comment B + - {j: fka, k: 42} # comment C + """) + output = rt(s) + assert s == output # ############ indentation - - -@pytest.mark.xfail -def test_roundtrip_four_space_indents(): - s = ( - 'a:\n' - '- foo\n' - '- bar\n' - ) - output = rt(s) - assert s == output |