def test_complex_yaml_yaml(complex_yaml_old, complex_yaml_new, complex_result_yaml): format_diff = gendiff.formatters.yaml.format_diff old_map, new_map = parse_yaml(complex_yaml_old), parse_yaml(complex_yaml_new) test_diff = yaml.load(format_diff(generate_diff(old_map, new_map)), Loader=yaml.SafeLoader) ethalon_diff = yaml.load(complex_result_yaml, Loader=yaml.SafeLoader) assert test_diff == ethalon_diff
def test_yaml_parse(): yaml_data = """ host: hexlet.io timeout: 50 proxy: "123.234.53.22" """ expected = { 'host': 'hexlet.io', 'timeout': 50, 'proxy': '123.234.53.22', } assert parsers.parse_yaml(yaml_data) == expected
def test_plain_yaml(plain_yaml_old, plain_yaml_new, plain_result_plain): format_diff = gendiff.formatters.plain.format_diff old_map, new_map = parse_yaml(plain_yaml_old), parse_yaml(plain_yaml_new) test_diff = format_diff(generate_diff(old_map, new_map)) ethalon_diff = plain_result_plain.read() assert test_diff == ethalon_diff
def test_complex_yaml_tree(complex_yaml_old, complex_yaml_new, complex_result_tree): format_diff = gendiff.formatters.tree.format_diff old_map, new_map = parse_yaml(complex_yaml_old), parse_yaml(complex_yaml_new) test_diff = format_diff(generate_diff(old_map, new_map)) ethalon_diff = complex_result_tree.read() assert test_diff == ethalon_diff
def get_parsed(file): _, ext = splitext(file.name) if ext in ['.json']: return parse_json(file) elif ext in ['.yaml', 'yml']: return parse_yaml(file)