|
27 | 27 | TEST_URL = "https://example.com" |
28 | 28 |
|
29 | 29 |
|
| 30 | +def create_example_html(tmpdir: Path) -> Path: |
| 31 | + """Create a local singlefile HTML fixture used as parser input.""" |
| 32 | + singlefile_dir = tmpdir / "singlefile" |
| 33 | + singlefile_dir.mkdir(parents=True, exist_ok=True) |
| 34 | + html_file = singlefile_dir / "singlefile.html" |
| 35 | + html_file.write_text( |
| 36 | + "<html><head><title>Example Domain</title></head><body><article><h1>Example Domain</h1><p>Example text body</p></article></body></html>", |
| 37 | + encoding="utf-8", |
| 38 | + ) |
| 39 | + return html_file |
| 40 | + |
| 41 | + |
30 | 42 | def test_hook_script_exists(): |
31 | 43 | assert DEFUDDLE_HOOK.exists(), f"Hook script not found: {DEFUDDLE_HOOK}" |
32 | 44 |
|
@@ -57,6 +69,7 @@ def test_reports_missing_dependency_when_not_installed(): |
57 | 69 | tmpdir = Path(tmpdir) |
58 | 70 | snap_dir = tmpdir / "snap" |
59 | 71 | snap_dir.mkdir(parents=True, exist_ok=True) |
| 72 | + create_example_html(snap_dir) |
60 | 73 |
|
61 | 74 | env = {"PATH": "/nonexistent", "HOME": str(tmpdir), "SNAP_DIR": str(snap_dir)} |
62 | 75 | result = subprocess.run( |
@@ -87,10 +100,20 @@ def test_extracts_article_with_json_output_from_binary(): |
87 | 100 | tmpdir = Path(tmpdir) |
88 | 101 | snap_dir = tmpdir / "snap" |
89 | 102 | snap_dir.mkdir(parents=True, exist_ok=True) |
| 103 | + expected_html = create_example_html(snap_dir) |
90 | 104 |
|
91 | 105 | fake_binary = tmpdir / "fake_defuddle.py" |
92 | 106 | fake_binary.write_text( |
93 | | - "import json,sys; print(json.dumps({'content':'<article>Example</article>','textContent':'Example text','title':'Example Title'}))" |
| 107 | + "import json, pathlib, sys\n" |
| 108 | + "args = sys.argv[1:]\n" |
| 109 | + "assert 'parse' in args\n" |
| 110 | + "idx = args.index('parse') + 1\n" |
| 111 | + "source = pathlib.Path(args[idx])\n" |
| 112 | + "assert source.is_file()\n" |
| 113 | + "assert str(source).startswith('/')\n" |
| 114 | + "assert not str(source).startswith('http')\n" |
| 115 | + "assert '--json' in args or '-j' in args\n" |
| 116 | + "print(json.dumps({'content':'<article>Example</article>','textContent':'Example text','title':'Example Title'}))\n" |
94 | 117 | ) |
95 | 118 | fake_binary.chmod(fake_binary.stat().st_mode | stat.S_IXUSR) |
96 | 119 |
|
@@ -126,3 +149,4 @@ def test_extracts_article_with_json_output_from_binary(): |
126 | 149 | assert "Example text" in (output_dir / "content.txt").read_text(encoding="utf-8") |
127 | 150 | metadata = json.loads((output_dir / "article.json").read_text(encoding="utf-8")) |
128 | 151 | assert metadata.get("title") == "Example Title" |
| 152 | + assert expected_html.exists() |
0 commit comments