From cb1bb8e70e72d40552b8f02ad677661b5176dd14 Mon Sep 17 00:00:00 2001 From: Simeon Visser Date: Thu, 22 Jul 2021 22:18:00 +0200 Subject: [PATCH] Return list instead of tuple in choices_distribution --- faker/utils/distribution.py | 2 +- tests/providers/__init__.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/faker/utils/distribution.py b/faker/utils/distribution.py index 64cc2e084d..93b133d48f 100644 --- a/faker/utils/distribution.py +++ b/faker/utils/distribution.py @@ -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: diff --git a/tests/providers/__init__.py b/tests/providers/__init__.py index 23816985dd..d175f3a255 100644 --- a/tests/providers/__init__.py +++ b/tests/providers/__init__.py @@ -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()