Skip to content

Commit 29c76a5

Browse files
committed
use empty_attribute_default in tests
run all tests with both empty string and None values for empty_attribute_default
1 parent c2ef88b commit 29c76a5

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

tests.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
class HumanNameTestBase(unittest.TestCase):
3939
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
4142
try:
4243
self.assertEqual(actual, expected, "'%s' != '%s' for '%s'\n%r" % (
4344
actual,
@@ -146,7 +147,7 @@ def test_comparison_case_insensitive(self):
146147
def test_slice(self):
147148
hn = HumanName("Doe-Ray, Dr. John P., CLU, CFP, LUTC")
148149
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)
150151
self.m(hn[1:-2], ['John', 'P.', 'Doe-Ray'], hn)
151152

152153
def test_getitem(self):
@@ -1287,7 +1288,7 @@ def test_empty_attribute_on_instance(self):
12871288
def test_none_empty_attribute_string_formatting(self):
12881289
hn = HumanName("", None)
12891290
hn.C.empty_attribute_default = None
1290-
self.m('', str(hn), hn)
1291+
self.assertEqual('', str(hn), hn)
12911292

12921293
class HumanNameNicknameTestCase(HumanNameTestBase):
12931294
# https://code.google.com/p/python-nameparser/issues/detail?id=33
@@ -2050,6 +2051,7 @@ def test_variations_of_TEST_NAMES(self):
20502051
hn = HumanName(name)
20512052
if len(hn.suffix_list) > 1:
20522053
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
20532055
hn_dict = hn.as_dict()
20542056
attrs = [
20552057
'title',
@@ -2059,9 +2061,6 @@ def test_variations_of_TEST_NAMES(self):
20592061
'suffix',
20602062
'nickname',
20612063
]
2062-
for attr in attrs:
2063-
if not getattr(hn, attr):
2064-
setattr(hn,attr,'')
20652064
nocomma = HumanName("{title} {first} {middle} {last} {suffix}".format(**hn_dict))
20662065
lastnamecomma = HumanName("{last}, {title} {first} {middle} {suffix}".format(**hn_dict))
20672066
if hn.suffix:
@@ -2090,11 +2089,11 @@ def test_variations_of_TEST_NAMES(self):
20902089
hn.capitalize()
20912090
print((repr(hn)))
20922091
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
21002099
unittest.main()

0 commit comments

Comments
 (0)