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

Method check_long_asint

Lib/test/test_capi/test_long.py:166–200  ·  view source on GitHub ↗
(self, func, min_val, max_val, *,
                         use_index=True,
                         mask=False,
                         negative_value_error=OverflowError)

Source from the content-addressed store, hash-verified

164 # CRASHES fromunicodeobject(NULL, 16)
165
166 def check_long_asint(self, func, min_val, max_val, *,
167 use_index=True,
168 mask=False,
169 negative_value_error=OverflowError):
170 # round trip (object -> C integer -> object)
171 values = (0, 1, 512, 1234, max_val)
172 if min_val < 0:
173 values += (-1, -512, -1234, min_val)
174 for value in values:
175 with self.subTest(value=value):
176 self.assertEqual(func(value), value)
177 self.assertEqual(func(IntSubclass(value)), value)
178 if use_index:
179 self.assertEqual(func(Index(value)), value)
180
181 if use_index:
182 self.assertEqual(func(MyIndexAndInt()), 10)
183 else:
184 self.assertRaises(TypeError, func, Index(42))
185 self.assertRaises(TypeError, func, MyIndexAndInt())
186
187 if mask:
188 self.assertEqual(func(min_val - 1), max_val)
189 self.assertEqual(func(max_val + 1), min_val)
190 self.assertEqual(func(-1 << 1000), 0)
191 self.assertEqual(func(1 << 1000), 0)
192 else:
193 self.assertRaises(negative_value_error, func, min_val - 1)
194 self.assertRaises(negative_value_error, func, -1 << 1000)
195 self.assertRaises(OverflowError, func, max_val + 1)
196 self.assertRaises(OverflowError, func, 1 << 1000)
197 self.assertRaises(TypeError, func, 1.0)
198 self.assertRaises(TypeError, func, b'2')
199 self.assertRaises(TypeError, func, '3')
200 self.assertRaises(SystemError, func, NULL)
201
202 def check_long_asintandoverflow(self, func, min_val, max_val):
203 # round trip (object -> C integer -> object)

Callers 14

test_long_asintMethod · 0.95
test_long_aslongMethod · 0.95
test_long_aslonglongMethod · 0.95
test_long_as_ssize_tMethod · 0.95
test_long_as_size_tMethod · 0.95
_test_long_aspidMethod · 0.95
test_long_asint32Method · 0.95
test_long_asint64Method · 0.95

Calls 7

MyIndexAndIntClass · 0.85
IntSubclassClass · 0.70
IndexClass · 0.70
funcFunction · 0.50
subTestMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected