| import pytest |
|
|
| from legex.models.base import Case |
| from legex.scrapers.ch import CHScraper |
|
|
|
|
| @pytest.mark.parametrize( |
| "url, expected", |
| [ |
| |
| ( |
| "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=03.10.2024_4A_426/2024", |
| ("4A_426/2024", "4A", "4"), |
| ), |
| ( |
| "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=20.10.2025_4A_43/2025", |
| ("4A_43/2025", "4A", "4"), |
| ), |
| ( |
| "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=12.11.2025_5A_957/2025", |
| ("5A_957/2025", "5A", "5"), |
| ), |
| ( |
| "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=06.11.2024_7B_893/2024", |
| ("7B_893/2024", "7B", "7"), |
| ), |
| |
| ( |
| "http://relevancy.bger.ch/php/aza/http/index.php?highlight_docid=aza://09-09-2025-9C_276-2025&lang=de", |
| ("9C_276/2025", "9C", "9"), |
| ), |
| |
| ( |
| "https://search.bger.ch/ext/eurospider/live/de/php/aza/http/index.php?" |
| "lang=de&highlight_docid=aza%3A%2F%2F29-07-2025-2C_401-2025&rank=43", |
| ("2C_401/2025", "2C", "2"), |
| ), |
| |
| ("https://example.com/not-a-case", (None, None, None)), |
| ("", (None, None, None)), |
| (None, (None, None, None)), |
| ], |
| ) |
| def test_parse_case_id(url: str | None, expected: tuple) -> None: |
| assert CHScraper.parse_case_id(url) == expected |
|
|
|
|
| def _case(division: str | None, case_id: str) -> Case: |
| md = {"division": division} if division else {} |
| return Case(case_id=case_id, link=f"http://x/{case_id}", jurisdiction="ch", metadata=md) |
|
|
|
|
| def test_civil_filter_keeps_4_and_5_drops_rest() -> None: |
| cases = [_case(d, f"{d}X_1/2020") for d in ["1", "2", "4", "5", "6", None]] |
| assert [c.case_id for c in CHScraper.civil_filter(cases)] == ["4X_1/2020", "5X_1/2020"] |
|
|