summaryrefslogtreecommitdiff
path: root/_test/test_z_data.py
diff options
context:
space:
mode:
Diffstat (limited to '_test/test_z_data.py')
-rw-r--r--_test/test_z_data.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/_test/test_z_data.py b/_test/test_z_data.py
index dcd6bd0..e48e9d5 100644
--- a/_test/test_z_data.py
+++ b/_test/test_z_data.py
@@ -1,10 +1,12 @@
# coding: utf-8
import sys
+import os
import pytest # NOQA
import warnings # NOQA
+from pathlib import Path
-from ruamel.std.pathlib import Path
+from ruamel.yaml.compat import _F
base_path = Path('data') # that is ruamel.yaml.data
@@ -82,6 +84,11 @@ def pytest_generate_tests(metafunc):
paths = sorted(base_path.glob('**/*.yaml'))
idlist = []
for path in paths:
+ # while developing tests put them in data/debug and run:
+ # auto -c "pytest _test/test_z_data.py" data/debug/*.yaml *.py _test/*.py
+ if os.environ.get('RUAMELAUTOTEST') == '1':
+ if path.parent.stem != 'debug':
+ continue
stem = path.stem
if stem.startswith('.#'): # skip emacs temporary file
continue
@@ -144,13 +151,32 @@ class TestYAMLData(object):
print(line)
exec(line)
- def run_python(self, python, data, tmpdir):
+ def run_python(self, python, data, tmpdir, input=None):
from roundtrip import save_and_run
+ if input is not None:
+ (tmpdir / 'input.yaml').write_text(input.value, encoding='utf-8')
assert save_and_run(python.value, base_dir=tmpdir, output=data.value) == 0
- # this is executed by pytest the methods with names not starting with test_
- # are helpers
+ def insert_comments(self, data, actions):
+ """this is to automatically insert based on:
+ path (a.1.b),
+ position (before, after, between), and
+ offset (absolute/relative)
+ """
+ raise NotImplementedError
+ expected = []
+ for line in data.value.splitlines(True):
+ idx = line.index['?']
+ if idx < 0:
+ expected.append(line)
+ continue
+ assert line.lstrip()[0] == '#' # it has to be comment line
+ print(data)
+ assert ''.join(expected) == data.value
+
+ # this is executed by pytest the methods with names not starting with
+ # test_ are helper methods
def test_yaml_data(self, yaml, tmpdir):
from collections.abc import Mapping
@@ -197,11 +223,15 @@ class TestYAMLData(object):
if typ == 'rt':
self.round_trip(data, output, yaml_version=yaml_version)
elif typ == 'python_run':
- self.run_python(python, output if output is not None else data, tmpdir)
+ inp = None if output is None or data is None else data
+ self.run_python(python, output if output is not None else data, tmpdir, input=inp)
elif typ == 'load_assert':
self.load_assert(data, confirm, yaml_version=yaml_version)
+ elif typ == 'comment':
+ actions = []
+ self.insert_comments(data, actions)
else:
- print('\nrun type unknown:', typ)
+ _F('\n>>>>>> run type unknown: "{typ}" <<<<<<\n')
raise AssertionError()