Skip to content

Commit c54b2cf

Browse files
derek73claude
andcommitted
test: add coverage for suffix_not_acronyms members in suffix-comma format
Add tests for 'I' (same single-letter ambiguity as 'V'), a mixed suffix-comma case (V MD), and two suffix_not_acronyms members together (V Jr.). Also tighten the are_suffixes_after_comma docstring to describe the short-circuit mechanism accurately and enumerate the full scope of affected suffix_not_acronyms entries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b72adf6 commit c54b2cf

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

nameparser/parser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,14 @@ def are_suffixes(self, pieces: Iterable[str]) -> bool:
488488
return True
489489

490490
def are_suffixes_after_comma(self, pieces: Iterable[str]) -> bool:
491-
"""Like are_suffixes but suffix_not_acronyms members are always
492-
recognized, even when they look like single-letter initials.
491+
"""Like are_suffixes, but pieces found in suffix_not_acronyms are
492+
accepted unconditionally without passing through is_suffix().
493493
494494
Used when detecting suffix-comma format (e.g. "John Ingram, V") where
495-
the post-comma position is unambiguous: a single uppercase roman
496-
numeral like 'V' is definitionally a suffix there, not an initial.
495+
the post-comma position is unambiguous. This covers all
496+
suffix_not_acronyms members (i, ii, iii, iv, v, jr, sr, etc.),
497+
case-insensitively, including single-letter entries that is_suffix()
498+
would otherwise reject via is_an_initial().
497499
"""
498500
for piece in pieces:
499501
if lc(piece) in self.C.suffix_not_acronyms:

tests/test_suffixes.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,34 @@ def test_two_suffixes_lastname_comma_format(self) -> None:
3535
self.m(hn.suffix, "Jr., MD", hn)
3636

3737
def test_roman_numeral_v_suffix_comma_format(self) -> None:
38-
# 'V' is a single uppercase letter, so it was incorrectly matched as an
39-
# initial and not recognized as a suffix (issue #136)
38+
# suffix-comma position is unambiguous: 'V' must be a suffix, not a single-letter initial
4039
hn = HumanName("John W. Ingram, V")
4140
self.m(hn.first, "John", hn)
4241
self.m(hn.middle, "W.", hn)
4342
self.m(hn.last, "Ingram", hn)
4443
self.m(hn.suffix, "V", hn)
4544

45+
def test_roman_numeral_i_suffix_comma_format(self) -> None:
46+
# 'I' has the same single-letter ambiguity as 'V'
47+
hn = HumanName("John W. Smith, I")
48+
self.m(hn.first, "John", hn)
49+
self.m(hn.middle, "W.", hn)
50+
self.m(hn.last, "Smith", hn)
51+
self.m(hn.suffix, "I", hn)
52+
53+
def test_suffix_not_acronym_then_acronym_suffix_comma_format(self) -> None:
54+
# single-letter suffix_not_acronyms entry followed by an acronym suffix
55+
hn = HumanName("John Smith, V MD")
56+
self.m(hn.first, "John", hn)
57+
self.m(hn.last, "Smith", hn)
58+
self.m(hn.suffix, "V MD", hn)
59+
60+
def test_two_suffix_not_acronyms_suffix_comma_format(self) -> None:
61+
hn = HumanName("John Smith, V Jr.")
62+
self.m(hn.first, "John", hn)
63+
self.m(hn.last, "Smith", hn)
64+
self.m(hn.suffix, "V Jr.", hn)
65+
4666
def test_two_suffixes_suffix_comma_format(self) -> None:
4767
hn = HumanName("Franklin Washington, Jr. MD")
4868
self.m(hn.first, "Franklin", hn)

0 commit comments

Comments
 (0)