Skip to content

Commit 59cb4cb

Browse files
derek73claude
andcommitted
test: regression guards from the review
Match-time contract of lower()-not-casefold() pinned at parse level (ΚΟΣ and GROẞFÜRST match; ASCII-SS GROSSFÜRST deliberately does not, v1 parity); facade rows for each new vocabulary category (bound given, Hebrew suffix, Devanagari title); maiden-wins pinned on a typographic pair; a pre-#273 three-key pickle restores as exactly its own keys (setstate replaces, never merges defaults). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ed9938a commit 59cb4cb

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tests/test_constants.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,21 @@ def test_nickname_delimiters_default_builtins_resolve_live(self) -> None:
549549
# v1 trio still present, still stored name-as-value
550550
for name in ('quoted_word', 'double_quotes', 'parenthesis'):
551551
self.assertEqual(entries[name], name)
552+
# A pre-#273 pickle restores as exactly its own three keys --
553+
# __setstate__ REPLACES the bucket, never merges defaults in --
554+
# so old configs don't silently gain the typographic pairs.
555+
legacy = Constants()
556+
state = legacy.__getstate__()
557+
state['nickname_delimiters'] = {
558+
'quoted_word': 'quoted_word', 'double_quotes': 'double_quotes',
559+
'parenthesis': 'parenthesis'}
560+
restored = Constants.__new__(Constants)
561+
restored.__setstate__(state)
562+
self.assertEqual(set(restored.nickname_delimiters),
563+
{'quoted_word', 'double_quotes', 'parenthesis'})
564+
from nameparser import HumanName
565+
assert HumanName('John «Jack» Kennedy', constants=restored).nickname == ''
566+
assert HumanName('John (Jack) Kennedy', constants=restored).nickname == 'Jack'
552567
# 2.0 adds the #273 typographic sentinels alongside them, same
553568
# name-as-value scheme (full list pinned in tests/v2/
554569
# test_config_shim.py against _SENTINEL_PAIRS)

tests/v2/test_policy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ def test_maiden_delimiters_win_over_nickname_defaults() -> None:
111111
assert p == explicit and hash(p) == hash(explicit)
112112

113113

114+
def test_maiden_wins_applies_to_typographic_pairs_too() -> None:
115+
# the subtraction is pair-agnostic; pin one #273 pair end-to-end
116+
from nameparser import Parser
117+
118+
p = Policy(maiden_delimiters=frozenset({("«", "»")}))
119+
assert ("«", "»") not in p.nickname_delimiters
120+
n = Parser(policy=p).parse("Jean «Dupont» Martin")
121+
assert n.maiden == "Dupont" and n.nickname == ""
122+
123+
114124
def test_maiden_precedence_applies_through_policy_patch() -> None:
115125
# apply_patch re-runs Policy's constructor, so a patch (e.g. from a
116126
# locale pack) adding a maiden pair gets the same subtraction

0 commit comments

Comments
 (0)