Skip to content

Commit

Permalink
Return list instead of tuple in choices_distribution (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
svisser authored Jul 22, 2021
1 parent 52e5018 commit e27c113
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion faker/utils/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def choices_distribution(

if hasattr(random, 'choices'):
if length == 1 and p is None:
return (random.choice(a),)
return [random.choice(a)]
else:
return random.choices(a, weights=p, k=length)
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ def test_random_letter(self, faker, num_samples):
letter = faker.random_letter()
assert letter.isalpha()

@pytest.mark.parametrize('length', [0, 1, 2], ids=[
'empty_list', 'list_with_one_element', 'list_with_two_elements',
])
def test_random_letters(self, faker, length):
letters = faker.random_letters(length=length)
assert len(letters) == length
assert isinstance(letters, list)
for letter in letters:
assert letter.isalpha()

def test_random_lowercase_letter(self, faker, num_samples):
for _ in range(num_samples):
letter = faker.random_lowercase_letter()
Expand Down

0 comments on commit e27c113

Please sign in to comment.