Skip to content

Commit aec8aec

Browse files
committed
feat(tasks): parameterize fuzz helpers
- add _invoke_fuzzer() helper so all fuzz tasks share the same runner logic and --long handling. - make test_fuzz take --input-file/--root-path parameters (defaults to _your_fixture_slug_ template) while keeping the tf alias. - introduce sdoc_test_fuzz (sdoc_tf) that resolves StrictDoc fixtures by slug, selecting the HTML file automatically or via --html. - emit clear errors when the StrictDoc docs folder is missing, has no base HTML, or contains multiple candidates without --html.
1 parent e623599 commit aec8aec

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

tasks.py

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,80 @@ def test_integration(
200200
run_invoke(context, itest_command)
201201

202202

203-
@task(aliases=["tf"])
204-
def test_fuzz(context, long: bool = False):
203+
def _invoke_fuzzer(
204+
context, input_file: str, root_path: str, long: bool
205+
) -> None:
205206
arg_long = "--long" if long else ""
206207

207208
run_invoke(
208209
context,
209210
f"""
210211
python html2pdf4doc/html2pdf4doc_fuzzer.py
211-
tests/fuzz/01_strictdoc_guide_202510/strictdoc/docs/strictdoc_01_user_guide-PDF.html
212-
tests/fuzz/01_strictdoc_guide_202510/
212+
{input_file}
213+
{root_path}
213214
{arg_long}
214215
""",
215216
)
216217

217218

219+
def _resolve_strictdoc_fixture(
220+
fixture: str, html: Optional[str]
221+
) -> tuple[str, str]:
222+
root_path = os.path.join("tests", "fuzz", fixture)
223+
docs_dir = Path(root_path, "strictdoc", "docs")
224+
225+
if not docs_dir.is_dir():
226+
raise RuntimeError(
227+
f"StrictDoc docs directory does not exist: {docs_dir}"
228+
)
229+
230+
if html is None:
231+
html_candidates = sorted(
232+
p
233+
for p in docs_dir.glob("*.html")
234+
if ".mut." not in p.name and not p.name.endswith(".mut.html")
235+
)
236+
if not html_candidates:
237+
raise RuntimeError(
238+
f"No HTML fixture found under {docs_dir}. "
239+
"Add an HTML file or pass --html explicitly."
240+
)
241+
if len(html_candidates) > 1:
242+
raise RuntimeError(
243+
f"Multiple HTML fixtures found under {docs_dir}: "
244+
f"{', '.join(p.name for p in html_candidates)}. "
245+
"Specify --html=<file> to choose one."
246+
)
247+
html_path = html_candidates[0]
248+
else:
249+
html_path = docs_dir / html
250+
if not html_path.is_file():
251+
raise RuntimeError(f"HTML file does not exist: {html_path}")
252+
253+
return (str(html_path), f"{root_path}/")
254+
255+
256+
@task(aliases=["tf"])
257+
def test_fuzz(
258+
context,
259+
input_file: str = "tests/fuzz/_your_fixture_slug_/file_to_mutate.html",
260+
root_path: str = "tests/fuzz/_your_fixture_slug_/",
261+
long: bool = False,
262+
):
263+
_invoke_fuzzer(context, input_file, root_path, long)
264+
265+
266+
@task(name="sdoc_test_fuzz", aliases=["sdoc_tf"])
267+
def sdoc_test_fuzz(
268+
context,
269+
fixture: str = "_your_strictdoc_fixture_slug_",
270+
html: Optional[str] = None,
271+
long: bool = False,
272+
):
273+
input_file, root_path = _resolve_strictdoc_fixture(fixture, html)
274+
_invoke_fuzzer(context, input_file, root_path, long)
275+
276+
218277
@task(aliases=["t"])
219278
def test(context):
220279
test_integration(context)

0 commit comments

Comments
 (0)