-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.py
More file actions
81 lines (63 loc) · 2.49 KB
/
Copy pathverify.py
File metadata and controls
81 lines (63 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Smoke test for 10-twig-cms. See SUITE.md "10 -- twig-cms" for the
required markers this checks.
"""
import glob
import os
import re
import subprocess
import sys
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
import bootstrap # noqa: E402
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
dist = bootstrap.inky_example("10-twig-cms")
failures = 0
proc = subprocess.run(
[sys.executable, os.path.join(THIS_DIR, "run.py")],
capture_output=True,
text=True,
)
output = proc.stdout + proc.stderr
if proc.returncode != 0:
print(f"10-twig-cms: run.py exited {proc.returncode}\n{output}", file=sys.stderr)
failures += 1
# All six outputs exist.
for order in ("a", "b"):
for n in range(1, 4):
path = os.path.join(dist, f"order-{order}-{n}.html")
if not os.path.isfile(path):
print(f"10-twig-cms: missing {path}", file=sys.stderr)
failures += 1
def read(path: str) -> str:
try:
with open(path, encoding="utf-8") as f:
return f.read()
except FileNotFoundError:
return ""
# Recipient 1: the correctness claim. Compared with insignificant inter-tag
# whitespace normalized (">\s+<" -> "><") -- the same whitespace inky-core's
# own break_long_lines comment calls out as not affecting rendering. See
# run.py's own comment above this same check for the full explanation of
# why a raw byte comparison doesn't hold and what the normalization does
# (and does not) paper over.
a1 = read(os.path.join(dist, "order-a-1.html"))
b1 = read(os.path.join(dist, "order-b-1.html"))
def normalize(html: str) -> str:
return re.sub(r">\s+<", "><", html)
if a1 == "" or b1 == "" or normalize(a1) != normalize(b1):
print("10-twig-cms: order-a-1.html and order-b-1.html are not equal (ignoring inter-tag whitespace)", file=sys.stderr)
failures += 1
# Timing lines printed.
if not re.search(r"orderA:\s*[\d.]+\s*ms,\s*orderB:\s*[\d.]+\s*ms \(shell built once\)", output):
print(f"10-twig-cms: expected an 'orderA: X ms, orderB: Y ms (shell built once)' line, got:\n{output}", file=sys.stderr)
failures += 1
# No un-rendered Jinja2 syntax in any final output.
for path in glob.glob(os.path.join(dist, "order-*.html")):
with open(path, encoding="utf-8") as f:
html = f.read()
if "{{" in html:
print(f"10-twig-cms: found un-rendered '{{{{' in {os.path.basename(path)}", file=sys.stderr)
failures += 1
if failures > 0:
sys.exit(1)
print("10-twig-cms: ok")