Skip to content

Commit 93f9ec2

Browse files
committed
pep8 tests and fix some test name clashes
1 parent 61fc1b4 commit 93f9ec2

1 file changed

Lines changed: 77 additions & 76 deletions

File tree

tests.py

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def m(self, actual, expected, hn):
5353
self.assertEquals(actual, expected)
5454

5555

56-
5756
class HumanNamePythonTests(HumanNameTestBase):
5857

5958
def test_utf8(self):
@@ -77,12 +76,12 @@ def test_len(self):
7776
hn = HumanName("John Doe")
7877
self.m(len(hn), 2, hn)
7978

80-
@unittest.skipUnless(dill,"requires python-dill module to test pickling")
79+
@unittest.skipUnless(dill, "requires python-dill module to test pickling")
8180
def test_config_pickle(self):
82-
C = Constants()
83-
self.assertTrue(dill.pickles(C))
81+
constants = Constants()
82+
self.assertTrue(dill.pickles(constants))
8483

85-
@unittest.skipUnless(dill,"requires python-dill module to test pickling")
84+
@unittest.skipUnless(dill, "requires python-dill module to test pickling")
8685
def test_name_instance_pickle(self):
8786
hn = HumanName("Title First Middle Middle Last, Jr.")
8887
self.assertTrue(dill.pickles(hn))
@@ -91,7 +90,7 @@ def test_comparison(self):
9190
hn1 = HumanName("Doe-Ray, Dr. John P., CLU, CFP, LUTC")
9291
hn2 = HumanName("Dr. John P. Doe-Ray, CLU, CFP, LUTC")
9392
self.assertTrue(hn1 == hn2)
94-
self.assertTrue(not hn1 is hn2)
93+
self.assertTrue(hn1 is not hn2)
9594
self.assertTrue(hn1 == "Dr. John P. Doe-Ray CLU, CFP, LUTC")
9695
hn1 = HumanName("Doe, Dr. John P., CLU, CFP, LUTC")
9796
hn2 = HumanName("Dr. John P. Doe-Ray, CLU, CFP, LUTC")
@@ -127,17 +126,17 @@ def test_assignment_to_attribute(self):
127126
with self.assertRaises(TypeError):
128127
hn.suffix = [['test']]
129128
with self.assertRaises(TypeError):
130-
hn.suffix = {"test":"test"}
129+
hn.suffix = {"test": "test"}
131130

132131
def test_assign_list_to_attribute(self):
133132
hn = HumanName("John A. Kenneth Doe, Jr.")
134-
hn.title = ["test1","test2"]
133+
hn.title = ["test1", "test2"]
135134
self.m(hn.title, "test1 test2", hn)
136-
hn.first = ["test3","test4"]
135+
hn.first = ["test3", "test4"]
137136
self.m(hn.first, "test3 test4", hn)
138-
hn.middle = ["test5","test6","test7"]
137+
hn.middle = ["test5", "test6", "test7"]
139138
self.m(hn.middle, "test5 test6 test7", hn)
140-
hn.last = ["test8","test9","test10"]
139+
hn.last = ["test8", "test9", "test10"]
141140
self.m(hn.last, "test8 test9 test10", hn)
142141
hn.suffix = ['test']
143142
self.m(hn.suffix, "test", hn)
@@ -146,13 +145,13 @@ def test_comparison_case_insensitive(self):
146145
hn1 = HumanName("Doe-Ray, Dr. John P., CLU, CFP, LUTC")
147146
hn2 = HumanName("dr. john p. doe-Ray, CLU, CFP, LUTC")
148147
self.assertTrue(hn1 == hn2)
149-
self.assertTrue(not hn1 is hn2)
148+
self.assertTrue(hn1 is not hn2)
150149
self.assertTrue(hn1 == "Dr. John P. Doe-ray clu, CFP, LUTC")
151150

152151
def test_slice(self):
153152
hn = HumanName("Doe-Ray, Dr. John P., CLU, CFP, LUTC")
154153
self.m(list(hn), ['Dr.', 'John', 'P.', 'Doe-Ray', 'CLU, CFP, LUTC'], hn)
155-
self.m(hn[1:], ['John', 'P.', 'Doe-Ray', 'CLU, CFP, LUTC',hn.C.empty_attribute_default], hn)
154+
self.m(hn[1:], ['John', 'P.', 'Doe-Ray', 'CLU, CFP, LUTC', hn.C.empty_attribute_default], hn)
156155
self.m(hn[1:-2], ['John', 'P.', 'Doe-Ray'], hn)
157156

