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

Method test_long_asdouble

Lib/test/test_capi/test_long.py:285–303  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

283 self.check_long_asint(as_size_t, 0, SIZE_MAX, use_index=False)
284
285 def test_long_asdouble(self):
286 # Test PyLong_AsDouble()
287 asdouble = _testlimitedcapi.pylong_asdouble
288 MAX = int(sys.float_info.max)
289 for value in (-MAX, MAX, -1, 0, 1, 1234):
290 with self.subTest(value=value):
291 self.assertEqual(asdouble(value), float(value))
292 self.assertIsInstance(asdouble(value), float)
293
294 self.assertEqual(asdouble(IntSubclass(42)), 42.0)
295 self.assertRaises(TypeError, asdouble, Index(42))
296 self.assertRaises(TypeError, asdouble, MyIndexAndInt())
297
298 self.assertRaises(OverflowError, asdouble, 2 * MAX)
299 self.assertRaises(OverflowError, asdouble, -2 * MAX)
300 self.assertRaises(TypeError, asdouble, 1.0)
301 self.assertRaises(TypeError, asdouble, b'2')
302 self.assertRaises(TypeError, asdouble, '3')
303 self.assertRaises(SystemError, asdouble, NULL)
304
305 def test_long_asvoidptr(self):
306 # Test PyLong_AsVoidPtr()

Callers

nothing calls this directly

Calls 7

MyIndexAndIntClass · 0.85
assertIsInstanceMethod · 0.80
IntSubclassClass · 0.70
IndexClass · 0.70
subTestMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected