aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks/test_scanner.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tasks/test_scanner.py')
-rw-r--r--tests/tasks/test_scanner.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py
index c0b9223..d16729c 100644
--- a/tests/tasks/test_scanner.py
+++ b/tests/tasks/test_scanner.py
@@ -82,6 +82,39 @@ def test_manual_scan_propagates_unrelated_errors(
scanner_module.manual_scan_sources.call_local()
+def test_scan_tree_returns_count_and_seen_paths(
+ app: Flask, scanner_module: ModuleType, tmp_path: Path, monkeypatch: MonkeyPatch
+) -> None:
+ for name in ("good", "bad"):
+ directory = tmp_path / name
+ directory.mkdir()
+ (directory / "index.html").write_text("<html></html>")
+
+ def parse(index_path: Path, **kwargs: Any) -> source_parser.ScannedSource:
+ if index_path.parent.name == "bad":
+ raise source_parser.SourceScanError("Unparseable source")
+ return source_parser.ScannedSource(
+ path="good/index.html",
+ url=f"{BASE_URL}good/",
+ content_hash="0" * 32,
+ targets=frozenset(),
+ )
+
+ monkeypatch.setattr(scanner_module, "scan_source_file", parse)
+ sources: dict[str, Source] = {}
+ urls: dict[str, str] = {}
+
+ with app.app_context():
+ scan = scanner_module.scan_tree(
+ tmp_path, BASE_URL, sources, urls, datetime.now(UTC)
+ )
+
+ assert scan.scanned_count == 1
+ assert scan.seen_paths == frozenset({"good/index.html", "bad/index.html"})
+ assert list(sources) == ["good/index.html"]
+ assert urls == {f"{BASE_URL}good/": "good/index.html"}
+
+
def test_scan_creates_source_and_webmentions(
app: Flask, scanner_module: ModuleType, tmp_path: Path, monkeypatch: MonkeyPatch
) -> None: