Skip to content

Commit

Permalink
Return list instead of tuple in choices_distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
svisser committed Jul 22, 2021
1 parent 52e5018 commit cb1bb8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion faker/utils/distribution.py
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
5 changes: 5 additions & 0 deletions tests/providers/__init__.py
Expand Up @@ -152,6 +152,11 @@ def test_random_letter(self, faker, num_samples):
letter = faker.random_letter()
assert letter.isalpha()

def test_random_letters(self, faker):
assert isinstance(faker.random_letters(length=0), list)
assert isinstance(faker.random_letters(length=1), list)
assert isinstance(faker.random_letters(length=2), list)

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 cb1bb8e

Please sign in to comment.