diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-10-02 10:26:40 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-10-02 10:26:40 +0200 |
commit | cdbd44762e625d6719299b29ce1906d5995e6da3 (patch) | |
tree | 4239364cae99c15d196e98cdd50c617b606b1a6b /_test | |
parent | 2817f01eb77a9daeacec6c54314865c08541df3e (diff) | |
download | ruamel.yaml-cdbd44762e625d6719299b29ce1906d5995e6da3.tar.gz |
test hierarchy, per file creation/loading of YAML
Diffstat (limited to '_test')
-rw-r--r-- | _test/roundtrip.py | 3 | ||||
-rw-r--r-- | _test/test_z_data.py | 32 |
2 files changed, 20 insertions, 15 deletions
diff --git a/_test/roundtrip.py b/_test/roundtrip.py index ac1d725..8e1e66e 100644 --- a/_test/roundtrip.py +++ b/_test/roundtrip.py @@ -251,7 +251,8 @@ def save_and_run(program, base_dir=None, output=None, file_name=None, optimized= print('running:', *cmd) res = check_output(cmd, stderr=STDOUT, universal_newlines=True) if output is not None: - print('res', res) + print('result: ', res, end='') + print('expected:', output, end='') assert res == output except CalledProcessError as exception: print("##### Running '{} {}' FAILED #####".format(sys.executable, file_name)) diff --git a/_test/test_z_data.py b/_test/test_z_data.py index 213ad66..35c1ded 100644 --- a/_test/test_z_data.py +++ b/_test/test_z_data.py @@ -77,20 +77,12 @@ class Assert(YAMLData): def pytest_generate_tests(metafunc): - from ruamel.yaml import YAML - - yaml = YAML(typ='safe', pure=True) - yaml.register_class(YAMLData) - yaml.register_class(Python) - yaml.register_class(Output) - yaml.register_class(Assert) test_yaml = [] - paths = sorted(base_path.glob('*.yaml')) + paths = sorted(base_path.glob('**/*.yaml')) idlist = [] for path in paths: idlist.append(path.stem) - x = yaml.load_all(path) - test_yaml.append([list(x)]) + test_yaml.append([path]) metafunc.parametrize(['yaml'], test_yaml, ids=idlist, scope='class') @@ -104,6 +96,16 @@ class TestYAMLData(object): y.version = yaml_version return y + def docs(self, path): + from ruamel.yaml import YAML + + tyaml = YAML(typ='safe', pure=True) + tyaml.register_class(YAMLData) + tyaml.register_class(Python) + tyaml.register_class(Output) + tyaml.register_class(Assert) + return list(tyaml.load_all(path)) + def yaml_load(self, value, yaml_version=None): yaml = self.yaml(yaml_version=yaml_version) data = yaml.load(value) @@ -150,13 +152,15 @@ class TestYAMLData(object): idx = 0 typ = None yaml_version = None - if isinstance(yaml[0], Mapping): - d = yaml[0] + + docs = self.docs(yaml) + if isinstance(docs[0], Mapping): + d = docs[0] typ = d.get('type') yaml_version = d.get('yaml_version') idx += 1 data = output = confirm = python = None - for doc in yaml[idx:]: + for doc in docs[idx:]: if isinstance(doc, Output): output = doc elif isinstance(doc, Assert): @@ -184,7 +188,7 @@ class TestYAMLData(object): if typ == 'rt': self.round_trip(data, output, yaml_version=yaml_version) elif typ == 'pyrun': - self.run_python(python, data, tmpdir) + self.run_python(python, output if output is not None else data, tmpdir) elif typ == 'load_assert': self.load_assert(data, confirm, yaml_version=yaml_version) else: |