diff --git a/ck b/ck index 0c9cfa1..9cf80c3 100755 --- a/ck +++ b/ck @@ -65,7 +65,7 @@ if [ ! -f .cutekit/tools-ready ]; then mkdir -p .cutekit if [ ! -d .cutekit/venv ]; then echo "Setting up Python virtual environment..." - python3 -m venv .cutekit/venv + python3.11 -m venv .cutekit/venv fi source .cutekit/venv/bin/activate diff --git a/meta/plugins/reftest.py b/meta/plugins/reftest.py index f0509ec..ac82e7f 100644 --- a/meta/plugins/reftest.py +++ b/meta/plugins/reftest.py @@ -1,8 +1,11 @@ from cutekit import shell, vt100, cli, builder, model -from pathlib import Path +from pathlib import Path, PurePath import dataclasses as dt from dataclasses_json import DataClassJsonMixin import tempfile +import re +import textwrap +import difflib def buildPaperMuncher(args: model.TargetArgs) -> builder.ProductScope: @@ -38,3 +41,58 @@ def _(args: model.TargetArgs): print(f"{vt100.GREEN}Passed{vt100.RESET}") else: print(f"{vt100.RED}Failed{vt100.RESET}") + + for file in shell.find("tests", ["*.xml"]): + print(f"Running comparison test {file}...") + + temp = Path(file).parent / '.tmp.xhtml' + + with Path(file).open() as ref: + content = ref.read() + + for name, test in re.findall(r"""([\w\W]+?)""", content): + search = re.search(r"""([\w\W]+?)""", content) + container = search and search.group(1) + + ref = None + ref_xhtml = None + for rendering in re.findall(r"""([\w\W]+?)""", test): + if container: + xhtml = container.replace("", rendering) + else: + xhtml = rendering + + with temp.open("w") as f: + f.write(f"\n{textwrap.dedent(xhtml)}") + + output = paperMuncher.popen("html2pdf", "-sdlpo", "/dev/null", temp) + + if not ref_xhtml: + ref_xhtml = rendering + ref = output + continue + + ref_result = ref.split('---')[-3] + output_result = output.split('---')[-3] + + if ref_result == output_result: + print(f"{vt100.GREEN}Passed{vt100.RESET}") + else: + print(f"{vt100.RED}Failed {name!r}{vt100.RESET}") + print(textwrap.dedent(ref_xhtml).strip()) + print(f"{vt100.RED}{textwrap.dedent(rendering).strip()}{vt100.RESET}") + + diff_html = [] + theDiffs = difflib.ndiff(ref_result.splitlines(), output_result.splitlines()) + for eachDiff in theDiffs: + if eachDiff[0] == "-": + diff_html.append(f"{vt100.RED}{eachDiff}{vt100.RESET}") + elif eachDiff[0] == "+": + diff_html.append(f"{vt100.GREEN}{eachDiff}{vt100.RESET}") + elif eachDiff[0] != "?": + diff_html.append(eachDiff) + print('\n'.join(diff_html)) + + break + + temp.unlink() diff --git a/tests/css/flex.xml b/tests/css/flex.xml new file mode 100644 index 0000000..c07d72e --- /dev/null +++ b/tests/css/flex.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+
+