Skip to content

Commit

Permalink
Merge pull request #6 from svisser/patch-2
Browse files Browse the repository at this point in the history
Adapted get_first_name to be explicit about what gender value required
  • Loading branch information
treyhunner committed Sep 11, 2014
2 parents d700d5d + 2b26d8d commit 095aa2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion names/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def get_name(filename):


def get_first_name(gender=None):
if gender not in ('male', 'female'):
if gender is None:
gender = random.choice(('male', 'female'))
if gender not in ('male', 'female'):
raise ValueError("Only 'male' and 'female' are supported as gender")
return get_name(FILES['first:%s' % gender]).capitalize()


Expand Down
4 changes: 4 additions & 0 deletions test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def test_empty_file(self):
self.assertEqual(names.get_first_name(gender='male'), "")
self.assertEqual(names.get_first_name(gender='female'), "")
self.assertEqual(names.get_last_name(), "")

def test_only_male_and_female_gender_are_supported(self):
with self.assertRaises(ValueError):
names.get_first_name(gender='other')


class CommandLineTest(unittest.TestCase):
Expand Down

0 comments on commit 095aa2c

Please sign in to comment.