diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-29 12:43:53 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-29 12:43:53 +0200 |
commit | 33f0d0b44b6272a572cc14494ea788c867ae190f (patch) | |
tree | 06da720c5e9c3b0a8a49ff7e8a249c887657bfd1 | |
parent | 375df52e3851ac08bf47cdaa12d319997c9a4a4a (diff) | |
download | ruamel.yaml-33f0d0b44b6272a572cc14494ea788c867ae190f.tar.gz |
cleanup of commented out xfails, added some (most failing) rt tests for spec examples
-rw-r--r-- | _test/roundtrip.py | 19 | ||||
-rw-r--r-- | _test/test_api_change.py | 1 | ||||
-rw-r--r-- | _test/test_comment_manipulation.py | 4 | ||||
-rw-r--r-- | _test/test_contextmanager.py | 3 | ||||
-rw-r--r-- | _test/test_float.py | 2 | ||||
-rw-r--r-- | _test/test_int.py | 1 | ||||
-rw-r--r-- | _test/test_issues.py | 2 | ||||
-rw-r--r-- | _test/test_spec_examples.py | 290 | ||||
-rw-r--r-- | _test/test_yamlfile.py | 1 |
9 files changed, 311 insertions, 12 deletions
diff --git a/_test/roundtrip.py b/_test/roundtrip.py index fa9d189..684bd45 100644 --- a/_test/roundtrip.py +++ b/_test/roundtrip.py @@ -195,7 +195,7 @@ def YAML(**kw): def round_trip(self, stream, **kw): from ruamel.yaml.compat import StringIO, BytesIO # NOQA - assert isinstance(stream, ruamel.yaml.compat.text_type) + assert isinstance(stream, (ruamel.yaml.compat.text_type, str)) lkw = kw.copy() if stream and stream[0] == '\n': stream = stream[1:] @@ -209,6 +209,23 @@ def YAML(**kw): diff(outp, res, 'input string') assert res == outp + def round_trip_all(self, stream, **kw): + from ruamel.yaml.compat import StringIO, BytesIO # NOQA + + assert isinstance(stream, (ruamel.yaml.compat.text_type, str)) + lkw = kw.copy() + if stream and stream[0] == '\n': + stream = stream[1:] + stream = textwrap.dedent(stream) + data = list(ruamel.yaml.YAML.load_all(self, stream)) + outp = lkw.pop('outp', stream) + lkw['stream'] = st = StringIO() + ruamel.yaml.YAML.dump_all(self, data, **lkw) + res = st.getvalue() + if res != outp: + diff(outp, res, 'input string') + assert res == outp + return MyYAML(**kw) diff --git a/_test/test_api_change.py b/_test/test_api_change.py index b5b3d00..b7c3290 100644 --- a/_test/test_api_change.py +++ b/_test/test_api_change.py @@ -29,7 +29,6 @@ class TestNewAPI: with pytest.raises(DuplicateKeyError): yaml.load('{a: 1, a: 2}') - # @pytest.mark.xfail(strict=True) def test_duplicate_keys_02(self): from ruamel.yaml import YAML from ruamel.yaml.constructor import DuplicateKeyError diff --git a/_test/test_comment_manipulation.py b/_test/test_comment_manipulation.py index ad0a768..7f09a38 100644 --- a/_test/test_comment_manipulation.py +++ b/_test/test_comment_manipulation.py @@ -21,9 +21,6 @@ def compare_eol(data, s): assert round_trip_dump(data).replace('\n', '|\n') == ds -# @pytest.mark.xfail - - class TestCommentsManipulation: # list @@ -244,7 +241,6 @@ class TestCommentsManipulation: """ compare(data, exp) - # @pytest.mark.xfail def test_before_top_map_rt(self): data = load(""" a: 1 diff --git a/_test/test_contextmanager.py b/_test/test_contextmanager.py index 7216473..b3bb3be 100644 --- a/_test/test_contextmanager.py +++ b/_test/test_contextmanager.py @@ -89,6 +89,9 @@ class TestContextManager: print(err) assert out == multi_doc + # input is not as simple with a context manager + # you need to indicate what you expect hence load and load_all + # @pytest.mark.xfail(strict=True) # def test_single_load(self): # from ruamel.yaml import YAML diff --git a/_test/test_float.py b/_test/test_float.py index 146793b..56a6b4a 100644 --- a/_test/test_float.py +++ b/_test/test_float.py @@ -49,7 +49,6 @@ class TestFloat: for d in data: assert -0.00001 < d < 0.00001 - # @pytest.mark.xfail(strict=True) def test_round_trip_zeros_1(self): # not sure if this should be supported, but it is data = round_trip("""\ @@ -79,7 +78,6 @@ class TestFloat: for d in data: assert 41.99e56 < d < 42.01e56 - # @pytest.mark.xfail(strict=True) def test_round_trip_exp_00f(self): data = round_trip("""\ - 42.E56 diff --git a/_test/test_int.py b/_test/test_int.py index 22ac3bc..b995f59 100644 --- a/_test/test_int.py +++ b/_test/test_int.py @@ -10,7 +10,6 @@ from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump class TestBinHexOct: - # @pytest.mark.xfail(strict=True) def test_round_trip_hex_oct(self): round_trip("""\ - 42 diff --git a/_test/test_issues.py b/_test/test_issues.py index ec793ea..1276381 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -305,5 +305,3 @@ class TestIssues: yaml = ruamel.yaml.YAML(typ='safe') yaml.load('phone: 0123456789') - - # @pytest.mark.xfail(strict=True) diff --git a/_test/test_spec_examples.py b/_test/test_spec_examples.py new file mode 100644 index 0000000..6661698 --- /dev/null +++ b/_test/test_spec_examples.py @@ -0,0 +1,290 @@ +from roundtrip import YAML +import pytest # NOQA + + +def test_example_2_1(): + yaml = YAML() + yaml.round_trip(""" + - Mark McGwire + - Sammy Sosa + - Ken Griffey + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_2(): + yaml = YAML() + yaml.mapping_value_align = True + yaml.round_trip(""" + hr: 65 # Home runs + avg: 0.278 # Batting average + rbi: 147 # Runs Batted In + """) + + +def test_example_2_3(): + yaml = YAML() + yaml.indent(sequence=4, offset=2) + yaml.round_trip(""" + american: + - Boston Red Sox + - Detroit Tigers + - New York Yankees + national: + - New York Mets + - Chicago Cubs + - Atlanta Braves + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_4(): + yaml = YAML() + yaml.mapping_value_align = True + yaml.round_trip(""" + - + name: Mark McGwire + hr: 65 + avg: 0.278 + - + name: Sammy Sosa + hr: 63 + avg: 0.288 + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_5(): + yaml = YAML() + yaml.flow_sequence_element_align = True + yaml.round_trip(""" + - [name , hr, avg ] + - [Mark McGwire, 65, 0.278] + - [Sammy Sosa , 63, 0.288] + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_6(): + yaml = YAML() + # yaml.flow_mapping_final_comma = False + yaml.flow_mapping_one_element_per_line = True + yaml.round_trip(""" + Mark McGwire: {hr: 65, avg: 0.278} + Sammy Sosa: { + hr: 63, + avg: 0.288 + } + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_7(): + yaml = YAML() + yaml.round_trip_all(""" + # Ranking of 1998 home runs + --- + - Mark McGwire + - Sammy Sosa + - Ken Griffey + + # Team ranking + --- + - Chicago Cubs + - St Louis Cardinals + """) + + +def test_example_2_8(): + yaml = YAML() + yaml.explicit_start = True + yaml.explicit_end = True + yaml.round_trip_all(""" + --- + time: 20:03:20 + player: Sammy Sosa + action: strike (miss) + ... + --- + time: 20:03:47 + player: Sammy Sosa + action: grand slam + ... + """) + + +def test_example_2_9(): + yaml = YAML() + yaml.explicit_start = True + yaml.indent(sequence=4, offset=2) + yaml.round_trip(""" + --- + hr: # 1998 hr ranking + - Mark McGwire + - Sammy Sosa + rbi: + # 1998 rbi ranking + - Sammy Sosa + - Ken Griffey + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_10(): + yaml = YAML() + yaml.explicit_start = True + yaml.indent(sequence=4, offset=2) + yaml.round_trip(""" + --- + hr: + - Mark McGwire + # Following node labeled SS + - &SS Sammy Sosa + rbi: + - *SS # Subsequent occurrence + - Ken Griffey + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_11(): + yaml = YAML() + yaml.round_trip(""" + ? - Detroit Tigers + - Chicago cubs + : + - 2001-07-23 + + ? [ New York Yankees, + Atlanta Braves ] + : [ 2001-07-02, 2001-08-12, + 2001-08-14 ] + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_12(): + yaml = YAML() + yaml.explicit_start = True + yaml.round_trip(""" + --- + # Products purchased + - item : Super Hoop + quantity: 1 + - item : Basketball + quantity: 4 + - item : Big Shoes + quantity: 1 + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_13(): + yaml = YAML() + yaml.round_trip(""" + # ASCII Art + --- | + \//||\/|| + // || ||__ + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_14(): + yaml = YAML() + yaml.explicit_start = True + yam.indent(root_scalar=2) # needs to be added + yaml.round_trip(""" + --- > + Mark McGwire's + year was crippled + by a knee injury. + """) + + +@pytest.mark.xfail(strict=True) +def test_example_2_15(): + yaml = YAML() + yaml.round_trip(""" + > + Sammy Sosa completed another + fine season with great stats. + + 63 Home Runs + 0.288 Batting Average + + What a year! + """) + + +def test_example_2_16(): + yaml = YAML() + yaml.round_trip(""" + name: Mark McGwire + accomplishment: > + Mark set a major league + home run record in 1998. + stats: | + 65 Home Runs + 0.278 Batting Average + """) + + +@pytest.mark.xfail( + strict=True, reason='cannot YAML dump escape sequences (\n) as hex and normal' +) +def test_example_2_17(): + yaml = YAML() + yaml.allow_unicode = False + yaml.preserve_quotes = True + yaml.round_trip(r""" + unicode: "Sosa did fine.\u263A" + control: "\b1998\t1999\t2000\n" + hex esc: "\x0d\x0a is \r\n" + + single: '"Howdy!" he cried.' + quoted: ' # Not a ''comment''.' + tie-fighter: '|\-*-/|' + """) + + +@pytest.mark.xfail(strict=True, reason='non-literal/folding multiline scalars not supported') +def test_example_2_18(): + yaml = YAML() + yaml.round_trip(""" + plain: + This unquoted scalar + spans many lines. + + quoted: "So does this + quoted scalar.\n" + """) + + +@pytest.mark.xfail(strict=True, reason='leading + on decimal dropped') +def test_example_2_19(): + yaml = YAML() + yaml.round_trip(""" + canonical: 12345 + decimal: +12345 + octal: 0o14 + hexadecimal: 0xC + """) + + +@pytest.mark.xfail(strict=True, reason='case of NaN not preserved') +def test_example_2_20(): + yaml = YAML() + yaml.round_trip(""" + canonical: 1.23015e+3 + exponential: 12.3015e+02 + fixed: 1230.15 + negative infinity: -.inf + not a number: .NaN + """) + + +def Xtest_example_2_X(): + yaml = YAML() + yaml.round_trip(""" + """) diff --git a/_test/test_yamlfile.py b/_test/test_yamlfile.py index 52cdaa5..8144c74 100644 --- a/_test/test_yamlfile.py +++ b/_test/test_yamlfile.py @@ -97,7 +97,6 @@ class TestYAML: c: null """) - # @pytest.mark.xfail # ordering is not preserved in a set def test_set_compact(self): # this format is read and also should be written by default |