summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-15 16:14:33 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-15 16:14:33 +0200
commitd89af927856c1f7f24cbc71045ae04e1cd375071 (patch)
tree1d5e1c6f30109daffedff8c2aa3bb132efdab4a6
parent8e1e0fb0fd47e5c62ff9d9e2b12f44e060e16da6 (diff)
downloadruamel.yaml-d89af927856c1f7f24cbc71045ae04e1cd375071.tar.gz
added failing test re #220 .pop optimized away
-rw-r--r--_test/roundtrip.py7
-rw-r--r--_test/test_issues.py21
2 files changed, 23 insertions, 5 deletions
diff --git a/_test/roundtrip.py b/_test/roundtrip.py
index c9b4ffb..462dfc6 100644
--- a/_test/roundtrip.py
+++ b/_test/roundtrip.py
@@ -209,7 +209,7 @@ def YAML(**kw):
return MyYAML(**kw)
-def save_and_run(program, base_dir=None, file_name=None):
+def save_and_run(program, base_dir=None, file_name=None, optimized=False):
"""
safe and run a python program, thereby circumventing any restrictions on module level
imports
@@ -224,7 +224,10 @@ def save_and_run(program, base_dir=None, file_name=None):
file_name.write_text(dedent(program))
try:
- cmd = [sys.executable, str(file_name)]
+ cmd = [sys.executable]
+ if optimized:
+ cmd.append('-O')
+ cmd.append(str(file_name))
print('running:', *cmd)
check_output(cmd, stderr=STDOUT, universal_newlines=True)
except CalledProcessError as exception:
diff --git a/_test/test_issues.py b/_test/test_issues.py
index ce8440a..563fdbc 100644
--- a/_test/test_issues.py
+++ b/_test/test_issues.py
@@ -33,7 +33,7 @@ class TestIssues:
assert str(data['comb']) == "ordereddict([('key', 'value'), ('key1', 'value1')])"
def test_issue_82(self, tmpdir):
- program_src = dedent('''\
+ program_src = r'''
from __future__ import print_function
from ruamel import yaml
@@ -76,8 +76,8 @@ class TestIssues:
""", Loader=yaml.Loader)
for idx, l in enumerate([1, 2, 3, 10000, 100000000000]):
assert int(ret[idx]) == l
- ''')
- assert save_and_run(program_src, tmpdir) == 0
+ '''
+ assert save_and_run(dedent(program_src), tmpdir) == 0
def test_issue_82rt(self, tmpdir):
yaml_str = '[1, 2, 3, !si 10k, 100G]\n'
@@ -232,3 +232,18 @@ class TestIssues:
d['bar'] = 'foo'
d.yaml_add_eol_comment('test1', 'bar')
assert round_trip_dump(d) == yaml_str + 'bar: foo # test1\n'
+
+ def test_issue_220(self, tmpdir):
+ program_src = r'''
+ from ruamel.yaml import YAML
+
+ yaml_str = u"""\
+ ---
+ foo: ["bar"]
+ """
+
+ yaml = YAML(typ='safe', pure=True)
+ d = yaml.load(yaml_str)
+ print(d)
+ '''
+ assert save_and_run(dedent(program_src), tmpdir, optimized=True) == 0