From dce10fcff1de54121fb8b440b883ef5d3fe2f96a Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Fri, 3 Aug 2018 22:14:57 +0200 Subject: Apply oitnb and mypy 0.620, then make everything work again --- _test/test_api_change.py | 49 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to '_test/test_api_change.py') diff --git a/_test/test_api_change.py b/_test/test_api_change.py index 59473fe..f191c56 100644 --- a/_test/test_api_change.py +++ b/_test/test_api_change.py @@ -16,6 +16,7 @@ class TestNewAPI: def test_duplicate_keys_00(self): from ruamel.yaml import YAML from ruamel.yaml.constructor import DuplicateKeyError + yaml = YAML() with pytest.raises(DuplicateKeyError): yaml.load('{a: 1, a: 2}') @@ -23,6 +24,7 @@ class TestNewAPI: def test_duplicate_keys_01(self): from ruamel.yaml import YAML from ruamel.yaml.constructor import DuplicateKeyError + yaml = YAML(typ='safe', pure=True) with pytest.raises(DuplicateKeyError): yaml.load('{a: 1, a: 2}') @@ -31,6 +33,7 @@ class TestNewAPI: def test_duplicate_keys_02(self): from ruamel.yaml import YAML from ruamel.yaml.constructor import DuplicateKeyError + yaml = YAML(typ='safe') with pytest.raises(DuplicateKeyError): yaml.load('{a: 1, a: 2}') @@ -38,6 +41,7 @@ class TestNewAPI: def test_issue_135(self): # reported by Andrzej Ostrowski from ruamel.yaml import YAML + data = {'a': 1, 'b': 2} yaml = YAML(typ='safe') # originally on 2.7: with pytest.raises(TypeError): @@ -46,6 +50,7 @@ class TestNewAPI: def test_issue_135_temporary_workaround(self): # never raised error from ruamel.yaml import YAML + data = {'a': 1, 'b': 2} yaml = YAML(typ='safe', pure=True) yaml.dump(data, sys.stdout) @@ -54,16 +59,18 @@ class TestNewAPI: class TestWrite: def test_dump_path(self, tmpdir): from ruamel.yaml import YAML + fn = Path(str(tmpdir)) / 'test.yaml' yaml = YAML() data = yaml.map() data['a'] = 1 data['b'] = 2 yaml.dump(data, fn) - assert fn.read_text() == "a: 1\nb: 2\n" + assert fn.read_text() == 'a: 1\nb: 2\n' def test_dump_file(self, tmpdir): from ruamel.yaml import YAML + fn = Path(str(tmpdir)) / 'test.yaml' yaml = YAML() data = yaml.map() @@ -71,10 +78,11 @@ class TestWrite: data['b'] = 2 with open(str(fn), 'w') as fp: yaml.dump(data, fp) - assert fn.read_text() == "a: 1\nb: 2\n" + assert fn.read_text() == 'a: 1\nb: 2\n' def test_dump_missing_stream(self): from ruamel.yaml import YAML + yaml = YAML() data = yaml.map() data['a'] = 1 @@ -84,6 +92,7 @@ class TestWrite: def test_dump_too_many_args(self, tmpdir): from ruamel.yaml import YAML + fn = Path(str(tmpdir)) / 'test.yaml' yaml = YAML() data = yaml.map() @@ -104,23 +113,25 @@ class TestWrite: data['a'] = 1 data['b'] = 2 yaml.dump(data, fn, transform=tr) - assert fn.read_text() == "a: 1\nb: 2\n" + assert fn.read_text() == 'a: 1\nb: 2\n' def test_print(self, capsys): from ruamel.yaml import YAML + yaml = YAML() data = yaml.map() data['a'] = 1 data['b'] = 2 yaml.dump(data, sys.stdout) out, err = capsys.readouterr() - assert out == "a: 1\nb: 2\n" + assert out == 'a: 1\nb: 2\n' class TestRead: def test_multi_load(self): # make sure reader, scanner, parser get reset from ruamel.yaml import YAML + yaml = YAML() yaml.load('a: 1') yaml.load('a: 1') # did not work in 0.15.4 @@ -130,14 +141,19 @@ class TestLoadAll: def test_multi_document_load(self, tmpdir): """this went wrong on 3.7 because of StopIteration, PR 37 and Issue 211""" from ruamel.yaml import YAML + fn = Path(str(tmpdir)) / 'test.yaml' - fn.write_text(textwrap.dedent(u"""\ + fn.write_text( + textwrap.dedent( + u"""\ --- - a --- - b ... - """)) + """ + ) + ) yaml = YAML() assert list(yaml.load_all(fn)) == [['a'], ['b']] @@ -147,15 +163,20 @@ class TestDuplSet: # round-trip-loader should except from ruamel.yaml import YAML from ruamel.yaml.constructor import DuplicateKeyError + yaml = YAML() with pytest.raises(DuplicateKeyError): - yaml.load(textwrap.dedent("""\ + yaml.load( + textwrap.dedent( + """\ !!set ? a ? b ? c ? a - """)) + """ + ) + ) class TestDumpLoadUnicode: @@ -163,26 +184,29 @@ class TestDumpLoadUnicode: # and answer by randomir (https://stackoverflow.com/a/45281922/1307905) def test_write_unicode(self, tmpdir): from ruamel.yaml import YAML + yaml = YAML() - text_dict = {"text": u"HELLO_WORLD©"} + text_dict = {'text': u'HELLO_WORLD©'} file_name = str(tmpdir) + '/tstFile.yaml' yaml.dump(text_dict, open(file_name, 'w')) assert open(file_name, 'rb').read().decode('utf-8') == u'text: HELLO_WORLD©\n' def test_read_unicode(self, tmpdir): from ruamel.yaml import YAML + yaml = YAML() file_name = str(tmpdir) + '/tstFile.yaml' with open(file_name, 'wb') as fp: fp.write(u'text: HELLO_WORLD©\n'.encode('utf-8')) text_dict = yaml.load(open(file_name, 'r')) - assert text_dict["text"] == u"HELLO_WORLD©" + assert text_dict['text'] == u'HELLO_WORLD©' class TestFlowStyle: def test_flow_style(self, capsys): # https://stackoverflow.com/questions/45791712/ from ruamel.yaml import YAML + yaml = YAML() yaml.default_flow_style = None data = yaml.map() @@ -190,15 +214,16 @@ class TestFlowStyle: data['a'] = [[1, 2], [3, 4]] yaml.dump(data, sys.stdout) out, err = capsys.readouterr() - assert out == "b: 1\na:\n- [1, 2]\n- [3, 4]\n" + assert out == 'b: 1\na:\n- [1, 2]\n- [3, 4]\n' class TestOldAPI: - @pytest.mark.skipif(sys.version_info >= (3, 0), reason="ok on Py3") + @pytest.mark.skipif(sys.version_info >= (3, 0), reason='ok on Py3') @pytest.mark.xfail(strict=True) def test_duplicate_keys_02(self): # Issue 165 unicode keys in error/warning from ruamel.yaml import safe_load from ruamel.yaml.constructor import DuplicateKeyFutureWarning + with pytest.warns(DuplicateKeyFutureWarning): safe_load('type: Doméstica\ntype: International') -- cgit v1.2.1