70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
|
|
"""Tests for MNC parser."""
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from aucourt_ingest.utils.mnc_parser import parse_mnc, is_valid_mnc
|
||
|
|
|
||
|
|
|
||
|
|
class TestParseMNC:
|
||
|
|
def test_standard_nsw(self):
|
||
|
|
r = parse_mnc("[2019] NSWSC 1234")
|
||
|
|
assert r is not None
|
||
|
|
assert r.year == 2019
|
||
|
|
assert r.court == "NSWSC"
|
||
|
|
assert r.number == 1234
|
||
|
|
assert r.jurisdiction == "NSW"
|
||
|
|
assert r.mnc == "[2019] NSWSC 1234"
|
||
|
|
|
||
|
|
def test_high_court(self):
|
||
|
|
r = parse_mnc("[2020] HCA 12")
|
||
|
|
assert r is not None
|
||
|
|
assert r.year == 2020
|
||
|
|
assert r.court == "HCA"
|
||
|
|
assert r.jurisdiction == "CTH"
|
||
|
|
|
||
|
|
def test_federal_court(self):
|
||
|
|
r = parse_mnc("[2021] FCA 456")
|
||
|
|
assert r is not None
|
||
|
|
assert r.court == "FCA"
|
||
|
|
assert r.jurisdiction == "CTH"
|
||
|
|
|
||
|
|
def test_queensland(self):
|
||
|
|
r = parse_mnc("[2018] QSC 78")
|
||
|
|
assert r is not None
|
||
|
|
assert r.jurisdiction == "QLD"
|
||
|
|
|
||
|
|
def test_victoria(self):
|
||
|
|
r = parse_mnc("[2022] VSC 333")
|
||
|
|
assert r is not None
|
||
|
|
assert r.jurisdiction == "VIC"
|
||
|
|
|
||
|
|
def test_extracts_from_longer_text(self):
|
||
|
|
r = parse_mnc("The matter is [2019] NSWSC 1234 and concerns...")
|
||
|
|
assert r is not None
|
||
|
|
assert r.year == 2019
|
||
|
|
assert r.court == "NSWSC"
|
||
|
|
|
||
|
|
def test_unknown_court(self):
|
||
|
|
r = parse_mnc("[2020] XXX 1")
|
||
|
|
assert r is not None
|
||
|
|
assert r.jurisdiction == "UNKNOWN"
|
||
|
|
|
||
|
|
def test_none_on_no_match(self):
|
||
|
|
assert parse_mnc("no citation here") is None
|
||
|
|
assert parse_mnc("") is None
|
||
|
|
assert parse_mnc("[not-a-year] NSWSC 1") is None
|
||
|
|
|
||
|
|
def test_none_on_malformed(self):
|
||
|
|
assert parse_mnc("[2019]NSWSC1234") is None # missing spaces
|
||
|
|
assert parse_mnc("[2019] 1234") is None # missing court code
|
||
|
|
assert parse_mnc("2019 NSWSC 1234") is None # missing brackets
|
||
|
|
|
||
|
|
|
||
|
|
class TestIsValidMNC:
|
||
|
|
def test_valid(self):
|
||
|
|
assert is_valid_mnc("[2019] NSWSC 1234")
|
||
|
|
assert is_valid_mnc("[2020] HCA 12")
|
||
|
|
|
||
|
|
def test_invalid(self):
|
||
|
|
assert not is_valid_mnc("not a citation")
|
||
|
|
assert not is_valid_mnc("")
|