Files
stack/tests/drugs/test_codes.py
kert aac023cc29
Some checks failed
CI / lint (push) Successful in 1m25s
CI / notebooks-smoke (push) Successful in 2m11s
Deploy / changes (push) Successful in 22s
Infra CI / notebooks (push) Successful in 1m0s
CI / test (push) Failing after 5m34s
Infra CI / zotero (push) Successful in 31s
Infra CI / docs (push) Successful in 54s
Infra CI / api (push) Successful in 2m5s
Infra CI / bcda (push) Successful in 2m21s
Infra CI / llm (push) Successful in 1m30s
Infra CI / mc (push) Successful in 35s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Deploy / api (push) Successful in 2m14s
Deploy / bcda (push) Successful in 2m35s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m47s
Deploy / report (push) Successful in 16s
Harden / build-scan-report (push) Successful in 37m31s
Comment Pull / comment-pull (push) Failing after 1m2s
Notebooks Integration / notebooks-integration (push) Failing after 11m47s
LLM Golden / llm-golden (push) Successful in 9m47s
Renovate / renovate (push) Successful in 1m56s
Zotero Sync / zotero-sync (push) Successful in 2m56s
BCDA Vendor / bcda-vendor (push) Failing after 41s
Package Supply Chain / pkg-supply-chain (push) Successful in 1m23s
fix(drugs): re-posted ASP files link to what they supersede in the manifest; 8-word guard over served drugs text; ndc11 whitespace tolerance documented
2026-11-13 04:39:35 -05:00

95 lines
3.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from datetime import date
import pytest
from drugs import codes
def test_level():
assert codes.level("90371") == "I"
assert codes.level("0202U") == "I"
assert codes.level("J9035") == "II"
assert codes.level("Q4101") == "II"
assert codes.level("D0120") == "CDT"
assert codes.level("A1") == ""
assert codes.licensed("D0120") is True
assert codes.licensed("90371") is True
assert codes.licensed("J9035") is False
assert codes.licensed("") is False
def test_ndc11_three_layouts():
n = codes.ndc11
assert n("0002-1433-80") == "00002143380"
assert n("50242-040-62") == "50242004062"
assert n("60574-4114-1") == "60574411401"
assert n("13533-0636-01") == "13533063601"
assert n("13533063601") == "13533063601"
assert n("1353306360") is None
assert n("ALT-ID 12") is None
assert n("123-45-6") is None
assert n(" 0002-1433-80 ") == "00002143380"
def test_appl_id():
assert codes.appl_id("N", "21436") == "NDA021436"
assert codes.appl_id("A", "90123") == "ANDA090123"
assert codes.appl_id("BLA", "125057") == "BLA125057"
assert codes.appl_id("NDA021436", "") == "NDA021436"
assert codes.appl_id("NDA", "21436") == "NDA021436"
assert codes.appl_id("ANDA", "90123") == "ANDA090123"
def test_expand():
assert codes.expand("J0287", "J0289") == ["J0287", "J0288", "J0289"]
assert codes.expand("J0287", "K0289") == ["J0287"]
assert codes.expand("J0287", "J0287") == ["J0287"]
assert codes.expand("J0289", "J0287") == ["J0289"]
assert codes.expand("JABCD", "JABCF") == ["JABCD"]
def test_quarters_and_fy():
assert codes.quarter(2026, 10) == "2026-Q4"
assert codes.quarter(2026, 1) == "2026-Q1"
assert codes.quarter(2026, 3) is None
assert codes.quarter_start("2026-Q4") == date(2026, 10, 1)
assert codes.quarter_end("2026-Q4") == date(2026, 12, 31)
assert codes.quarter_end("2026-Q1") == date(2026, 3, 31)
assert codes.fy_effective("2026") == date(2025, 10, 1)
assert codes.fy_effective("2026-04") == date(2026, 4, 1)
def test_level_and_ndc_reject_trailing_newline_and_fullwidth_digits():
assert codes.level("J9035\n") == ""
assert codes.level("90371") == ""
assert codes.level("90371") == ""
assert codes.licensed("90371\n") is False
assert codes.ndc11("000214338011") is None
assert codes.ndc11("00021433801") is None
assert codes.ndc11("0002-1433-80") is None
assert codes.ndc11("0002-1433-80") == "00002143380"
def test_appl_id_rejects_unknown_kinds():
with pytest.raises(ValueError, match="unknown application kind"):
codes.appl_id("X", "5")
with pytest.raises(ValueError):
codes.appl_id("", "5")
def test_expand_caps_range_size():
assert len(codes.expand("J0001", "J0500")) == 500
assert codes.MAX_RANGE == 500
with pytest.raises(ValueError, match="range too large"):
codes.expand("J0001", "J9999")
with pytest.raises(ValueError):
codes.expand("J0001", "J0501")
assert codes.expand("J9001", "J9002") == ["J9001"]
def test_ndc11_tolerates_surrounding_whitespace_but_level_does_not():
assert codes.ndc11(" 0002-1433-80\n") == "00002143380"
assert codes.ndc11("\t00021433801 ") == "00021433801"
assert codes.level(" J9035") == ""
assert codes.level("J9035 ") == ""