def test_issue_288a(self): import sys from io import StringIO from ruyaml import YAML yamldoc = dedent( """\ --- # Reusable values aliases: # First-element comment - &firstEntry First entry # Second-element comment - &secondEntry Second entry # Third-element comment is # a multi-line value - &thirdEntry Third entry # EOF Comment """ ) yaml = YAML() yaml.indent(mapping=2, sequence=4, offset=2) yaml.explicit_start = True yaml.preserve_quotes = True yaml.width = sys.maxsize data = yaml.load(yamldoc) buf = StringIO() yaml.dump(data, buf) assert buf.getvalue() == yamldoc
def test_example_2_14(): yaml = YAML() yaml.explicit_start = True yaml.indent(root_scalar=2) # needs to be added yaml.round_trip(""" --- > Mark McGwire's year was crippled by a knee injury. """)
def test_02(self): yaml = YAML() yaml.indent(mapping=5, sequence=6, offset=3) inp = """ a: b: - 1 - [1, 2] """ yaml.round_trip(inp)
def test_01(self): yaml = YAML() yaml.indent(sequence=6) yaml.indent(offset=3) inp = """ a: - 1 - {b: 3} """ yaml.round_trip(inp)
def test_04(self): yaml = YAML() yaml.indent(mapping=5, sequence=6) inp = """ a: b: - 1 - [1, 2] - {d: 3.14} """ yaml.round_trip(inp)
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 """)
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 """)
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 """)
def test_issue_51(self): yaml = YAML() # yaml.map_indent = 2 # the default yaml.indent(sequence=4, offset=2) yaml.preserve_quotes = True yaml.round_trip(""" role::startup::author::rsyslog_inputs: imfile: - ruleset: 'AEM-slinglog' File: '/opt/aem/author/crx-quickstart/logs/error.log' startmsg.regex: '^[-+T.:[:digit:]]*' tag: 'error' - ruleset: 'AEM-slinglog' File: '/opt/aem/author/crx-quickstart/logs/stdout.log' startmsg.regex: '^[-+T.:[:digit:]]*' tag: 'stdout' """)
def test_00(self): # old style yaml = YAML() yaml.indent = 6 yaml.block_seq_indent = 3 inp = """ a: - 1 - [1, 2] """ yaml.round_trip(inp)
def test_rt_root_sq_scalar_expl_indent(self): yaml = YAML() yaml.explicit_start = True yaml.indent = 4 s = "'testing: 123'" ys = """ --- {} """ ys = ys.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys)
def test_rt_root_plain_scalar_no_indent(self): yaml = YAML() yaml.explicit_start = True yaml.indent = 0 s = 'testing123' ys = """ --- {} """ ys = ys.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys)
def test_issue_279(self): from io import StringIO from ruyaml import YAML yaml = YAML() yaml.indent(sequence=4, offset=2) inp = dedent( """\ experiments: - datasets: # ATLAS EWK - {dataset: ATLASWZRAP36PB, frac: 1.0} - {dataset: ATLASZHIGHMASS49FB, frac: 1.0} """ ) a = yaml.load(inp) buf = StringIO() yaml.dump(a, buf) print(buf.getvalue()) assert buf.getvalue() == inp
def test_issue_290a(self): import sys from io import StringIO from ruyaml import YAML yamldoc = dedent( """\ --- aliases: # Folded-element comment # for a multi-line value - &FoldedEntry > THIS IS A FOLDED, MULTI-LINE VALUE # Literal-element comment # for a multi-line value - &literalEntry | THIS IS A LITERAL, MULTI-LINE VALUE # Plain-element comment - &plainEntry Plain entry """ ) yaml = YAML() yaml.indent(mapping=2, sequence=4, offset=2) yaml.explicit_start = True yaml.preserve_quotes = True yaml.width = sys.maxsize data = yaml.load(yamldoc) buf = StringIO() yaml.dump(data, buf) assert buf.getvalue() == yamldoc
def test_rt_root_dq_scalar_expl_indent(self): # if yaml.indent is the default (None) # then write after the directive indicator yaml = YAML() yaml.explicit_start = True yaml.indent = 0 s = '"\'testing123"' ys = """ --- {} """ ys = ys.format(s) d = yaml.load(ys) yaml.dump(d, compare=ys)