def test_issue_232(self): import ruyaml with pytest.raises(ruyaml.parser.ParserError): ruyaml.safe_load(']') with pytest.raises(ruyaml.parser.ParserError): ruyaml.safe_load('{]')
def test_duplicate_key_00(self): from ruyaml import round_trip_load, safe_load, version_info from ruyaml.constructor import DuplicateKeyError, DuplicateKeyFutureWarning s = dedent( """\ &anchor foo: foo: bar *anchor : duplicate key baz: bat *anchor : duplicate key """ ) if version_info < (0, 15, 1): pass elif version_info < (0, 16, 0): with pytest.warns(DuplicateKeyFutureWarning): safe_load(s) with pytest.warns(DuplicateKeyFutureWarning): round_trip_load(s) else: with pytest.raises(DuplicateKeyError): safe_load(s) with pytest.raises(DuplicateKeyError): round_trip_load(s)
def test_duplicate_key_00(self): from ruyaml import round_trip_load, safe_load from ruyaml.constructor import DuplicateKeyError s = dedent("""\ &anchor foo: foo: bar *anchor : duplicate key baz: bat *anchor : duplicate key """) with pytest.raises(DuplicateKeyError): safe_load(s) with pytest.raises(DuplicateKeyError): round_trip_load(s)
def test_issue_130a(self): # issue 130 reported by Devid Fee import ruyaml ys = dedent( """\ components: server: &server_component type: spark.server:ServerComponent host: 0.0.0.0 port: 8000 shell: &shell_component type: spark.shell:ShellComponent services: server: &server_service <<: *server_component port: 4000 shell: &shell_service <<: *shell_component components: server: {<<: *server_service} """ ) data = ruyaml.safe_load(ys) assert data['services']['shell']['components']['server']['port'] == 4000
def test_merge_items(self): from ruyaml import safe_load d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) count = 0 for x in data[2].items(): count += 1 print(count, x) assert count == len(d[2])
def __init__(self): self.project_root_directory = os.getcwd() if os.path.exists('DragonMake'): with open('DragonMake') as f: self.config = yaml.safe_load(f) self.preexisting_config = True else: self.config = {} self.preexisting_config = False
def test_root_literal_scalar_no_indent_1_1_old_style(self): from textwrap import dedent from ruyaml import safe_load s = 'testing123' inp = """ %YAML 1.1 --- | {} """ d = safe_load(dedent(inp.format(s))) print(d) assert d == s + '\n'
def test_len_items_delete(self): from ruyaml import safe_load d = safe_load(self.yaml_str) data = round_trip_load(self.yaml_str) x = data[2].items() print('d2 items', d[2].items(), len(d[2].items()), x, len(x)) ref = len(d[2].items()) print('ref', ref) assert len(x) == ref del data[2]['m'] ref -= 1 assert len(x) == ref del data[2]['d'] ref -= 1 assert len(x) == ref del data[2]['a'] ref -= 1 assert len(x) == ref