venom-report 0.1.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.
Files changed (27) hide show
  1. venom_report-0.1.0/.gitignore +8 -0
  2. venom_report-0.1.0/LICENSE +202 -0
  3. venom_report-0.1.0/PKG-INFO +88 -0
  4. venom_report-0.1.0/README.md +67 -0
  5. venom_report-0.1.0/pyproject.toml +47 -0
  6. venom_report-0.1.0/src/venom_report/__init__.py +8 -0
  7. venom_report-0.1.0/src/venom_report/__main__.py +5 -0
  8. venom_report-0.1.0/src/venom_report/cli.py +245 -0
  9. venom_report-0.1.0/src/venom_report/readers.py +382 -0
  10. venom_report-0.1.0/src/venom_report/template.html +322 -0
  11. venom_report-0.1.0/tests/fixtures/json/suite_a.TC1-exec-ok.testcase.1.step.1.0.dump.json +34 -0
  12. venom_report-0.1.0/tests/fixtures/json/suite_a.TC2-exec-fails.testcase.2.step.1.0.dump.json +34 -0
  13. venom_report-0.1.0/tests/fixtures/json/suite_a.TC2-exec-fails.testcase.2.step.2.0.dump.json +35 -0
  14. venom_report-0.1.0/tests/fixtures/json/suite_a.TC3-http.testcase.3.step.1.0.dump.json +61 -0
  15. venom_report-0.1.0/tests/fixtures/json/suite_a.TC5-loop.testcase.5.step.1.0.dump.json +41 -0
  16. venom_report-0.1.0/tests/fixtures/json/suite_a.TC5-loop.testcase.5.step.1.1.dump.json +41 -0
  17. venom_report-0.1.0/tests/fixtures/json/test_results_suite_a.json +666 -0
  18. venom_report-0.1.0/tests/fixtures/nodump/test_results_suite_a.xml +54 -0
  19. venom_report-0.1.0/tests/fixtures/suite_a.yml +45 -0
  20. venom_report-0.1.0/tests/fixtures/xml/suite_a.TC1-exec-ok.testcase.1.step.1.0.dump.json +34 -0
  21. venom_report-0.1.0/tests/fixtures/xml/suite_a.TC2-exec-fails.testcase.2.step.1.0.dump.json +34 -0
  22. venom_report-0.1.0/tests/fixtures/xml/suite_a.TC2-exec-fails.testcase.2.step.2.0.dump.json +35 -0
  23. venom_report-0.1.0/tests/fixtures/xml/suite_a.TC3-http.testcase.3.step.1.0.dump.json +61 -0
  24. venom_report-0.1.0/tests/fixtures/xml/suite_a.TC5-loop.testcase.5.step.1.0.dump.json +41 -0
  25. venom_report-0.1.0/tests/fixtures/xml/suite_a.TC5-loop.testcase.5.step.1.1.dump.json +41 -0
  26. venom_report-0.1.0/tests/fixtures/xml/test_results_suite_a.xml +57 -0
  27. venom_report-0.1.0/tests/test_venom_report.py +175 -0
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ .pytest_cache/
3
+ .ruff_cache/
4
+ .venv/
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+ uv.lock
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.5
2
+ Name: venom-report
3
+ Version: 0.1.0
4
+ Summary: A static HTML report for any venom run, like coverage html.
5
+ Project-URL: Homepage, https://github.com/pfrayer/venom-report
6
+ Project-URL: Issues, https://github.com/pfrayer/venom-report/issues
7
+ Author: Pierre Frayer
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: html,junit,report,testing,venom
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Software Development :: Testing
17
+ Requires-Python: >=3.10
18
+ Provides-Extra: yaml
19
+ Requires-Dist: pyyaml; extra == 'yaml'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # venom-report
23
+
24
+ A static HTML report for any [venom](https://github.com/ovh/venom) run, like `coverage html`:
25
+ every suite, testcase and step, the HTTP call made (method, URL, headers, body), the
26
+ response, the assertions (the failing one in red), and why a testcase was skipped.
27
+
28
+ ```sh
29
+ pipx install venom-report # or: uv tool install venom-report
30
+ venom-report path/to/output # -> path/to/output/report/index.html
31
+ venom-report output --open # and open it
32
+ ```
33
+
34
+ No dependency (Python ≥ 3.10); `pip install 'venom-report[yaml]'` adds PyYAML for `--expected-reds`. The page is one self-contained file that opens over `file://`.
35
+
36
+ ## What it reads
37
+
38
+ | venom writes | when | gives |
39
+ |---|---|---|
40
+ | `test_results_*.xml` | `format: xml` (default) | suites, testcases, pass/fail/skip, failure messages |
41
+ | `test_results_*.json` | `format: json` | same, plus every step with its request/response, no dump needed |
42
+ | `*.dump.json` | `-vvv` / `verbosity: 3` | each step: the request sent and the full response |
43
+
44
+ Without dumps (xml, no `-vvv`), the report falls back on the JUnit `system-out` and says so.
45
+
46
+ venom never cleans `output/`: dumps from older runs sit next to fresh ones. A dump is
47
+ used only if it was written during the run that produced the report (from its mtime).
48
+ If the same suite was reported twice (e.g. `venom run tests/` then `venom run tests/x.yml`),
49
+ the newest report wins.
50
+
51
+ ## Options
52
+
53
+ | option | default | |
54
+ |---|---|---|
55
+ | `-o FILE` | `OUTPUT_DIR/report/index.html` | where to write |
56
+ | `--title T` | `venom · <parent dir>` | page title |
57
+ | `--expected-reds FILE` | none | YAML list of reds that are known and accepted, shown apart from regressions (needs PyYAML) |
58
+ | `--redact REGEX` | `authorization\|token\|secret\|passw(or)?d\|cookie\|api[-_]?key\|credential` | keys and headers whose values are masked |
59
+ | `--max-body N` | `100000` | bodies longer than N chars are truncated |
60
+ | `--open` | | open the report in a browser |
61
+
62
+ `--expected-reds` accepts a list, or a mapping with an `expected_reds:` list, of entries
63
+ `{testcase, suite?, divergence?, why?}` or bare testcase names. Names match loosely
64
+ (`TC8 foo bar` = `TC8-foo-bar`).
65
+
66
+ ## Secrets
67
+
68
+ Values under a sensitive key (in dumps, headers, venom vars, venom `secrets`) are masked,
69
+ then every other occurrence of those values is masked too (URLs, bodies, logs), as is
70
+ any `Bearer …` / `Basic …`. The venom variables block is never embedded. Still, check a
71
+ report before sharing it outside your team.
72
+
73
+ ## Tests
74
+
75
+ ```sh
76
+ uv run pytest
77
+ ```
78
+
79
+ The fixtures are real venom v1.3.0 outputs of `tests/fixtures/suite_a.yml`.
80
+
81
+ ## Release
82
+
83
+ Publish a GitHub release with a `vX.Y.Z` tag: the version comes from the tag, and the
84
+ `Release` workflow uploads to PyPI (trusted publishing, no token).
85
+
86
+ ## License
87
+
88
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,67 @@
1
+ # venom-report
2
+
3
+ A static HTML report for any [venom](https://github.com/ovh/venom) run, like `coverage html`:
4
+ every suite, testcase and step, the HTTP call made (method, URL, headers, body), the
5
+ response, the assertions (the failing one in red), and why a testcase was skipped.
6
+
7
+ ```sh
8
+ pipx install venom-report # or: uv tool install venom-report
9
+ venom-report path/to/output # -> path/to/output/report/index.html
10
+ venom-report output --open # and open it
11
+ ```
12
+
13
+ No dependency (Python ≥ 3.10); `pip install 'venom-report[yaml]'` adds PyYAML for `--expected-reds`. The page is one self-contained file that opens over `file://`.
14
+
15
+ ## What it reads
16
+
17
+ | venom writes | when | gives |
18
+ |---|---|---|
19
+ | `test_results_*.xml` | `format: xml` (default) | suites, testcases, pass/fail/skip, failure messages |
20
+ | `test_results_*.json` | `format: json` | same, plus every step with its request/response, no dump needed |
21
+ | `*.dump.json` | `-vvv` / `verbosity: 3` | each step: the request sent and the full response |
22
+
23
+ Without dumps (xml, no `-vvv`), the report falls back on the JUnit `system-out` and says so.
24
+
25
+ venom never cleans `output/`: dumps from older runs sit next to fresh ones. A dump is
26
+ used only if it was written during the run that produced the report (from its mtime).
27
+ If the same suite was reported twice (e.g. `venom run tests/` then `venom run tests/x.yml`),
28
+ the newest report wins.
29
+
30
+ ## Options
31
+
32
+ | option | default | |
33
+ |---|---|---|
34
+ | `-o FILE` | `OUTPUT_DIR/report/index.html` | where to write |
35
+ | `--title T` | `venom · <parent dir>` | page title |
36
+ | `--expected-reds FILE` | none | YAML list of reds that are known and accepted, shown apart from regressions (needs PyYAML) |
37
+ | `--redact REGEX` | `authorization\|token\|secret\|passw(or)?d\|cookie\|api[-_]?key\|credential` | keys and headers whose values are masked |
38
+ | `--max-body N` | `100000` | bodies longer than N chars are truncated |
39
+ | `--open` | | open the report in a browser |
40
+
41
+ `--expected-reds` accepts a list, or a mapping with an `expected_reds:` list, of entries
42
+ `{testcase, suite?, divergence?, why?}` or bare testcase names. Names match loosely
43
+ (`TC8 foo bar` = `TC8-foo-bar`).
44
+
45
+ ## Secrets
46
+
47
+ Values under a sensitive key (in dumps, headers, venom vars, venom `secrets`) are masked,
48
+ then every other occurrence of those values is masked too (URLs, bodies, logs), as is
49
+ any `Bearer …` / `Basic …`. The venom variables block is never embedded. Still, check a
50
+ report before sharing it outside your team.
51
+
52
+ ## Tests
53
+
54
+ ```sh
55
+ uv run pytest
56
+ ```
57
+
58
+ The fixtures are real venom v1.3.0 outputs of `tests/fixtures/suite_a.yml`.
59
+
60
+ ## Release
61
+
62
+ Publish a GitHub release with a `vX.Y.Z` tag: the version comes from the tag, and the
63
+ `Release` workflow uploads to PyPI (trusted publishing, no token).
64
+
65
+ ## License
66
+
67
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "venom-report"
7
+ dynamic = ["version"]
8
+ description = "A static HTML report for any venom run, like coverage html."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.10"
13
+ authors = [{ name = "Pierre Frayer" }]
14
+ keywords = ["venom", "testing", "report", "html", "junit"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Topic :: Software Development :: Testing",
22
+ ]
23
+
24
+ [project.optional-dependencies]
25
+ yaml = ["pyyaml"]
26
+
27
+ [project.scripts]
28
+ venom-report = "venom_report.cli:main"
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/pfrayer/venom-report"
32
+ Issues = "https://github.com/pfrayer/venom-report/issues"
33
+
34
+ [dependency-groups]
35
+ dev = ["pytest", "pyyaml", "ruff"]
36
+
37
+ [tool.hatch.version]
38
+ source = "vcs"
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ include = ["src", "tests", "README.md", "LICENSE"]
42
+
43
+ [tool.ruff]
44
+ line-length = 120
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
@@ -0,0 +1,8 @@
1
+ """Turn a venom output directory into a single static HTML report."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ try:
6
+ __version__ = version("venom-report")
7
+ except PackageNotFoundError: # running from a source tree that was never installed
8
+ __version__ = "0.0.0"
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,245 @@
1
+ """Turn a venom output directory into a single static HTML report.
2
+
3
+ venom-report [OUTPUT_DIR] [-o index.html] [--expected-reds FILE]
4
+
5
+ Reads what venom writes, whatever the suite:
6
+ - test_results_*.xml (format: xml) or test_results_*.json (format: json)
7
+ - *.dump.json, one per executed step, when venom ran with -vvv / verbosity: 3
8
+
9
+ Stdlib only. The report never reflects the test status in its exit code: venom
10
+ already does that.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import argparse
16
+ import json
17
+ import re
18
+ import sys
19
+ import webbrowser
20
+ import xml.etree.ElementTree as ET
21
+ from datetime import datetime, timezone
22
+ from importlib.resources import files
23
+ from pathlib import Path
24
+ from typing import Any
25
+
26
+ from . import __version__
27
+ from .readers import (
28
+ Redactor,
29
+ Suite,
30
+ Testcase,
31
+ attach_dumps,
32
+ index_dumps,
33
+ read_json,
34
+ read_xml,
35
+ resolve_statuses,
36
+ run_windows,
37
+ )
38
+
39
+ DEFAULT_REDACT = r"authorization|token|secret|passw(or)?d|cookie|api[-_]?key|credential"
40
+
41
+
42
+ # --------------------------------------------------------------------------- expected reds
43
+
44
+
45
+ def load_expected(path: Path | None) -> list[dict[str, Any]]:
46
+ if not path:
47
+ return []
48
+ try:
49
+ import yaml # type: ignore[import-untyped]
50
+ except ImportError:
51
+ print("warning: PyYAML missing, --expected-reds ignored", file=sys.stderr)
52
+ return []
53
+ doc = yaml.safe_load(path.read_text()) or {}
54
+ entries = doc.get("expected_reds", []) if isinstance(doc, dict) else doc
55
+ return [e if isinstance(e, dict) else {"testcase": str(e)} for e in entries or []]
56
+
57
+
58
+ def _norm(s: str) -> str:
59
+ return re.sub(r"[^a-z0-9]+", "-", s.lower()).strip("-")
60
+
61
+
62
+ def match_expected(suite: Suite, tc: Testcase, entries: list[dict[str, Any]]) -> dict[str, Any] | None:
63
+ for e in entries:
64
+ if e.get("suite") and Path(str(e["suite"])).name not in (
65
+ Path(suite.file).name,
66
+ suite.stem,
67
+ ):
68
+ continue
69
+ if _norm(str(e.get("testcase") or e.get("class") or "")) == _norm(tc.name):
70
+ return {k: e[k] for k in ("divergence", "why") if k in e}
71
+ return None
72
+
73
+
74
+ # --------------------------------------------------------------------------- output
75
+
76
+
77
+ def _truncate(s: Any, limit: int) -> Any:
78
+ if isinstance(s, str) and len(s) > limit:
79
+ return s[:limit] + f"\n\n… truncated by venom-report ({len(s)} bytes, --max-body {limit})"
80
+ return s
81
+
82
+
83
+ def serialize(suites: list[Suite], redactor: Redactor, max_body: int) -> list[dict[str, Any]]:
84
+ out = []
85
+ for s in suites:
86
+ tcs = []
87
+ for tc in s.testcases:
88
+ steps = []
89
+ for st in tc.steps:
90
+ http = None
91
+ if st.http:
92
+ http = redactor.obj(st.http)
93
+ http["reqBody"] = _truncate(http["reqBody"], max_body)
94
+ http["respBody"] = _truncate(http["respBody"], max_body)
95
+ raw = redactor.obj(st.raw)
96
+ raw_s = raw if isinstance(raw, str) else json.dumps(raw, indent=2, ensure_ascii=False, default=str)
97
+ steps.append(
98
+ {
99
+ "n": st.n,
100
+ "r": st.r,
101
+ "type": st.type,
102
+ "name": st.name,
103
+ "status": st.status,
104
+ "errors": [redactor.text(e) for e in st.errors],
105
+ "assertions": redactor.obj(st.assertions),
106
+ "http": http,
107
+ "hasDump": st.has_dump,
108
+ "systemout": _truncate(redactor.text(st.systemout.strip()), max_body),
109
+ "systemerr": _truncate(redactor.text(st.systemerr.strip()), max_body),
110
+ "raw": _truncate(raw_s, max_body) if st.raw else "",
111
+ }
112
+ )
113
+ tcs.append(
114
+ {
115
+ "name": tc.name,
116
+ "index": tc.index,
117
+ "status": tc.status,
118
+ "time": tc.time,
119
+ "messages": [redactor.text(m) for m in tc.messages],
120
+ "skipReason": redactor.text(tc.skip_reason),
121
+ "systemout": _truncate(redactor.text(tc.systemout), max_body),
122
+ "steps": steps,
123
+ "expected": tc.expected,
124
+ }
125
+ )
126
+ out.append(
127
+ {
128
+ "name": s.name,
129
+ "file": s.file,
130
+ "source": s.source,
131
+ "time": s.time,
132
+ "end": s.end,
133
+ "testcases": tcs,
134
+ }
135
+ )
136
+ return out
137
+
138
+
139
+ def build(
140
+ out_dir: Path,
141
+ expected_path: Path | None,
142
+ redact: str,
143
+ max_body: int,
144
+ title: str | None,
145
+ ) -> tuple[str, dict]:
146
+ redactor = Redactor(redact)
147
+ suites: dict[str, Suite] = {}
148
+ for p in sorted(out_dir.glob("test_results*.xml")) + sorted(out_dir.glob("test_results*.json")):
149
+ try:
150
+ found = read_xml(p) if p.suffix == ".xml" else read_json(p, redactor)
151
+ except (ET.ParseError, ValueError, OSError) as exc:
152
+ print(f"warning: {p.name} skipped ({exc})", file=sys.stderr)
153
+ continue
154
+ for s in found: # the same suite run twice (dir vs file spelling): keep the newest
155
+ key = s.file or s.name
156
+ if key not in suites or s.end > suites[key].end:
157
+ suites[key] = s
158
+ idx = index_dumps(out_dir)
159
+ entries = load_expected(expected_path)
160
+ dumps = 0
161
+ run_windows(list(suites.values()))
162
+ for s in suites.values():
163
+ dumps += attach_dumps(s, idx, redactor)
164
+ for tc in s.testcases:
165
+ resolve_statuses(tc)
166
+ if tc.status == "fail":
167
+ tc.expected = match_expected(s, tc, entries)
168
+ ordered = sorted(suites.values(), key=lambda s: s.file or s.name)
169
+ meta = {
170
+ "title": title or f"venom · {out_dir.resolve().parent.name}",
171
+ "outputDir": str(out_dir.resolve()),
172
+ "generated": datetime.now(timezone.utc).isoformat(timespec="seconds"),
173
+ "dumps": dumps,
174
+ "expectedReds": bool(entries),
175
+ }
176
+ data = {"meta": meta, "suites": serialize(ordered, redactor, max_body)}
177
+ payload = json.dumps(data, ensure_ascii=False, separators=(",", ":")).replace("<", "\\u003c")
178
+ template = (
179
+ files(__package__).joinpath("template.html").read_text().replace("__TITLE__", _html_escape(meta["title"]))
180
+ )
181
+ html = template.replace("/*__DATA__*/", payload)
182
+ return html, data
183
+
184
+
185
+ def _html_escape(s: str) -> str:
186
+ return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
187
+
188
+
189
+ def main(argv: list[str] | None = None) -> int:
190
+ ap = argparse.ArgumentParser(
191
+ prog="venom-report", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
192
+ )
193
+ ap.add_argument(
194
+ "output_dir",
195
+ nargs="?",
196
+ default="output",
197
+ type=Path,
198
+ help="venom output dir (default: ./output)",
199
+ )
200
+ ap.add_argument(
201
+ "-o",
202
+ "--out",
203
+ type=Path,
204
+ help="report file (default: OUTPUT_DIR/report/index.html)",
205
+ )
206
+ ap.add_argument("--title", help="page title")
207
+ ap.add_argument(
208
+ "--expected-reds",
209
+ type=Path,
210
+ help="YAML list of reds known to be expected (needs PyYAML)",
211
+ )
212
+ ap.add_argument(
213
+ "--redact",
214
+ default=DEFAULT_REDACT,
215
+ help=f"regex of sensitive keys (default: {DEFAULT_REDACT})",
216
+ )
217
+ ap.add_argument(
218
+ "--max-body",
219
+ type=int,
220
+ default=100_000,
221
+ help="truncate bodies above N chars (default: 100000)",
222
+ )
223
+ ap.add_argument("--open", action="store_true", help="open the report in a browser")
224
+ ap.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
225
+ args = ap.parse_args(argv)
226
+ if not args.output_dir.is_dir():
227
+ print(f"error: {args.output_dir} is not a directory", file=sys.stderr)
228
+ return 2
229
+ html, data = build(args.output_dir, args.expected_reds, args.redact, args.max_body, args.title)
230
+ if not data["suites"]:
231
+ print(f"error: no test_results_*.xml|json in {args.output_dir}", file=sys.stderr)
232
+ return 2
233
+ out = args.out or args.output_dir / "report" / "index.html"
234
+ out.parent.mkdir(parents=True, exist_ok=True)
235
+ out.write_text(html)
236
+ tcs = [tc for s in data["suites"] for tc in s["testcases"]]
237
+ count = {k: sum(tc["status"] == k for tc in tcs) for k in ("pass", "fail", "skip")}
238
+ print(
239
+ f"{len(data['suites'])} suites · {len(tcs)} testcases · {count['pass']} passed · "
240
+ f"{count['fail']} failed · {count['skip']} skipped · {data['meta']['dumps']} step dumps"
241
+ )
242
+ print(f"report: {out.resolve()}")
243
+ if args.open:
244
+ webbrowser.open(out.resolve().as_uri())
245
+ return 0