diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-09-01 09:30:27 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-09-01 09:30:27 +0200 |
commit | 94d2de64fbbe298365c42246e801e366aaaa9a60 (patch) | |
tree | 715523ff68b56615574d1bfec8fa70434aea851a /_test/test_literal.py | |
parent | 849c06e2272a9535bfabb068711a75484b622f1e (diff) | |
download | ruamel.yaml-94d2de64fbbe298365c42246e801e366aaaa9a60.tar.gz |
rt of doc with root literal and embedded directive/document end
Diffstat (limited to '_test/test_literal.py')
-rw-r--r-- | _test/test_literal.py | 87 |
1 files changed, 61 insertions, 26 deletions
diff --git a/_test/test_literal.py b/_test/test_literal.py index edb86ce..698ece5 100644 --- a/_test/test_literal.py +++ b/_test/test_literal.py @@ -7,14 +7,14 @@ from roundtrip import YAML # does an automatic dedent on load """ -YAML 1.0 allowed top level literal style without indentation: +YAML 1.0 allowed root level literal style without indentation: "Usually top level nodes are not indented" (example 4.21 in 4.6.3) YAML 1.1 is a bit vague but says: "Regardless of style, scalar content must always be indented by at least one space" (4.4.3) "In general, the document’s node is indented as if it has a parent indented at -1 spaces." (4.3.3) -YAML 1.2 is again clear about top level literal scalar after directive in example 9.5: +YAML 1.2 is again clear about root literal level scalar after directive in example 9.5: %YAML 1.2 --- | @@ -28,7 +28,7 @@ YAML 1.2 is again clear about top level literal scalar after directive in exampl class TestNoIndent: - def test_top_literal_scalar_indent_example_9_5(self): + def test_root_literal_scalar_indent_example_9_5(self): yaml = YAML() s = '%!PS-Adobe-2.0' inp = """ @@ -39,7 +39,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_scalar_no_indent(self): + def test_root_literal_scalar_no_indent(self): yaml = YAML() s = 'testing123' inp = """ @@ -50,7 +50,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_scalar_no_indent_1_1(self): + def test_root_literal_scalar_no_indent_1_1(self): yaml = YAML() s = 'testing123' inp = """ @@ -62,7 +62,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_scalar_no_indent_1_1_old_style(self): + def test_root_literal_scalar_no_indent_1_1_old_style(self): from textwrap import dedent from ruamel.yaml import safe_load @@ -76,13 +76,14 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_scalar_no_indent_1_1_raise(self): - from ruamel.yaml.parser import ParserError + def test_root_literal_scalar_no_indent_1_1_no_raise(self): + # from ruamel.yaml.parser import ParserError yaml = YAML() - yaml.top_level_block_style_scalar_no_indent_error_1_1 = True + yaml.root_level_block_style_scalar_no_indent_error_1_1 = True s = 'testing123' - with pytest.raises(ParserError): + # with pytest.raises(ParserError): + if True: inp = """ %YAML 1.1 --- | @@ -90,7 +91,7 @@ class TestNoIndent: """ yaml.load(inp.format(s)) - def test_top_literal_scalar_indent_offset_one(self): + def test_root_literal_scalar_indent_offset_one(self): yaml = YAML() s = 'testing123' inp = """ @@ -101,7 +102,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_scalar_indent_offset_four(self): + def test_root_literal_scalar_indent_offset_four(self): yaml = YAML() s = 'testing123' inp = """ @@ -112,7 +113,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_scalar_indent_offset_two_leading_space(self): + def test_root_literal_scalar_indent_offset_two_leading_space(self): yaml = YAML() s = ' testing123' inp = """ @@ -124,7 +125,7 @@ class TestNoIndent: print(d) assert d == (s + '\n') * 2 - def test_top_literal_scalar_no_indent_special(self): + def test_root_literal_scalar_no_indent_special(self): yaml = YAML() s = '%!PS-Adobe-2.0' inp = """ @@ -135,7 +136,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_folding_scalar_indent(self): + def test_root_folding_scalar_indent(self): yaml = YAML() s = '%!PS-Adobe-2.0' inp = """ @@ -146,7 +147,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_folding_scalar_no_indent(self): + def test_root_folding_scalar_no_indent(self): yaml = YAML() s = 'testing123' inp = """ @@ -157,7 +158,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_folding_scalar_no_indent_special(self): + def test_root_folding_scalar_no_indent_special(self): yaml = YAML() s = '%!PS-Adobe-2.0' inp = """ @@ -168,7 +169,7 @@ class TestNoIndent: print(d) assert d == s + '\n' - def test_top_literal_multi_doc(self): + def test_root_literal_multi_doc(self): yaml = YAML(typ='safe', pure=True) s1 = 'abc' s2 = 'klm' @@ -182,9 +183,43 @@ class TestNoIndent: print('d1:', d1) assert ['abc', 'klm\n'][idx] == d1 + def test_root_literal_doc_indent_directives_end(self): + yaml = YAML() + yaml.explicit_start = True + inp = """ + --- |- + %YAML 1.3 + --- + this: is a test + """ + yaml.round_trip(inp) + + def test_root_literal_doc_indent_document_end(self): + yaml = YAML() + yaml.explicit_start = True + inp = """ + --- |- + some more + ... + text + """ + yaml.round_trip(inp) + + def test_root_literal_doc_indent_marker(self): + yaml = YAML() + yaml.explicit_start = True + inp = """ + --- |2 + some more + text + """ + d = yaml.load(inp) + print(type(d), repr(d)) + yaml.round_trip(inp) + class Test_RoundTripLiteral: - def test_rt_top_literal_scalar_no_indent(self): + def test_rt_root_literal_scalar_no_indent(self): yaml = YAML() yaml.explicit_start = True s = 'testing123' @@ -196,7 +231,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_top_literal_scalar_indent(self): + def test_rt_root_literal_scalar_indent(self): yaml = YAML() yaml.explicit_start = True yaml.indent = 4 @@ -209,7 +244,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_top_plain_scalar_no_indent(self): + def test_rt_root_plain_scalar_no_indent(self): yaml = YAML() yaml.explicit_start = True yaml.indent = 0 @@ -222,7 +257,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_top_plain_scalar_expl_indent(self): + def test_rt_root_plain_scalar_expl_indent(self): yaml = YAML() yaml.explicit_start = True yaml.indent = 4 @@ -235,7 +270,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_top_sq_scalar_expl_indent(self): + def test_rt_root_sq_scalar_expl_indent(self): yaml = YAML() yaml.explicit_start = True yaml.indent = 4 @@ -248,7 +283,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_top_dq_scalar_expl_indent(self): + def test_rt_root_dq_scalar_expl_indent(self): # if yaml.indent is the default (None) # then write after the directive indicator yaml = YAML() @@ -263,7 +298,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_top_literal_scalar_no_indent_no_eol(self): + def test_rt_root_literal_scalar_no_indent_no_eol(self): yaml = YAML() yaml.explicit_start = True s = 'testing123' @@ -275,7 +310,7 @@ class Test_RoundTripLiteral: d = yaml.load(ys) yaml.dump(d, compare=ys) - def test_rt_non_top_literal_scalar(self): + def test_rt_non_root_literal_scalar(self): yaml = YAML() s = 'testing123' ys = """ |