Skip to content
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

Make generation reproducible #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pgrandinetti
Copy link

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'
>>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant