diff --git a/nameparser/config/__init__.py b/nameparser/config/__init__.py index ce9da44..624ef6b 100644 --- a/nameparser/config/__init__.py +++ b/nameparser/config/__init__.py @@ -179,7 +179,6 @@ class Constants: capitalization_exceptions: TupleManager[str] regexes: RegexTupleManager - _pst: Set[str] | None string_format = "{title} {first} {middle} {last} {suffix} ({nickname})" """ @@ -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 "" diff --git a/tests/test_constants.py b/tests/test_constants.py index 9f619c3..ca13dc6 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -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'))