summaryrefslogtreecommitdiff
path: root/_test/test_api_change.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/test_api_change.py')
-rw-r--r--_test/test_api_change.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/_test/test_api_change.py b/_test/test_api_change.py
index 65789f4..59473fe 100644
--- a/_test/test_api_change.py
+++ b/_test/test_api_change.py
@@ -9,31 +9,35 @@ testing of anchors and the aliases referring to them
import sys
import textwrap
import pytest
-from ruamel.yaml import YAML, safe_load
-from ruamel.yaml.constructor import DuplicateKeyError, DuplicateKeyFutureWarning
from ruamel.std.pathlib import Path
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}')
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}')
# @pytest.mark.xfail(strict=True)
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}')
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):
@@ -41,6 +45,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)
@@ -48,6 +53,7 @@ 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()
@@ -57,6 +63,7 @@ class TestWrite:
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()
@@ -67,6 +74,7 @@ class TestWrite:
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
@@ -75,6 +83,7 @@ class TestWrite:
yaml.dump(data)
def test_dump_too_many_args(self, tmpdir):
+ from ruamel.yaml import YAML
fn = Path(str(tmpdir)) / 'test.yaml'
yaml = YAML()
data = yaml.map()
@@ -84,6 +93,8 @@ class TestWrite:
yaml.dump(data, fn, True)
def test_transform(self, tmpdir):
+ from ruamel.yaml import YAML
+
def tr(s):
return s.replace(' ', ' ')
@@ -96,6 +107,7 @@ class TestWrite:
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
@@ -108,6 +120,7 @@ class TestWrite:
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
@@ -116,6 +129,7 @@ class TestRead:
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"""\
---
@@ -131,6 +145,8 @@ class TestLoadAll:
class TestDuplSet:
def test_dupl_set_00(self):
# 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("""\
@@ -146,6 +162,7 @@ class TestDumpLoadUnicode:
# test triggered by SamH on stackoverflow (https://stackoverflow.com/q/45281596/1307905)
# 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©"}
file_name = str(tmpdir) + '/tstFile.yaml'
@@ -153,6 +170,7 @@ class TestDumpLoadUnicode:
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:
@@ -164,6 +182,7 @@ class TestDumpLoadUnicode:
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()
@@ -179,5 +198,7 @@ class TestOldAPI:
@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')