MCPcopy Index your code
hub / github.com/python/cpython / test_choice_with_numpy

Method test_choice_with_numpy

Lib/test/test_random.py:126–139  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

124 self.assertIn(choice([25, 75]), [25, 75])
125
126 def test_choice_with_numpy(self):
127 # Accommodation for NumPy arrays which have disabled __bool__().
128 # See: https://github.com/python/cpython/issues/100805
129 choice = self.gen.choice
130
131 class NA(list):
132 "Simulate numpy.array() behavior"
133 def __bool__(self):
134 raise RuntimeError
135
136 with self.assertRaises(IndexError):
137 choice(NA([]))
138 self.assertEqual(choice(NA([50])), 50)
139 self.assertIn(choice(NA([25, 75])), [25, 75])
140
141 def test_sample(self):
142 # For the entire allowable range of 0 <= k <= N, validate that

Callers

nothing calls this directly

Calls 5

choiceFunction · 0.85
NAClass · 0.85
assertInMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected