def test_characters_do_not_break(raw): _ = Name(raw).raw
def t_strip_margin_hyphens(self, raw, cooked): assert Name.clean(raw) == cooked
def issue_7_allow_initials_written_properly(): n = Name("J.R.R. Tolkien") assert n.first == "j" assert n.middle == "r r" assert n.last == "tolkien"
def test_unit_do_not_grab_junior(clusters): blank = Name() _ = blank._grab_junior(clusters) assert "jr" not in blank.detail["suffix"]
def t_drop_spacing(self, raw): assert Name.clean(raw) == "mr eric praline"
def t_ignore_most_symbols(self, raw): assert Name.clean(raw) == "mr eric praline"
def test_conjunction_avoid(static): assert Name._combine_conjunctions(static) == static
def t_drop_emoji(self, raw): name = Name() assert name.clean(name._pre_clean(raw)) == "spiny norman"
def test_prefix_avoid(static): raw = " ".join(static) assert set(static) <= set(Name(raw).values())
def test_conjunction_combine(incoming, outgoing): assert Name._combine_conjunctions(incoming) == outgoing
def test_prefix_combining(incoming, outgoing): assert Name._combine_rightmost_prefixes(incoming) == outgoing
def issue_40_smart_quotes(): name = Name("Bergholt “BSJ” Johnson") assert name.nickname
def test_commas_do_not_break(raw1, raw2, raw3): _ = Name(f"{raw1},{raw2}").raw _ = Name(f"{raw1},{raw2},{raw3}").raw
def issue_4_clean_nicknames(): name = Name("ang%ua (ba%%rky) uberwald") assert name.first == "angua" assert name.nickname == "barky"
def only_weird_prefixes(): assert Name("van de von der von")
def issue_52_hyphenated_number(): name = Name("¼,A,A") assert name.first == "a" assert name.last == "a"
def issue_14_mc_and_mac_as_prefix(first, second): assert Name(first) == Name(second)
def t_convert_unicode(self, raw): """This is handled by unidecode and should not be extensively tested""" assert Name._pre_clean(raw) == "mr eric praline"
def issue_22_consistently_handle_of_prefixes_in_first_name(): name1 = Name("de ook, van ook yolo moomoo") name2 = Name("van ook yolo moomoo de ook") assert name1 == name2
def t_colons_and_commas(self, raw): assert Name.clean(raw) == "praline, mr eric"
def cli_report(raw_name: str, details: bool = True) -> int: """Parse into Name, output (core or report) attributes.""" name = Name(raw_name) output = name.report() if details else dict(name) prettier_print(output) return 0
def t_handle_certain_symbols(self, raw, cooked): assert Name.clean(raw) == cooked
def parse_name(s: str) -> T.Dict[str, T.Any]: """Parse into Name, return core name attributes as a dict. This is the simplest function interface to *nominally*. """ return dict(Name(s))
def test_sweep_suffixes(incoming, outs, outwork): bob = Name() observed_string = bob._sweep_suffixes(incoming) assert observed_string.strip() == outs assert bob.detail["suffix"] == outwork
def t_force_lower(self, raw): assert Name._pre_clean(raw) == "dinsdale"
def test_way_too_many_name_parts_post_suffix(): name = Name("johnson, bergholt, stuttley, joonyor") assert name.first == "bergholt" assert name.middle == "stuttley joonyor" assert name.last == "johnson"
def test_alphabetical_text_does_not_break(raw): _ = Name(raw).raw