37
37
38
38
class HumanNameTestBase (unittest .TestCase ):
39
39
def m (self , actual , expected , hn ):
40
- """assertEquals with a better message"""
40
+ """assertEquals with a better message and awareness of hn.C.empty_attribute_default"""
41
+ expected = expected or hn .C .empty_attribute_default
41
42
try :
42
43
self .assertEqual (actual , expected , "'%s' != '%s' for '%s'\n %r" % (
43
44
actual ,
@@ -146,7 +147,7 @@ def test_comparison_case_insensitive(self):
146
147
def test_slice (self ):
147
148
hn = HumanName ("Doe-Ray, Dr. John P., CLU, CFP, LUTC" )
148
149
self .m (list (hn ), ['Dr.' , 'John' , 'P.' , 'Doe-Ray' , 'CLU, CFP, LUTC' ], hn )
149
- self .m (hn [1 :], ['John' , 'P.' , 'Doe-Ray' , 'CLU, CFP, LUTC' ,'' ], hn )
150
+ self .m (hn [1 :], ['John' , 'P.' , 'Doe-Ray' , 'CLU, CFP, LUTC' ,hn . C . empty_attribute_default ], hn )
150
151
self .m (hn [1 :- 2 ], ['John' , 'P.' , 'Doe-Ray' ], hn )
151
152
152
153
def test_getitem (self ):
@@ -1287,7 +1288,7 @@ def test_empty_attribute_on_instance(self):
1287
1288
def test_none_empty_attribute_string_formatting (self ):
1288
1289
hn = HumanName ("" , None )
1289
1290
hn .C .empty_attribute_default = None
1290
- self .m ('' , str (hn ), hn )
1291
+ self .assertEqual ('' , str (hn ), hn )
1291
1292
1292
1293
class HumanNameNicknameTestCase (HumanNameTestBase ):
1293
1294
# https://code.google.com/p/python-nameparser/issues/detail?id=33
@@ -2050,6 +2051,7 @@ def test_variations_of_TEST_NAMES(self):
2050
2051
hn = HumanName (name )
2051
2052
if len (hn .suffix_list ) > 1 :
2052
2053
hn = HumanName ("{title} {first} {middle} {last} {suffix}" .format (** hn .as_dict ()).split (',' )[0 ])
2054
+ hn .C .empty_attribute_default = '' # format strings below require empty string
2053
2055
hn_dict = hn .as_dict ()
2054
2056
attrs = [
2055
2057
'title' ,
@@ -2059,9 +2061,6 @@ def test_variations_of_TEST_NAMES(self):
2059
2061
'suffix' ,
2060
2062
'nickname' ,
2061
2063
]
2062
- for attr in attrs :
2063
- if not getattr (hn , attr ):
2064
- setattr (hn ,attr ,'' )
2065
2064
nocomma = HumanName ("{title} {first} {middle} {last} {suffix}" .format (** hn_dict ))
2066
2065
lastnamecomma = HumanName ("{last}, {title} {first} {middle} {suffix}" .format (** hn_dict ))
2067
2066
if hn .suffix :
@@ -2090,11 +2089,11 @@ def test_variations_of_TEST_NAMES(self):
2090
2089
hn .capitalize ()
2091
2090
print ((repr (hn )))
2092
2091
else :
2093
- # if log.level > 0:
2094
- # for name in TEST_NAMES:
2095
- # hn = HumanName(name )
2096
- # print((u(name)) )
2097
- # print((u(hn)) )
2098
- # print((repr(hn)))
2099
- # print("\n-------------------------------------------\n")
2092
+ print ( "-" * 80 )
2093
+ print ( "Running tests" )
2094
+ unittest . main ( exit = False )
2095
+ print ("-" * 80 )
2096
+ print ( "Running tests with empty_attribute_default = None" )
2097
+ from nameparser . config import CONSTANTS
2098
+ CONSTANTS . empty_attribute_default = None
2100
2099
unittest .main ()
0 commit comments