-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create skip_cleaning and prefixes Name arguments
Both ideas are discussed in #58. - skip_cleaning completely skips multiple stages of cleaning names and name parts. - prefixes allows the user to modify the list of prefixes, exposed from the default config.PREFIXES This currently only affects the Name class and is not part of the CLI or a full release while I consider: 1. How to implement a general way to override config lists such as suffixes, conjunctions, titles, etc. It's currently possible only to monkeypatch these, but since we can now adjust prefixes we should extend this to other constants. 2. Whether and how to incorporate any of these changes into the CLI. I'm leaning toward no, but perhaps --skip-cleaning is fine.
- Loading branch information
1 parent
f0879e3
commit f56c303
Showing
5 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
""" | ||
import pytest | ||
|
||
from nominally import Name | ||
from nominally.config import PREFIXES | ||
|
||
from .conftest import dict_entry_test | ||
""" | ||
|
||
|
||
def issue_58_respect_basic_case(): | ||
dict_entry_test( | ||
Name, | ||
{ | ||
"raw": "Herve Corre", | ||
"first": "Herve", | ||
"last": "Corre", | ||
}, | ||
skip_cleaning=True, | ||
) | ||
|
||
|
||
def issue_58_allow_skipping_cleaning_to_preserve_accents(): | ||
name = Name("Hervé Corre", skip_cleaning=True) | ||
assert name.first == "Hervé" | ||
assert name.last == "Corre" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"raw, first, middle, last", | ||
[ | ||
("Antonia Ax:son Johnson", "Antonia", "Ax:son", "Johnson"), | ||
("Elliot S! Maggin", "Elliot", "S!", "Maggin"), | ||
], | ||
) | ||
def issue_58_allow_skipping_cleaning_to_preserve_punctuation(raw, first, middle, last): | ||
name = Name(raw, skip_cleaning=True) | ||
assert name.first == first | ||
assert name.middle == middle | ||
assert name.last == last | ||
|
||
|
||
def issue_58_allow_skipping_cleaning_to_preserve_numbers(): | ||
name = Name("2 Chainz", skip_cleaning=True) | ||
assert name.first == "2" | ||
assert name.last == "Chainz" | ||
|
||
|
||
def issue_58_allow_skipping_cleaning_to_preserve_capitals(): | ||
name = Name("Herve Le Corre", skip_cleaning=True) | ||
assert name.first == "Herve" | ||
assert name.middle == "Le" | ||
assert name.last == "Corre" | ||
|
||
|
||
def issue_58_nofix_two_name_raw_despite_prefix(): | ||
""" | ||
This behavior is intended; an existing test uses "van nguyen" to capture the first | ||
name "van." | ||
""" | ||
name = Name("de patris", prefixes={"de"}) | ||
assert name.first == "de" | ||
assert name.last == "patris" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"prefix_arg, first, middle, last", | ||
[ | ||
(None, "herve", "pfx", "corre"), # default argument goes to config.PREFIXES | ||
({"pfx"} | PREFIXES, "herve", "", "pfx corre"), # Now "pfx" is part of suffixes | ||
({"pfx"}, "herve", "", "pfx corre"), # Now "pfx" is the ONLY suffix | ||
], | ||
) | ||
def issue_58_api_for_custom_prefixes(prefix_arg, first, middle, last): | ||
name = Name("herve pfx corre", prefixes=prefix_arg) | ||
assert name.first == first | ||
assert name.middle == middle | ||
assert name.last == last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters