I needed to make the functionality of this package reproducible across multiple runs, to create a simulation that can be analyzed.
Wrapped the functionalities into a class that has a random.Random object has as field.
Maintained backward compatibility.
Added unit test to check reproducibility.
Changed environment to 3.7, though it shouldn't make a big difference.
Test results
running test
WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.
running egg_info
writing names.egg-info/PKG-INFO
writing dependency_links to names.egg-info/dependency_links.txt
writing entry points to names.egg-info/entry_points.txt
writing top-level names to names.egg-info/top_level.txt
reading manifest file 'names.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'names.egg-info/SOURCES.txt'
running build_ext
test_cli (test_names.CommandLineTest) ... ok
test_correct_files (test_names.NamesTest) ... ok
test_empty_file (test_names.NamesTest) ... ok
test_get_name (test_names.NamesTest) ... ok
test_only_male_and_female_gender_are_supported (test_names.NamesTest) ... ok
test_random_gender (test_names.NamesTest) ... ok
test_reproducibility (test_names.NamesTest) ... ok
----------------------------------------------------------------------
Ran 7 tests in 1.316s
OK
______________________________________________________________________ summary ______________________________________________________________________
py37: commands succeeded
congratulations :)
Example usage
# old usage still works out-of-the-box
>>> import names
>>> names.get_full_name()
'David Johnson'
>>> names.get_full_name(gender='male')
'David Burkart'
>>> names.get_first_name()
'Marie'
>>> names.get_first_name(gender='female')
'Lida'
>>> names.get_last_name()
'Rossi'
# new functionality to reproduce the generation
>>> gen = names.Names(123)
>>> gen.get_full_name()
'Christopher Dryer'
>>> gen.get_first_name(gender='female')
'Virginia'
>>> gen2 = names.Names(123)
>>> gen2.get_full_name()
'Christopher Dryer'
>>> gen2.get_first_name(gender='female')
'Virginia'
>>>
I needed to make the functionality of this package reproducible across multiple runs, to create a simulation that can be analyzed.
random.Random
object has as field.Test results
Example usage