From f61591016bf07db8b600bbd9383dcad4aaf03e74 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sun, 10 Oct 2004 03:55:29 +0000 Subject: [PATCH] Added a test for random.choice behavior. --- src/fix.py | 2 +- test/test_fix.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fix.py b/src/fix.py index 87b679bdf..e787922c6 100644 --- a/src/fix.py +++ b/src/fix.py @@ -49,7 +49,7 @@ string.ascii = string.maketrans('', '') import random _choice = random.choice def choice(iterable): - if isinstance(iterable, list): + if isinstance(iterable, (list, tuple)): return _choice(iterable) else: n = 1 diff --git a/test/test_fix.py b/test/test_fix.py index 3acb2a629..f11f9a8be 100644 --- a/test/test_fix.py +++ b/test/test_fix.py @@ -31,9 +31,13 @@ from testsupport import * +import random import itertools class FunctionsTest(SupyTestCase): + def testRandomChoice(self): + self.assertRaises(IndexError, random.choice, {}) + def testReversed(self): L = range(10) revL = list(reversed(L))