diff --git a/nameparser/parser.py b/nameparser/parser.py index cb88a84..7b71cd9 100644 --- a/nameparser/parser.py +++ b/nameparser/parser.py @@ -570,8 +570,8 @@ def is_conjunction(self, piece: str) -> bool: for item in piece: if self.is_conjunction(item): return True - else: - return piece.lower() in self.C.conjunctions and not self.is_an_initial(piece) + return False + return piece.lower() in self.C.conjunctions and not self.is_an_initial(piece) def is_prefix(self, piece: str) -> bool: """ @@ -582,8 +582,8 @@ def is_prefix(self, piece: str) -> bool: for item in piece: if self.is_prefix(item): return True - else: - return lc(piece) in self.C.prefixes + return False + return lc(piece) in self.C.prefixes def is_bound_first_name(self, piece: str) -> bool: """Lowercased, leading/trailing-periods-stripped version of piece is in :py:attr:`~nameparser.config.Constants.bound_first_names`.""" @@ -641,6 +641,7 @@ def is_suffix(self, piece: str) -> bool: for item in piece: if self.is_suffix(item): return True + return False else: return ((lc(piece).replace('.', '') in self.C.suffix_acronyms) or (lc(piece) in self.C.suffix_not_acronyms)) \ @@ -852,7 +853,7 @@ def fix_phd(self) -> None: if match := _re.search(self._full_name): self.suffix_list.extend(match.groups()) - self._full_name = _re.sub('', self._full_name) + self._full_name = _re.sub("", self._full_name) def parse_nicknames(self) -> None: """ diff --git a/tests/test_python_api.py b/tests/test_python_api.py index 2dbf504..66d067d 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -286,12 +286,30 @@ def test_is_prefix_with_list(self) -> None: self.assertTrue(hn.is_prefix(items)) self.assertTrue(hn.is_prefix(items[1:])) + def test_is_prefix_with_list_no_match(self) -> None: + hn = HumanName() + self.assertFalse(hn.is_prefix(['firstname', 'lastname'])) + def test_is_conjunction_with_list(self) -> None: hn = HumanName() items = ['firstname', 'lastname', 'and'] self.assertTrue(hn.is_conjunction(items)) self.assertTrue(hn.is_conjunction(items[1:])) + def test_is_conjunction_with_list_no_match(self) -> None: + hn = HumanName() + self.assertFalse(hn.is_conjunction(['firstname', 'lastname'])) + + def test_is_suffix_with_list(self) -> None: + hn = HumanName() + items = ['firstname', 'lastname', 'jr'] + self.assertTrue(hn.is_suffix(items)) + self.assertTrue(hn.is_suffix(items[1:])) + + def test_is_suffix_with_list_no_match(self) -> None: + hn = HumanName() + self.assertFalse(hn.is_suffix(['firstname', 'lastname'])) + def test_override_constants(self) -> None: C = Constants() hn = HumanName(constants=C)