Download tests/scrapers/test_at.py from legexbenchmark/code: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/datasets/legexbenchmark/code/resolve/main/tests/scrapers/test_at.py
- Command line
-
hf download hf://datasets/legexbenchmark/code/tests/scrapers/test_at.py
-
curl -L -o test_at.py https://huggingface.co/datasets/legexbenchmark/code/resolve/main/tests/scrapers/test_at.py
2.33 kB
| from datetime import date | |
| from legex.models.base import Case | |
| from legex.scrapers.at import ( | |
| ATScraper, | |
| _extract_text_from_xml, | |
| _first_geschaeftszahl, | |
| _norm_gz, | |
| _parse_doc_id_date, | |
| ) | |
| def _make(case_id: str, rechtsgebiete: str = "Zivilrecht") -> Case: | |
| return Case( | |
| case_id=case_id, | |
| jurisdiction="at", | |
| metadata={"rechtsgebiete": rechtsgebiete}, | |
| ) | |
| def test_parse_doc_id_date_jjr(): | |
| assert _parse_doc_id_date("JJR_20241219_OGH0002_0010OB00108_24Z0000_000") == date(2024, 12, 19) | |
| def test_parse_doc_id_date_jjt(): | |
| assert _parse_doc_id_date("JJT_20230515_OGH0002_0040OB00042_23X0000_000") == date(2023, 5, 15) | |
| def test_parse_doc_id_date_invalid(): | |
| assert _parse_doc_id_date("not-a-real-id") is None | |
| assert _parse_doc_id_date("") is None | |
| def test_first_geschaeftszahl_single(): | |
| assert _first_geschaeftszahl("4Ob402/85") == "4Ob402/85" | |
| def test_first_geschaeftszahl_list_string(): | |
| # API often joins related cases with semicolons; we take the first. | |
| raw = {"item": "4Ob402/85; 4Ob402/87; 4Ob128/89"} | |
| assert _first_geschaeftszahl(raw) == "4Ob402/85" | |
| def test_civil_filter_keeps_zivilrecht(): | |
| cases = [_make("1Ob1/24z", "Zivilrecht"), _make("2Os1/24x", "Strafrecht")] | |
| kept = ATScraper.civil_filter(cases) | |
| assert [c.case_id for c in kept] == ["1Ob1/24z"] | |
| def test_civil_filter_accepts_multi_value(): | |
| case = _make("1Ob1/24z", "Zivilrecht | Arbeitsrecht") | |
| assert ATScraper.civil_filter([case]) | |
| def test_norm_gz_strips_whitespace(): | |
| # RIS prints "1 Ob 108/24z" in some payloads and "1Ob108/24z" in others. | |
| assert _norm_gz("1 Ob 108/24z") == _norm_gz("1Ob108/24z") == "1ob108/24z" | |
| def test_extract_text_from_xml_concatenates_text_nodes(): | |
| xml = b"""<?xml version="1.0"?><root><a>Hello</a><b> world </b><c></c><d>foo bar</d></root>""" | |
| out = _extract_text_from_xml(xml) | |
| assert out == "Hello world foo bar" | |
| def test_extract_text_from_xml_invalid(): | |
| assert _extract_text_from_xml(b"<not xml>") is None | |
| def test_enrich_skips_cases_with_existing_text(): | |
| # If full_text is already set, enrich shouldn't make a network call. | |
| c = Case(case_id="1Ob1/24z", jurisdiction="at", full_text="cached", metadata={"doc_id": ""}) | |
| out = ATScraper.enrich([c]) | |
| assert out[0].full_text == "cached" | |