Download tests/scrapers/test_gh.py from legexbenchmark/code: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/legexbenchmark/code/resolve/main/tests/scrapers/test_gh.py
- Command line
-
hf download hf://datasets/legexbenchmark/code/tests/scrapers/test_gh.py
-
curl -L -o test_gh.py https://huggingface.co/datasets/legexbenchmark/code/resolve/main/tests/scrapers/test_gh.py
1.39 kB
| from legex.models.base import Case | |
| from legex.scrapers.gh import GHScraper, _CRIMINAL_RE | |
| def _case(title: str) -> Case: | |
| return Case(case_id="[2024] GHASC 1", jurisdiction="gh", metadata={"title": title}) | |
| def test_criminal_re_matches_classic(): | |
| assert _CRIMINAL_RE.match("Republic v Mensah") | |
| assert _CRIMINAL_RE.match("The Republic v Mensah") | |
| def test_criminal_re_matches_vrs(): | |
| assert _CRIMINAL_RE.match("Republic vrs Owusu") | |
| assert _CRIMINAL_RE.match("The Republic vrs. Owusu") | |
| def test_criminal_re_skips_civil(): | |
| assert not _CRIMINAL_RE.match("OWUSU & anor v MAPUTO & 3 ors") | |
| assert not _CRIMINAL_RE.match("In Re Estate of X") | |
| def test_civil_filter_drops_criminal(): | |
| cases = [_case("Republic v Smith"), _case("Mensah v Owusu")] | |
| kept = GHScraper.civil_filter(cases) | |
| assert [c.metadata["title"] for c in kept] == ["Mensah v Owusu"] | |
| def test_parse_listing_picks_up_link(): | |
| html = ( | |
| '<div><a href="/akn/gh/judgment/ghasc/2024/12/eng@2024-03-19" ' | |
| 'data-key-link="document">Foo v Bar [2024] GHASC 12 (19 March 2024)</a></div>' | |
| ) | |
| entries = list(GHScraper._parse_listing(html)) | |
| assert entries == [ | |
| ( | |
| "/akn/gh/judgment/ghasc/2024/12/eng@2024-03-19", | |
| "2024", | |
| "12", | |
| "2024-03-19", | |
| "Foo v Bar [2024] GHASC 12 (19 March 2024)", | |
| ) | |
| ] | |