summaryrefslogtreecommitdiff
path: root/_test/test_literal.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/test_literal.py')
-rw-r--r--_test/test_literal.py142
1 files changed, 108 insertions, 34 deletions
diff --git a/_test/test_literal.py b/_test/test_literal.py
index 0499a16..74dca3d 100644
--- a/_test/test_literal.py
+++ b/_test/test_literal.py
@@ -31,126 +31,178 @@ class TestNoIndent:
def test_top_literal_scalar_indent_example_9_5(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- |
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_literal_scalar_no_indent(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- |
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_literal_scalar_no_indent_1_1(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ d = yaml.load(
+ """
%YAML 1.1
--- |
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_literal_scalar_no_indent_1_1_old_style(self):
from textwrap import dedent
from ruamel.yaml import safe_load
+
s = 'testing123'
- d = safe_load(dedent("""
+ d = safe_load(
+ dedent(
+ """
%YAML 1.1
--- |
{}
- """.format(s)))
+ """.format(
+ s
+ )
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_literal_scalar_no_indent_1_1_raise(self):
from ruamel.yaml.parser import ParserError
+
yaml = YAML()
yaml.top_level_block_style_scalar_no_indent_error_1_1 = True
s = 'testing123'
with pytest.raises(ParserError):
- yaml.load("""
+ yaml.load(
+ """
%YAML 1.1
--- |
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
def test_top_literal_scalar_indent_offset_one(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- |1
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_literal_scalar_indent_offset_four(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- |4
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_literal_scalar_indent_offset_two_leading_space(self):
yaml = YAML()
s = ' testing123'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- |4
{s}
{s}
- """.format(s=s))
+ """.format(
+ s=s
+ )
+ )
print(d)
assert d == (s + '\n') * 2
def test_top_literal_scalar_no_indent_special(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- |
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_folding_scalar_indent(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- >
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_folding_scalar_no_indent(self):
yaml = YAML()
s = 'testing123'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- >
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
def test_top_folding_scalar_no_indent_special(self):
yaml = YAML()
s = '%!PS-Adobe-2.0'
- d = yaml.load("""
+ d = yaml.load(
+ """
--- >
{}
- """.format(s))
+ """.format(
+ s
+ )
+ )
print(d)
assert d == s + '\n'
@@ -158,12 +210,18 @@ class TestNoIndent:
yaml = YAML(typ='safe', pure=True)
s1 = 'abc'
s2 = 'klm'
- for idx, d1 in enumerate(yaml.load_all("""
+ for idx, d1 in enumerate(
+ yaml.load_all(
+ """
--- |-
{}
--- |
{}
- """.format(s1, s2))):
+ """.format(
+ s1, s2
+ )
+ )
+ ):
print('d1:', d1)
assert ['abc', 'klm\n'][idx] == d1
@@ -176,7 +234,9 @@ class Test_RoundTripLiteral:
ys = """
--- |
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -188,7 +248,9 @@ class Test_RoundTripLiteral:
ys = """
--- |
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -200,7 +262,9 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -212,7 +276,9 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -224,7 +290,9 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -238,7 +306,9 @@ class Test_RoundTripLiteral:
ys = """
---
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -249,7 +319,9 @@ class Test_RoundTripLiteral:
ys = """
--- |-
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)
@@ -259,6 +331,8 @@ class Test_RoundTripLiteral:
ys = """
- |
{}
- """.format(s)
+ """.format(
+ s
+ )
d = yaml.load(ys)
yaml.dump(d, compare=ys)