Skip to content
Open
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
6 changes: 1 addition & 5 deletions nameparser/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ class Constants:
capitalization_exceptions: TupleManager[str]
regexes: RegexTupleManager

_pst: Set[str] | None

string_format = "{title} {first} {middle} {last} {suffix} ({nickname})"
"""
Expand Down Expand Up @@ -262,13 +261,10 @@ def __init__(self,
self.conjunctions = SetManager(conjunctions)
self.capitalization_exceptions = TupleManager(capitalization_exceptions)
self.regexes = RegexTupleManager(regexes)
self._pst = None

@property
def suffixes_prefixes_titles(self) -> Set[str]:
if not self._pst:
self._pst = self.prefixes | self.suffix_acronyms | self.suffix_not_acronyms | self.titles
return self._pst
return self.prefixes | self.suffix_acronyms | self.suffix_not_acronyms | self.titles

def __repr__(self) -> str:
return "<Constants() instance>"
Expand Down
32 changes: 32 additions & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,35 @@ def test_add_constant_with_explicit_encoding(self) -> None:
c = Constants()
c.titles.add_with_encoding(b'b\351ck', encoding='latin_1')
self.assertIn('béck', c.titles)

def test_suffixes_prefixes_titles_reflects_add_title(self) -> None:
"""suffixes_prefixes_titles must include titles added after construction."""
c = Constants()
c.titles.add('emerita')
self.assertIn('emerita', c.suffixes_prefixes_titles)

def test_suffixes_prefixes_titles_reflects_add_prefix(self) -> None:
"""suffixes_prefixes_titles must include prefixes added after construction."""
c = Constants()
c.prefixes.add('xpfx')
self.assertIn('xpfx', c.suffixes_prefixes_titles)

def test_suffixes_prefixes_titles_reflects_remove_title(self) -> None:
"""suffixes_prefixes_titles must not include a word that was only in titles and is then removed."""
c = Constants()
c.titles.add('emerita')
self.assertIn('emerita', c.suffixes_prefixes_titles)
c.titles.remove('emerita')
self.assertFalse('emerita' in c.suffixes_prefixes_titles)

def test_is_rootname_consistent_with_is_title(self) -> None:
"""is_rootname must return False for words recognised by is_title."""
hn = HumanName("", constants=None)
hn.C.titles.add('emerita')
self.assertFalse(hn.is_rootname('emerita'))

def test_is_rootname_consistent_with_is_prefix(self) -> None:
"""is_rootname must return False for words recognised by is_prefix."""
hn = HumanName("", constants=None)
hn.C.prefixes.add('xpfx')
self.assertFalse(hn.is_rootname('xpfx'))