|
20 | 20 | """
|
21 | 21 |
|
22 | 22 | import logging
|
| 23 | +import re |
23 | 24 | try:
|
24 | 25 | import dill
|
25 | 26 | except ImportError:
|
26 | 27 | dill = False
|
27 | 28 |
|
28 | 29 | from nameparser import HumanName
|
29 | 30 | from nameparser.util import u
|
30 |
| -from nameparser.config import Constants |
| 31 | +from nameparser.config import Constants, TupleManager |
31 | 32 |
|
32 | 33 | log = logging.getLogger('HumanName')
|
33 | 34 |
|
@@ -199,6 +200,59 @@ def test_surnames_attribute(self):
|
199 | 200 | hn = HumanName("John Edgar Casey Williams III")
|
200 | 201 | self.m(hn.surnames, "Edgar Casey Williams", hn)
|
201 | 202 |
|
| 203 | + def test_override_constants(self): |
| 204 | + C = Constants() |
| 205 | + hn = HumanName(constants=C) |
| 206 | + self.assertTrue(hn.C is C) |
| 207 | + |
| 208 | + def test_override_regex(self): |
| 209 | + var = TupleManager([("spaces", re.compile(r"\s+", re.U)),]) |
| 210 | + C = Constants(regexes=var) |
| 211 | + hn = HumanName(constants=C) |
| 212 | + self.assertTrue(hn.C.regexes == var) |
| 213 | + |
| 214 | + def test_override_titles(self): |
| 215 | + var = ["abc","def"] |
| 216 | + C = Constants(titles=var) |
| 217 | + hn = HumanName(constants=C) |
| 218 | + self.assertTrue(sorted(hn.C.titles) == sorted(var)) |
| 219 | + |
| 220 | + def test_override_first_name_titles(self): |
| 221 | + var = ["abc","def"] |
| 222 | + C = Constants(first_name_titles=var) |
| 223 | + hn = HumanName(constants=C) |
| 224 | + self.assertTrue(sorted(hn.C.first_name_titles) == sorted(var)) |
| 225 | + |
| 226 | + def test_override_prefixes(self): |
| 227 | + var = ["abc","def"] |
| 228 | + C = Constants(prefixes=var) |
| 229 | + hn = HumanName(constants=C) |
| 230 | + self.assertTrue(sorted(hn.C.prefixes) == sorted(var)) |
| 231 | + |
| 232 | + def test_override_suffix_acronyms(self): |
| 233 | + var = ["abc","def"] |
| 234 | + C = Constants(suffix_acronyms=var) |
| 235 | + hn = HumanName(constants=C) |
| 236 | + self.assertTrue(sorted(hn.C.suffix_acronyms) == sorted(var)) |
| 237 | + |
| 238 | + def test_override_suffix_not_acronyms(self): |
| 239 | + var = ["abc","def"] |
| 240 | + C = Constants(suffix_not_acronyms=var) |
| 241 | + hn = HumanName(constants=C) |
| 242 | + self.assertTrue(sorted(hn.C.suffix_not_acronyms) == sorted(var)) |
| 243 | + |
| 244 | + def test_override_conjunctions(self): |
| 245 | + var = ["abc","def"] |
| 246 | + C = Constants(conjunctions=var) |
| 247 | + hn = HumanName(constants=C) |
| 248 | + self.assertTrue(sorted(hn.C.conjunctions) == sorted(var)) |
| 249 | + |
| 250 | + def test_override_capitalization_exceptions(self): |
| 251 | + var = TupleManager([("spaces", re.compile(r"\s+", re.U)),]) |
| 252 | + C = Constants(capitalization_exceptions=var) |
| 253 | + hn = HumanName(constants=C) |
| 254 | + self.assertTrue(hn.C.capitalization_exceptions == var) |
| 255 | + |
202 | 256 |
|
203 | 257 | class FirstNameHandlingTests(HumanNameTestBase):
|
204 | 258 | def test_first_name(self):
|
|
0 commit comments