summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-12-20 12:49:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-12-20 12:49:13 -0500
commitc54b27ab123a4bf29ba7bc76924e188e2bc88e9f (patch)
treefa2cb4af6c8783f169a2925c510dbc4dd0de986f /lib/sqlalchemy/testing/util.py
parente6afc0a8cf7a8fb18855cab9da488a0d48c42386 (diff)
downloadsqlalchemy-c54b27ab123a4bf29ba7bc76924e188e2bc88e9f.tar.gz
Implement random_choices for Python 2
Apparently py2k has no random.choices, so make a quick one for the tests that use it. Change-Id: Iadc3442b35f400b5bab0f711b7d3ede5dbc28f52
Diffstat (limited to 'lib/sqlalchemy/testing/util.py')
-rw-r--r--lib/sqlalchemy/testing/util.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py
index dbe6a383d..5244d0d37 100644
--- a/lib/sqlalchemy/testing/util.py
+++ b/lib/sqlalchemy/testing/util.py
@@ -66,6 +66,21 @@ def picklers():
yield pickle_.loads, lambda d: pickle_.dumps(d, protocol)
+if py2k:
+
+ def random_choices(population, k=1):
+ pop = list(population)
+ # lame but works :)
+ random.shuffle(pop)
+ return pop[0:k]
+
+
+else:
+
+ def random_choices(population, k=1):
+ return random.choices(population, k=k)
+
+
def round_decimal(value, prec):
if isinstance(value, float):
return round(value, prec)