-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Expand file tree
/
Copy pathtest_nonsense_url_language_roots.py
More file actions
53 lines (43 loc) 路 1.6 KB
/
Copy pathtest_nonsense_url_language_roots.py
File metadata and controls
53 lines (43 loc) 路 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Regression test for ``AsyncUrlSeeder._is_nonsense_url`` language roots.
The "very short path" filter measured length on the slash-stripped path but
matched the *un-stripped* path against the language-root whitelist, so the
canonical trailing-slash form (e.g. ``/en/``) was dropped as nonsense even
though ``/en`` was kept.
"""
import sys
from types import SimpleNamespace
import pytest
# Avoid the optional rank_bm25 dependency at import time (mirrors the sibling
# unit test); _is_nonsense_url itself does not use BM25.
sys.modules.setdefault("rank_bm25", SimpleNamespace(BM25Okapi=object))
from crawl4ai.async_url_seeder import AsyncUrlSeeder
@pytest.fixture
def seeder():
# _is_nonsense_url only uses its url argument (no instance state), so it is
# safe to bypass __init__.
return AsyncUrlSeeder.__new__(AsyncUrlSeeder)
@pytest.mark.parametrize(
"url",
[
"https://example.com/en",
"https://example.com/en/", # the bug: canonical trailing-slash form
"https://example.com/de/",
"https://example.com/fr/",
"https://example.com/es/",
"https://example.com/it/",
"https://example.com/",
"https://example.com/about",
],
)
def test_language_roots_are_not_filtered(seeder, url):
assert seeder._is_nonsense_url(url) is False
@pytest.mark.parametrize(
"url",
[
"https://example.com/ab/", # genuinely short, non-language path
"https://example.com/x",
"https://example.com/robots.txt",
],
)
def test_short_junk_and_utility_still_filtered(seeder, url):
assert seeder._is_nonsense_url(url) is True