-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move all simple unit tests into JSON file #61
base: master
Are you sure you want to change the base?
Conversation
Extra random notes:
Cheers, |
|
- This class name was duplicated in the next class, which was redefining it.
@derek73 sorry about the test not actually running — it looks like I used a duplicate class name, so it was just redefined later in the document, nulling the first one. It runs now (but the John Doe, Msc.Ed. test fails—is this expected?). Re: 4., okay, I suppose that might be complicated. Is there a way with the current code to set up the print(name) to print with, e.g., "{first initial} {last}", or similar? This would just be for simple one-word names. Cheers, |
By the way, if it's still desirable to have a separate test "function" for each test in the JSON, I think this could be doable by, in |
Cool, I was able to raise an error now. re 4, it's easier if you don't need to handle hyphenated names. You could do it with python string formatting, e.g.: >>> from nameparser import HumanName
>>> test = HumanName("Firstname Middle Last")
>>> test.string_format = '{first[0]} {middle[0]} {last[0]}'
>>> print(test)
F M L That's kinda brittle because it will barf if the name doesn't have all the keys in the format string. You could also treat it like an iterable, e.g.: >>> for part in test:
>>> if part: print(part[0])
F
M
L If you implemented something in the class that's probably how you'd do it, with some special case when it has a hyphen depending what you want it to return in that case. |
Some other thoughts as I'm using your branch as I try to look into some of the other bug reports.
|
This PR takes all "simple" unit tests, and puts them into a single JSON file to help clean things up.
The result is
tests.py
reduced to 814 lines, and an easier way to bulk-add new names (just append them to the JSON file).simple here means a test with a single
HumanName(...)
call, followed by severalself.m(...)
, with nothing else. No other tests are ported.Let me know what you think.
Cheers,
Miles