htmlcmp 2.2.0__tar.gz → 2.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/PKG-INFO +37 -1
- htmlcmp-2.4.0/README.md +85 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/pyproject.toml +4 -1
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp/common.py +26 -5
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp/compare_output_cli.py +24 -4
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp/compare_output_server.py +311 -393
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp/html_render_diff.py +62 -11
- htmlcmp-2.4.0/src/htmlcmp/static/common.js +38 -0
- htmlcmp-2.4.0/src/htmlcmp/static/compare.js +340 -0
- htmlcmp-2.4.0/src/htmlcmp/static/index.js +152 -0
- htmlcmp-2.4.0/src/htmlcmp/static/style.css +253 -0
- htmlcmp-2.4.0/src/htmlcmp/templates/compare.html +104 -0
- htmlcmp-2.4.0/src/htmlcmp/templates/index.html +69 -0
- htmlcmp-2.4.0/src/htmlcmp/templates/missing.html +15 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp.egg-info/PKG-INFO +37 -1
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp.egg-info/SOURCES.txt +8 -0
- htmlcmp-2.4.0/tests/test_compare_html_retries.py +80 -0
- htmlcmp-2.2.0/README.md +0 -49
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/setup.cfg +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp/__init__.py +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp/tidy_output.py +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp.egg-info/dependency_links.txt +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp.egg-info/entry_points.txt +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp.egg-info/requires.txt +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/src/htmlcmp.egg-info/top_level.txt +0 -0
- {htmlcmp-2.2.0 → htmlcmp-2.4.0}/tests/test_html_render_diff.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: htmlcmp
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Compare HTML files by rendered output
|
|
5
5
|
Author: Andreas Stefl
|
|
6
6
|
Maintainer-email: Andreas Stefl <stefl.andreas@gmail.com>
|
|
@@ -29,6 +29,42 @@ Provides various entry points to run:
|
|
|
29
29
|
|
|
30
30
|
Used for regression testing in https://github.com/opendocument-app/OpenDocument.core.
|
|
31
31
|
|
|
32
|
+
## Reviewing differences in the browser
|
|
33
|
+
|
|
34
|
+
`compare-html-server` serves two pages:
|
|
35
|
+
|
|
36
|
+
- the **overview** lists every comparable file with its status (`same`,
|
|
37
|
+
`different`, `pending`), a search box, status filters with counts, and an
|
|
38
|
+
`update ref` button per file plus `Update all in view`
|
|
39
|
+
- the **compare page** (click a path) shows reference (A) and monitored (B)
|
|
40
|
+
side by side with synchronised scrolling, a diff strip in between, and the
|
|
41
|
+
controls to work through a review
|
|
42
|
+
|
|
43
|
+
On the compare page:
|
|
44
|
+
|
|
45
|
+
- **Update reference** copies the monitored file over the reference one; the
|
|
46
|
+
file is then marked `✓ accepted` for the rest of the session (the mark
|
|
47
|
+
disappears again if the monitored file changes afterwards)
|
|
48
|
+
- **← / →** step to the previous and next document; tick *diffs only* to skip
|
|
49
|
+
files that already match
|
|
50
|
+
- the **diff strip** maps the whole page into the column: red bars mark the
|
|
51
|
+
regions that differ, the blue box marks the visible part of the document, and
|
|
52
|
+
a click jumps both panes to that position
|
|
53
|
+
|
|
54
|
+
| key | action |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `←` / `k`, `→` / `j` | previous / next document |
|
|
57
|
+
| `1` / `2` / `3` | reference only / side by side / monitored only |
|
|
58
|
+
| `d` | toggle the diff strip |
|
|
59
|
+
| `u` | update the reference |
|
|
60
|
+
| `r` | reload both panes |
|
|
61
|
+
| `Esc` | back to the overview |
|
|
62
|
+
| `?` | shortcut help |
|
|
63
|
+
|
|
64
|
+
Comparison results are computed live, so the pages update themselves while the
|
|
65
|
+
monitored directory is being regenerated. Accepted marks are kept in memory
|
|
66
|
+
only and are gone after a restart.
|
|
67
|
+
|
|
32
68
|
## Install via PyPI
|
|
33
69
|
|
|
34
70
|
```bash
|
htmlcmp-2.4.0/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# htmlcmp
|
|
2
|
+
|
|
3
|
+
Tool to compare (generated) HTML files visually and automatically using Selenium.
|
|
4
|
+
|
|
5
|
+
Provides various entry points to run:
|
|
6
|
+
- `compare-html` is a CLI tool to compare two directory structures containing HTML files
|
|
7
|
+
- `compare-html-server` starts a webserver and allows to inspect differences manually
|
|
8
|
+
- `html-render-diff` renders two HTML files and produces images
|
|
9
|
+
- `html-tidy` allows to run HTML tidy on a directory
|
|
10
|
+
|
|
11
|
+
Used for regression testing in https://github.com/opendocument-app/OpenDocument.core.
|
|
12
|
+
|
|
13
|
+
## Reviewing differences in the browser
|
|
14
|
+
|
|
15
|
+
`compare-html-server` serves two pages:
|
|
16
|
+
|
|
17
|
+
- the **overview** lists every comparable file with its status (`same`,
|
|
18
|
+
`different`, `pending`), a search box, status filters with counts, and an
|
|
19
|
+
`update ref` button per file plus `Update all in view`
|
|
20
|
+
- the **compare page** (click a path) shows reference (A) and monitored (B)
|
|
21
|
+
side by side with synchronised scrolling, a diff strip in between, and the
|
|
22
|
+
controls to work through a review
|
|
23
|
+
|
|
24
|
+
On the compare page:
|
|
25
|
+
|
|
26
|
+
- **Update reference** copies the monitored file over the reference one; the
|
|
27
|
+
file is then marked `✓ accepted` for the rest of the session (the mark
|
|
28
|
+
disappears again if the monitored file changes afterwards)
|
|
29
|
+
- **← / →** step to the previous and next document; tick *diffs only* to skip
|
|
30
|
+
files that already match
|
|
31
|
+
- the **diff strip** maps the whole page into the column: red bars mark the
|
|
32
|
+
regions that differ, the blue box marks the visible part of the document, and
|
|
33
|
+
a click jumps both panes to that position
|
|
34
|
+
|
|
35
|
+
| key | action |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `←` / `k`, `→` / `j` | previous / next document |
|
|
38
|
+
| `1` / `2` / `3` | reference only / side by side / monitored only |
|
|
39
|
+
| `d` | toggle the diff strip |
|
|
40
|
+
| `u` | update the reference |
|
|
41
|
+
| `r` | reload both panes |
|
|
42
|
+
| `Esc` | back to the overview |
|
|
43
|
+
| `?` | shortcut help |
|
|
44
|
+
|
|
45
|
+
Comparison results are computed live, so the pages update themselves while the
|
|
46
|
+
monitored directory is being regenerated. Accepted marks are kept in memory
|
|
47
|
+
only and are gone after a restart.
|
|
48
|
+
|
|
49
|
+
## Install via PyPI
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install htmlcmp
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Download and run the docker image
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
docker pull ghcr.io/opendocument-app/odr_core_test
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
docker run -ti \
|
|
63
|
+
-v $(pwd):/repo \
|
|
64
|
+
-p 8000:8000 \
|
|
65
|
+
ghcr.io/opendocument-app/odr_core_test \
|
|
66
|
+
compare-html-server /repo/REFERENCE /repo/MONITORED --compare --driver firefox --port 8000
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Manually build the docker image
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
docker build --tag odr_core_test test/docker
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Run locally
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
PYTHONPATH=$(pwd)/src:$PYTHONPATH python ./src/htmlcmp/compare_output_server.py \
|
|
79
|
+
/path/to/REFERENCE \
|
|
80
|
+
/path/to/MONITORED \
|
|
81
|
+
--compare \
|
|
82
|
+
--driver firefox \
|
|
83
|
+
--port 8000 \
|
|
84
|
+
-vv
|
|
85
|
+
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "htmlcmp"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.4.0"
|
|
4
4
|
description = "Compare HTML files by rendered output"
|
|
5
5
|
classifiers = []
|
|
6
6
|
authors = [
|
|
@@ -33,6 +33,9 @@ download = "https://pypi.org/project/pyodr/#files"
|
|
|
33
33
|
tracker = "https://github.com/opendocument-app/compare-html/issues"
|
|
34
34
|
"release notes" = "https://github.com/opendocument-app/compare-html/releases"
|
|
35
35
|
|
|
36
|
+
[tool.setuptools.package-data]
|
|
37
|
+
htmlcmp = ["templates/*.html", "static/*.css", "static/*.js"]
|
|
38
|
+
|
|
36
39
|
[tool.pytest.ini_options]
|
|
37
40
|
pythonpath = ["src"]
|
|
38
41
|
|
|
@@ -6,6 +6,8 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
from htmlcmp.html_render_diff import get_browser, html_render_diff
|
|
8
8
|
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
9
11
|
|
|
10
12
|
class bcolors:
|
|
11
13
|
HEADER = "\033[95m"
|
|
@@ -40,22 +42,41 @@ def compare_json(a: Path, b: Path) -> bool:
|
|
|
40
42
|
return json_a == json_b
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
def compare_html(
|
|
45
|
+
def compare_html(
|
|
46
|
+
a: Path, b: Path, browser=None, diff_output: Path = None, retries: int = 1
|
|
47
|
+
) -> bool:
|
|
48
|
+
"""Whether `a` and `b` render to the same pixels.
|
|
49
|
+
|
|
50
|
+
A mismatch is rendered again before it is reported, `retries` times. A real
|
|
51
|
+
difference is in the markup and comes back every time; one that does not is
|
|
52
|
+
the page having been caught mid-render, and a browser gives no promise that
|
|
53
|
+
two runs of the same page paint alike at the same instant. The retry costs
|
|
54
|
+
nothing on the matching files, which are almost all of them.
|
|
55
|
+
"""
|
|
44
56
|
if not isinstance(a, Path) or not isinstance(b, Path):
|
|
45
57
|
raise TypeError("Both arguments must be of type Path")
|
|
46
58
|
if not a.is_file() or not b.is_file():
|
|
47
59
|
raise FileNotFoundError("Both arguments must be files")
|
|
60
|
+
if not isinstance(retries, int) or retries < 0:
|
|
61
|
+
raise ValueError(f"retries must be a non-negative int, got {retries!r}")
|
|
48
62
|
|
|
49
63
|
if browser is None:
|
|
50
64
|
browser = get_browser("firefox")
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
|
|
66
|
+
for attempt in range(retries + 1):
|
|
67
|
+
diff, (image_a, image_b) = html_render_diff(a, b, browser=browser)
|
|
68
|
+
if diff.getbbox() is None:
|
|
69
|
+
return True
|
|
70
|
+
logger.debug(
|
|
71
|
+
"%s and %s differ on attempt %d of %d", a, b, attempt + 1, retries + 1
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if diff_output is not None:
|
|
54
75
|
diff_output.mkdir(parents=True, exist_ok=True)
|
|
55
76
|
image_a.save(diff_output / "a.png")
|
|
56
77
|
image_b.save(diff_output / "b.png")
|
|
57
78
|
diff.save(diff_output / "diff.png")
|
|
58
|
-
return
|
|
79
|
+
return False
|
|
59
80
|
|
|
60
81
|
|
|
61
82
|
def compare_files(a: Path, b: Path, **kwargs) -> bool:
|
|
@@ -34,11 +34,14 @@ class Config:
|
|
|
34
34
|
class Task:
|
|
35
35
|
"""A single file comparison between the reference (A) and monitored (B) tree."""
|
|
36
36
|
|
|
37
|
-
def __init__(
|
|
37
|
+
def __init__(
|
|
38
|
+
self, rel: Path, a: Path, b: Path, diff_output: Path = None, retries: int = 1
|
|
39
|
+
):
|
|
38
40
|
self.rel = rel
|
|
39
41
|
self.a = a
|
|
40
42
|
self.b = b
|
|
41
43
|
self.diff_output = diff_output
|
|
44
|
+
self.retries = retries
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
class Failure:
|
|
@@ -54,7 +57,7 @@ class Failure:
|
|
|
54
57
|
|
|
55
58
|
|
|
56
59
|
def collect_tasks(
|
|
57
|
-
a: Path, b: Path, root: Path = None, diff_output: Path = None
|
|
60
|
+
a: Path, b: Path, root: Path = None, diff_output: Path = None, retries: int = 1
|
|
58
61
|
) -> tuple[list[Task], list[Failure]]:
|
|
59
62
|
"""Walk both trees once and return (comparable tasks, structural failures).
|
|
60
63
|
|
|
@@ -91,6 +94,7 @@ def collect_tasks(
|
|
|
91
94
|
a / name,
|
|
92
95
|
b / name,
|
|
93
96
|
None if diff_output is None else diff_output / name,
|
|
97
|
+
retries=retries,
|
|
94
98
|
)
|
|
95
99
|
)
|
|
96
100
|
elif name in left_files:
|
|
@@ -107,6 +111,7 @@ def collect_tasks(
|
|
|
107
111
|
b / name,
|
|
108
112
|
root=root,
|
|
109
113
|
diff_output=None if diff_output is None else diff_output / name,
|
|
114
|
+
retries=retries,
|
|
110
115
|
)
|
|
111
116
|
tasks.extend(sub_tasks)
|
|
112
117
|
failures.extend(sub_failures)
|
|
@@ -126,7 +131,13 @@ def collect_tasks(
|
|
|
126
131
|
def run_task(task: Task) -> bool:
|
|
127
132
|
logger.debug("Comparing %s", task.rel)
|
|
128
133
|
browser = getattr(Config.thread_local, "browser", None)
|
|
129
|
-
return compare_files(
|
|
134
|
+
return compare_files(
|
|
135
|
+
task.a,
|
|
136
|
+
task.b,
|
|
137
|
+
browser=browser,
|
|
138
|
+
diff_output=task.diff_output,
|
|
139
|
+
retries=task.retries,
|
|
140
|
+
)
|
|
130
141
|
|
|
131
142
|
|
|
132
143
|
def make_executor(max_workers: int, driver: str | None) -> ThreadPoolExecutor:
|
|
@@ -248,6 +259,7 @@ def run(
|
|
|
248
259
|
driver: str | None,
|
|
249
260
|
max_workers: int,
|
|
250
261
|
diff_output: Path | None,
|
|
262
|
+
retries: int,
|
|
251
263
|
console: Console,
|
|
252
264
|
live: bool,
|
|
253
265
|
github: bool,
|
|
@@ -256,7 +268,7 @@ def run(
|
|
|
256
268
|
f"[bold]Comparing[/bold] {escape(str(a))} [dim]→[/dim] {escape(str(b))}"
|
|
257
269
|
)
|
|
258
270
|
|
|
259
|
-
tasks, failures = collect_tasks(a, b, diff_output=diff_output)
|
|
271
|
+
tasks, failures = collect_tasks(a, b, diff_output=diff_output, retries=retries)
|
|
260
272
|
logger.info(
|
|
261
273
|
"Collected %d comparable file(s), %d structural difference(s)",
|
|
262
274
|
len(tasks),
|
|
@@ -326,6 +338,13 @@ def main():
|
|
|
326
338
|
default=0,
|
|
327
339
|
help="Increase verbosity (-v, -vv, -vvv)",
|
|
328
340
|
)
|
|
341
|
+
parser.add_argument(
|
|
342
|
+
"--retries",
|
|
343
|
+
type=int,
|
|
344
|
+
default=1,
|
|
345
|
+
help="Re-render a mismatch this many times before reporting it "
|
|
346
|
+
"(default: 1; 0 reports the first render)",
|
|
347
|
+
)
|
|
329
348
|
parser.add_argument("--log-file", type=Path, help="Path to log file")
|
|
330
349
|
parser.add_argument(
|
|
331
350
|
"--log-file-verbosity", type=int, help="Log file verbosity level"
|
|
@@ -351,6 +370,7 @@ def main():
|
|
|
351
370
|
driver=driver,
|
|
352
371
|
max_workers=args.max_workers,
|
|
353
372
|
diff_output=args.diff_output,
|
|
373
|
+
retries=args.retries,
|
|
354
374
|
console=console,
|
|
355
375
|
live=live,
|
|
356
376
|
github=github,
|