158157
def test_getitem(self):
@@ -167,12 +166,12 @@ def test_setitem(self):
167166
hn = HumanName("Dr. John A. Kenneth Doe, Jr.")
168167
hn['title'] = 'test'
169168
self.m(hn['title'], "test", hn)
170-
hn['last'] = ['test','test2']
169+
hn['last'] = ['test', 'test2']
171170
self.m(hn['last'], "test test2", hn)
172171
with self.assertRaises(TypeError):
173172
hn["suffix"] = [['test']]
174173
with self.assertRaises(TypeError):
175-
hn["suffix"] = {"test":"test"}
174+
hn["suffix"] = {"test": "test"}
176175

177176
def test_conjunction_names(self):
178177
hn = HumanName("johnny y")
@@ -1261,31 +1260,30 @@ def test_portuguese_prefixes(self):
12611260
self.m(hn.last, "Souza", hn)
12621261

12631262

1264-
12651263
class ConstantsCustomization(HumanNameTestBase):
12661264

12671265
def test_add_title(self):
12681266
hn = HumanName("Te Awanui-a-Rangi Black", constants=None)
12691267
hn.C.titles.add('te')
12701268
hn.parse_full_name()
1271-
self.m(hn.title,"Te", hn)
1272-
self.m(hn.first,"Awanui-a-Rangi", hn)
1273-
self.m(hn.last,"Black", hn)
1269+
self.m(hn.title, "Te", hn)
1270+
self.m(hn.first, "Awanui-a-Rangi", hn)
1271+
self.m(hn.last, "Black", hn)
12741272

12751273
def test_remove_title(self):
12761274
hn = HumanName("Hon Solo", constants=None)
12771275
hn.C.titles.remove('hon')
12781276
hn.parse_full_name()
1279-
self.m(hn.first,"Hon", hn)
1280-
self.m(hn.last,"Solo", hn)
1277+
self.m(hn.first, "Hon", hn)
1278+
self.m(hn.last, "Solo", hn)
12811279

12821280
def test_add_multiple_arguments(self):
12831281
hn = HumanName("Assoc Dean of Chemistry Robert Johns", constants=None)
12841282
hn.C.titles.add('dean', 'Chemistry')
12851283
hn.parse_full_name()
1286-
self.m(hn.title,"Assoc Dean of Chemistry", hn)
1287-
self.m(hn.first,"Robert", hn)
1288-
self.m(hn.last,"Johns", hn)
1284+
self.m(hn.title, "Assoc Dean of Chemistry", hn)
1285+
self.m(hn.first, "Robert", hn)
1286+
self.m(hn.last, "Johns", hn)
12891287

12901288
def test_instances_can_have_own_constants(self):
12911289
hn = HumanName("", None)
@@ -1295,8 +1293,7 @@ def test_instances_can_have_own_constants(self):
12951293
self.assertEqual(hn.has_own_config, True)
12961294
self.assertEqual('hon' in hn2.C.titles, True)
12971295
self.assertEqual(hn2.has_own_config, False)
1298-
1299-
1296+
13001297
def test_can_change_global_constants(self):
13011298
hn = HumanName("")
13021299
hn2 = HumanName("")
@@ -1312,18 +1309,18 @@ def test_remove_multiple_arguments(self):
13121309
hn = HumanName("Ms Hon Solo", constants=None)
13131310
hn.C.titles.remove('hon', 'ms')
13141311
hn.parse_full_name()
1315-
self.m(hn.first,"Ms", hn)
1316-
self.m(hn.middle,"Hon", hn)
1317-
self.m(hn.last,"Solo", hn)
1312+
self.m(hn.first, "Ms", hn)
1313+
self.m(hn.middle, "Hon", hn)
1314+
self.m(hn.last, "Solo", hn)
13181315

