Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions tests/v2/test_local_agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,57 @@ def test_a_score_whose_worker_read_another_nameparser_aborts(
monkeypatch.setattr(nameparser, "__file__", "/elsewhere/nameparser/__init__.py")
with pytest.raises(SystemExit, match="a worker imported nameparser from"):
agreement.score(list(_ALL), _PSC_FIELDS, Parser(), jobs=2)


# -- a source whose given box holds the middle names (orcid-researchers) -----

_ORCID_FIELDS = agreement.FIELDED[corpora.ORCID]


def _held(given: str, family: str, country: str = "NZ") -> dict[str, str]:
return {"name": f"{given} {family}".strip(), "given": given, "family": family,
"country": country}


def test_a_given_box_holding_the_middle_names_is_compared_with_both() -> None:
# The parser reads Marie as a middle name; the box holds both words.
agrees = agreement.read(_held("Ann Marie", "Lee"), _ORCID_FIELDS, Parser(), _LISTED)
assert (agrees.got, agrees.set_aside) == ({}, False)
# Off: the box compared with the given name alone misses.
alone = agreement.Fielded({"given": "given", "family": "family"}, group="country")
assert agreement.read(_held("Ann Marie", "Lee"), alone, Parser(), _LISTED).got == {
"given": "Ann"}


def test_a_source_with_no_title_box_scores_a_read_title_as_a_miss_not_filer_error() -> None:
reading = agreement.read(_held("Dr Ann", "Lee"), _ORCID_FIELDS, Parser(), _LISTED)
assert (reading.got, reading.set_aside) == ({"given+middle": "Ann"}, False)


def test_a_peeled_suffix_is_compared_inside_the_family_box_of_a_joined_source() -> None:
reading = agreement.read(_held("Bob", "Roe Jr"), _ORCID_FIELDS, Parser(), _LISTED)
assert (reading.got, reading.by_suffix) == ({}, True)


def test_a_country_code_group_prints_as_written(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(agreement, "GROUP_FLOOR", 1)
result = agreement.score([_held("Ann", "Lee"), _held("Bo Yu", "Wu Li", "CN")],
_ORCID_FIELDS, Parser())
assert result.scored == {"NZ": 1, "CN": 1}
assert result.misses == {"CN": {"given+middle": 1, "family": 1}}
assert result.shapes == {"given+middle 2->3, family 2->1": 1}


def test_the_roles_a_box_may_name_are_the_parsers() -> None:
from nameparser import Role
assert agreement.ROLES == {role.value for role in Role}


@pytest.mark.parametrize("fields", [
{"forename": "given", "surname": "famly"},
{"forename": "given+midle", "surname": "family"},
{"forename": "given"}])
def test_a_fielded_source_naming_an_unknown_role_or_no_family_is_refused(
fields: dict[str, str]) -> None:
with pytest.raises(ValueError, match="each box names roles of"):
agreement.Fielded(fields, group="nationality")
16 changes: 9 additions & 7 deletions tests/v2/test_local_corpora.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
# the fetches read, so a patch reaches the code only when it is set on
# the module holding the name (local_core.RETRIES, local_fec.FEC_MAX_BAD).
# A second load by path (load_tool) would be a copy nothing reads.
core, ctgov, fec, tse, tw, ukec, psc, jrc, nepal = (
core, ctgov, fec, tse, tw, ukec, psc, jrc, nepal, orcid = (
importlib.import_module(f"local_{key}")
for key in ("core", "ctgov", "fec", "tse", "tw", "ukec", "psc", "jrc", "nepal"))
for key in ("core", "ctgov", "fec", "tse", "tw", "ukec", "psc", "jrc", "nepal", "orcid"))

_SOURCE = "ctgov-officials"
_DATE = "2026-10-21T09:00:05"
Expand Down Expand Up @@ -2669,7 +2669,8 @@ def test_a_second_corpus_key_the_records_do_not_fill_is_refused(
assert local.load(_NEPAL) is None


@pytest.mark.parametrize("source", sorted(set(local.SOURCES) - {_NEPAL}))
@pytest.mark.parametrize("source", sorted(
s for s, row in local.SOURCES.items() if row.corpus_keys == ("name",)))
def test_every_other_source_s_corpus_and_index_read_the_name_alone(
monkeypatch: pytest.MonkeyPatch, source: str) -> None:
# A record's other keys (psc's boxes, tse's registry name) are no
Expand Down Expand Up @@ -3344,19 +3345,20 @@ def test_no_module_imports_a_sibling_constant() -> None:
# tse.TSE_MAX_BAD), and every other reader reads it through that
# module. A `from local_x import CONSTANT` would bind a second name a
# patch on local_x cannot reach, and a test could pass with its guard
# off. The modules are SOURCES' own, so a new source is covered. PSC and
# JRC are sources' names, keys of SOURCES, and no fetch's setting.
# off. The modules are SOURCES' own, so a new source is covered. PSC,
# JRC and ORCID are sources' names, keys of SOURCES, and no fetch's setting.
import ast
sources = {source.fetch.__module__ for source in local.SOURCES.values()}
assert sources == {m.__name__ for m in (ctgov, fec, tse, tw, ukec, psc, jrc, nepal)}
assert sources == {m.__name__ for m in (ctgov, fec, tse, tw, ukec, psc, jrc, nepal, orcid)}
siblings = {"local_corpora", "local_core", *sources}
imported = {(path.stem, alias.name)
for path in (Path(str(local.__file__)).parent / f"{s}.py"
for s in sorted(siblings))
for node in ast.walk(ast.parse(path.read_text(encoding="utf-8")))
if isinstance(node, ast.ImportFrom) and node.module in siblings
for alias in node.names if alias.name.lstrip("_").isupper()}
assert imported == {("local_corpora", "PSC"), ("local_corpora", "JRC")}
assert imported == {("local_corpora", "PSC"), ("local_corpora", "JRC"),
("local_corpora", "ORCID")}


def test_the_fold_lists_everything_its_functions_call_and_read() -> None:
Expand Down
Loading
Loading