From ce81106eb9a12b6ddc47f5e93189842c8349d0f3 Mon Sep 17 00:00:00 2001 From: Gorash Date: Thu, 19 Sep 2024 18:14:28 +0200 Subject: [PATCH] [IMP] add some comparison testing for flex box --- ck | 2 +- meta/plugins/reftest.py | 66 ++++++++- tests/css/display-block.xml | 259 ++++++++++++++++++++++++++++++++++++ tests/css/display-flex.xml | 97 ++++++++++++++ 4 files changed, 420 insertions(+), 4 deletions(-) create mode 100644 tests/css/display-block.xml create mode 100644 tests/css/display-flex.xml 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..4c5b69f 100644 --- a/meta/plugins/reftest.py +++ b/meta/plugins/reftest.py @@ -1,8 +1,8 @@ from cutekit import shell, vt100, cli, builder, model from pathlib import Path -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 +38,63 @@ 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 tag, rendering in re.findall(r"""<(rendering|error)>([\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] + + is_same = ref_result == output_result + + if is_same == (tag == 'rendering'): + print(f"{vt100.GREEN}Passed{vt100.RESET}") + else: + if tag == 'error': + print(f"{vt100.RED}Failed {name!r} (The result should be different){vt100.RESET}") + print(f"{vt100.WHITE}{ref_xhtml[1:].rstrip()}{vt100.RESET}") + print(f"{vt100.BLUE}{rendering[1:].rstrip()}{vt100.RESET}") + else: + print(f"{vt100.RED}Failed {name!r}{vt100.RESET}") + print(f"{vt100.WHITE}{ref_xhtml[1:].rstrip()}{vt100.RESET}") + print(f"{vt100.BLUE}{rendering[1:].rstrip()}{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)) + + temp.unlink() diff --git a/tests/css/display-block.xml b/tests/css/display-block.xml new file mode 100644 index 0000000..aef2fff --- /dev/null +++ b/tests/css/display-block.xml @@ -0,0 +1,259 @@ + + + + + + + + + + + + + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+
+ + + + + + + + + + + + + + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+
+ + + + + + + + + + + + + + +
+
+
+
+
+ + +
+
+
+
+
+
diff --git a/tests/css/display-flex.xml b/tests/css/display-flex.xml new file mode 100644 index 0000000..b7bbf45 --- /dev/null +++ b/tests/css/display-flex.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+
+