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))