31 lines
891 B
Python
31 lines
891 B
Python
from ingestion.segment.units import normalize_unit_token, validate_unit_tokens
|
|
|
|
|
|
def test_clean_unit_passes_through():
|
|
assert normalize_unit_token("mg") == "mg"
|
|
assert normalize_unit_token("mcg") == "mcg"
|
|
assert normalize_unit_token("mmol") == "mmol"
|
|
|
|
|
|
def test_stray_whitespace_split_recovered_by_analogy_to_atc():
|
|
assert normalize_unit_token("m g") == "mg"
|
|
assert normalize_unit_token("m cg") == "mcg"
|
|
|
|
|
|
def test_case_insensitive():
|
|
assert normalize_unit_token("MG") == "mg"
|
|
|
|
|
|
def test_unknown_token_not_recovered():
|
|
assert normalize_unit_token("xyz") is None
|
|
assert normalize_unit_token("") is None
|
|
|
|
|
|
def test_validate_unit_tokens_flags_only_bad_ones():
|
|
bad = validate_unit_tokens(["mg", "mcg", "xyz", "ml"])
|
|
assert bad == ["xyz"]
|
|
|
|
|
|
def test_validate_unit_tokens_empty_when_all_valid():
|
|
assert validate_unit_tokens(["mg", "mcg", "mmol"]) == []
|