Skip to content

Commit 5ae669f

Browse files
gh-135326: Test support of __index__ in random.getrandbits() (#135356)
1 parent 0f866cb commit 5ae669f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_random.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
from fractions import Fraction
1515
from collections import abc, Counter
1616

17+
18+
class MyIndex:
19+
def __init__(self, value):
20+
self.value = value
21+
22+
def __index__(self):
23+
return self.value
24+
25+
1726
class TestBasicOps:
1827
# Superclass with tests common to all generators.
1928
# Subclasses must arrange for self.gen to retrieve the Random instance
@@ -809,6 +818,9 @@ def test_getrandbits(self):
809818
self.gen.seed(1234567)
810819
self.assertEqual(self.gen.getrandbits(100),
811820
97904845777343510404718956115)
821+
self.gen.seed(1234567)
822+
self.assertEqual(self.gen.getrandbits(MyIndex(100)),
823+
97904845777343510404718956115)
812824

813825
def test_getrandbits_2G_bits(self):
814826
size = 2**31

0 commit comments

Comments
 (0)