Skip to content

Commit bf0711a

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 bf0711a

1 file changed

Lines changed: 61 additions & 4 deletions

File tree

tasks.py

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,78 @@ 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(context, input_file: str, root_path: str, long: bool) -> None:
205204
arg_long = "--long" if long else ""
206205

207206
run_invoke(
208207
context,
209208
f"""
210209
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/
210+
{input_file}
211+
{root_path}
213212
{arg_long}
214213
""",
215214
)
216215

217216

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

0 commit comments

Comments
 (0)