Skip to content
Merged
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
11 changes: 6 additions & 5 deletions nameparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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`."""
Expand Down Expand Up @@ -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)) \
Expand Down Expand Up @@ -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:
"""
Expand Down
18 changes: 18 additions & 0 deletions tests/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down