13191316
def test_chain_multiple_arguments(self):
13201317
hn = HumanName("Dean Ms Hon Solo", constants=None)
13211318
hn.C.titles.remove('hon', 'ms').add('dean')
13221319
hn.parse_full_name()
1323-
self.m(hn.title,"Dean", hn)
1324-
self.m(hn.first,"Ms", hn)
1325-
self.m(hn.middle,"Hon", hn)
1326-
self.m(hn.last,"Solo", hn)
1320+
self.m(hn.title, "Dean", hn)
1321+
self.m(hn.first, "Ms", hn)
1322+
self.m(hn.middle, "Hon", hn)
1323+
self.m(hn.last, "Solo", hn)
13271324

13281325
def test_empty_attribute_default(self):
13291326
from nameparser.config import CONSTANTS
@@ -1421,7 +1418,7 @@ def test_single_quotes_on_end_of_last_name_not_treated_as_nickname(self):
14211418
self.m(hn.last, "Aube'", hn)
14221419
self.m(hn.nickname, "", hn)
14231420

1424-
#http://code.google.com/p/python-nameparser/issues/detail?id=17
1421+
# http://code.google.com/p/python-nameparser/issues/detail?id=17
14251422
def test_parenthesis_are_removed(self):
14261423
hn = HumanName("John Jones (Google Docs)")
14271424
self.m(hn.first, "John", hn)
@@ -1435,6 +1432,7 @@ def test_parenthesis_are_removed2(self):
14351432
self.m(hn.last, "Jones", hn)
14361433
self.m(hn.suffix, "Jr.", hn)
14371434

1435+
14381436
class PrefixesTestCase(HumanNameTestBase):
14391437

14401438
def test_prefix(self):
@@ -1543,7 +1541,7 @@ def test_phd_with_erroneous_space(self):
15431541
self.m(hn.last, "Smith", hn)
15441542
self.m(hn.suffix, "Ph. D.", hn)
15451543

1546-
#http://en.wikipedia.org/wiki/Ma_(surname)
1544+
# http://en.wikipedia.org/wiki/Ma_(surname)
15471545
def test_potential_suffix_that_is_also_last_name(self):
15481546
hn = HumanName("Jack Ma")
15491547
self.m(hn.first, "Jack", hn)
@@ -1586,23 +1584,23 @@ def test_king(self):
15861584
self.m(hn.last, "King", hn)
15871585
self.m(hn.suffix, "Jr", hn)
15881586

1589-
def test_suffix_with_periods(self):
1587+
def test_multiple_letter_suffix_with_periods(self):
15901588
hn = HumanName("John Doe Msc.Ed.")
1591-
self.m(hn.first,"John", hn)
1592-
self.m(hn.last,"Doe", hn)
1593-
self.m(hn.suffix,"Msc.Ed.", hn)
1589+
self.m(hn.first, "John", hn)
1590+
self.m(hn.last, "Doe", hn)
1591+
self.m(hn.suffix, "Msc.Ed.", hn)
15941592

15951593
def test_suffix_with_periods_with_comma(self):
15961594
hn = HumanName("John Doe, Msc.Ed.")
1597-
self.m(hn.first,"John", hn)
1598-
self.m(hn.last,"Doe", hn)
1599-
self.m(hn.suffix,"Msc.Ed.", hn)
1595+
self.m(hn.first, "John", hn)
1596+
self.m(hn.last, "Doe", hn)
1597+
self.m(hn.suffix, "Msc.Ed.", hn)
16001598

16011599
def test_suffix_with_periods_with_lastname_comma(self):
16021600
hn = HumanName("Doe, John Msc.Ed.")
1603-
self.m(hn.first,"John", hn)
1604-
self.m(hn.last,"Doe", hn)
1605-
self.m(hn.suffix,"Msc.Ed.", hn)
1601+
self.m(hn.first, "John", hn)
1602+
self.m(hn.last, "Doe", hn)
1603+
self.m(hn.suffix, "Msc.Ed.", hn)
16061604

16071605

16081606
class TitleTestCase(HumanNameTestBase):
@@ -1652,7 +1650,7 @@ def test_title_is_title(self):
16521650

16531651
# TODO: fix handling of U.S.
16541652
@unittest.expectedFailure
1655-
def test_chained_title_first_name_initial(self):
1653+
def test_chained_title_first_name_title_is_initials(self):
16561654
hn = HumanName("U.S. District Judge Marc Thomas Treadwell")
16571655
self.m(hn.title, "U.S. District Judge", hn)
16581656
self.m(hn.first, "Marc", hn)
@@ -1665,7 +1663,7 @@ def test_conflict_with_chained_title_first_name_initial(self):
16651663
self.m(hn.middle, "S.", hn)
16661664
self.m(hn.last, "Grant", hn)
16671665

1668-
def test_chained_title_first_name_initial(self):
1666+
def test_chained_title_first_name_initial_with_no_period(self):
16691667
hn = HumanName("US Magistrate Judge T Michael Putnam")
16701668
self.m(hn.title, "US Magistrate Judge", hn)
16711669
self.m(hn.first, "T", hn)
@@ -1781,8 +1779,8 @@ def test_possible_conflict_with_suffix_that_could_be_initial(self):
17811779
@unittest.expectedFailure
17821780
def test_ben_as_conjunction(self):
17831781
hn = HumanName("Ahmad ben Husain")
1784-
self.m(hn.first,"Ahmad", hn)
1785-
self.m(hn.last,"ben Husain", hn)
1782+
self.m(hn.first, "Ahmad", hn)
1783+
self.m(hn.last, "ben Husain", hn)
17861784

17871785
def test_ben_as_first_name(self):
17881786
hn = HumanName("Ben Johnson")
@@ -1809,15 +1807,16 @@ def test_last_name_also_prefix(self):
18091807

18101808
def test_title_with_periods(self):
18111809
hn = HumanName("Lt.Gov. John Doe")
1812-
self.m(hn.title,"Lt.Gov.", hn)
1813-
self.m(hn.first,"John", hn)
1814-
self.m(hn.last,"Doe", hn)
1810+
self.m(hn.title, "Lt.Gov.", hn)
1811+
self.m(hn.first, "John", hn)
1812+
self.m(hn.last, "Doe", hn)
18151813

18161814
def test_title_with_periods_lastname_comma(self):
18171815
hn = HumanName("Doe, Lt.Gov. John")
1818-
self.m(hn.title,"Lt.Gov.", hn)
1819-
self.m(hn.first,"John", hn)
1820-
self.m(hn.last,"Doe", hn)
1816+
self.m(hn.title, "Lt.Gov.", hn)
1817+
self.m(hn.first, "John", hn)
1818+
self.m(hn.last, "Doe", hn)
1819+
18211820

18221821
class HumanNameCapitalizationTestCase(HumanNameTestBase):
18231822
def test_capitalization_exception_for_III(self):
@@ -1892,11 +1891,12 @@ def test_portuguese_prefixes(self):
18921891
hn.capitalize()
18931892
self.m(str(hn), 'Joao da Silva do Amaral de Souza', hn)
18941893

1894+
18951895
class HumanNameOutputFormatTests(HumanNameTestBase):
18961896

18971897
def test_formatting_init_argument(self):
1898-
hn = HumanName("Rev John A. Kenneth Doe III (Kenny)",
1899-
string_format = "TEST1")
1898+
hn = HumanName("Rev John A. Kenneth Doe III (Kenny)",
1899+
string_format="TEST1")
19001900
self.assertEqual(u(hn), "TEST1")
19011901

19021902
def test_formatting_constants_attribute(self):
@@ -1935,63 +1935,64 @@ def test_formating_removing_pieces_from_name_buckets(self):
19351935
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III 'Kenny'")
19361936
hn.string_format = "{title} {first} {middle} {last} {suffix}"
19371937
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III")
1938-
hn.middle=''
1938+
hn.middle = ''
19391939
self.assertEqual(u(hn), "Rev John Doe III")
1940-
hn.suffix=''
1940+
hn.suffix = ''
19411941
self.assertEqual(u(hn), "Rev John Doe")
1942-
hn.title=''
1942+
hn.title = ''
19431943
self.assertEqual(u(hn), "John Doe")
19441944

19451945
def test_formating_of_nicknames_with_parenthesis(self):
19461946
hn = HumanName("Rev John A. Kenneth Doe III (Kenny)")
19471947
hn.string_format = "{title} {first} {middle} {last} {suffix} ({nickname})"
19481948
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III (Kenny)")
1949-
hn.nickname=''
1949+
hn.nickname = ''
19501950
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III")
19511951

19521952
def test_formating_of_nicknames_with_single_quotes(self):
19531953
hn = HumanName("Rev John A. Kenneth Doe III (Kenny)")
19541954
hn.string_format = "{title} {first} {middle} {last} {suffix} '{nickname}'"
19551955
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III 'Kenny'")
1956-
hn.nickname=''
1956+
hn.nickname = ''
19571957
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III")
19581958

19591959
def test_formating_of_nicknames_with_double_quotes(self):
19601960
hn = HumanName("Rev John A. Kenneth Doe III (Kenny)")
19611961
hn.string_format = "{title} {first} {middle} {last} {suffix} \"{nickname}\""
19621962
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III \"Kenny\"")
1963-
hn.nickname=''
1963+
hn.nickname = ''
19641964
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III")
19651965

19661966
def test_formating_of_nicknames_in_middle(self):
19671967
hn = HumanName("Rev John A. Kenneth Doe III (Kenny)")
19681968
hn.string_format = "{title} {first} ({nickname}) {middle} {last} {suffix}"
19691969
self.assertEqual(u(hn), "Rev John (Kenny) A. Kenneth Doe III")
1970-
hn.nickname=''
1970+
hn.nickname = ''
19711971
self.assertEqual(u(hn), "Rev John A. Kenneth Doe III")
19721972

19731973
def test_remove_emojis(self):
19741974
hn = HumanName("Sam Smith 😊")
1975-
self.m(hn.first,"Sam", hn)
1976-
self.m(hn.last,"Smith", hn)
1975+
self.m(hn.first, "Sam", hn)
1976+
self.m(hn.last, "Smith", hn)
19771977
self.assertEqual(u(hn), "Sam Smith")
19781978

19791979
def test_keep_non_emojis(self):
19801980
hn = HumanName("∫≜⩕ Smith 😊")
1981-
self.m(hn.first,"∫≜⩕", hn)
1982-
self.m(hn.last,"Smith", hn)
1981+
self.m(hn.first, "∫≜⩕", hn)
1982+
self.m(hn.last, "Smith", hn)
19831983
self.assertEqual(u(hn), "∫≜⩕ Smith")
19841984

19851985
def test_keep_emojis(self):
19861986
from nameparser.config import Constants
19871987
constants = Constants()
19881988
constants.regexes.emoji = False
19891989
hn = HumanName("∫≜⩕ Smith😊", constants)
1990-
self.m(hn.first,"∫≜⩕", hn)
1991-
self.m(hn.last,"Smith😊", hn)
1990+
self.m(hn.first, "∫≜⩕", hn)
1991+
self.m(hn.last, "Smith😊", hn)
19921992
self.assertEqual(u(hn), "∫≜⩕ Smith😊")
19931993
# test cleanup
19941994

1995+
19951996
TEST_NAMES = (
19961997
"John Doe",
19971998
"John Doe, Jr.",
@@ -2180,7 +2181,7 @@ def test_variations_of_TEST_NAMES(self):
21802181
hn = HumanName(name)
21812182
if len(hn.suffix_list) > 1:
21822183
hn = HumanName("{title} {first} {middle} {last} {suffix}".format(**hn.as_dict()).split(',')[0])
2183-
hn.C.empty_attribute_default = '' # format strings below require empty string
2184+
hn.C.empty_attribute_default = '' # format strings below require empty string
21842185
hn_dict = hn.as_dict()
21852186
attrs = [
21862187
'title',
@@ -2212,11 +2213,11 @@ def test_variations_of_TEST_NAMES(self):
22122213
if len(sys.argv) > 1:
22132214
log.setLevel(logging.ERROR)
22142215
log.addHandler(logging.StreamHandler())
2215-
name = sys.argv[1]
2216-
hn = HumanName(name, encoding=sys.stdout.encoding)
2217-
print((repr(hn)))
2218-
hn.capitalize()
2219-
print((repr(hn)))
2216+
name_string = sys.argv[1]
2217+
hn_instance = HumanName(name_string, encoding=sys.stdout.encoding)
2218+
print((repr(hn_instance)))
2219+
hn_instance.capitalize()
2220+
print((repr(hn_instance)))
22202221
else:
22212222
print("-"*80)
22222223
print("Running tests")

0 commit comments

Comments
 (0)