MCPcopy Index your code
hub / github.com/RustPython/RustPython / test___sizeof__

Method test___sizeof__

Lib/test/test_long.py:1664–1703  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1662
1663 @unittest.expectedFailure # TODO: RUSTPYTHON
1664 def test___sizeof__(self):
1665 self.assertEqual(int.__itemsize__, sys.int_info.sizeof_digit)
1666
1667 # Pairs (test_value, number of allocated digits)
1668 test_values = [
1669 # We always allocate space for at least one digit, even for
1670 # a value of zero; sys.getsizeof should reflect that.
1671 (0, 1),
1672 (1, 1),
1673 (-1, 1),
1674 (BASE-1, 1),
1675 (1-BASE, 1),
1676 (BASE, 2),
1677 (-BASE, 2),
1678 (BASE*BASE - 1, 2),
1679 (BASE*BASE, 3),
1680 ]
1681
1682 for value, ndigits in test_values:
1683 with self.subTest(value):
1684 self.assertEqual(
1685 value.__sizeof__(),
1686 int.__basicsize__ + int.__itemsize__ * ndigits
1687 )
1688
1689 # Same test for a subclass of int.
1690 class MyInt(int):
1691 pass
1692
1693 self.assertEqual(MyInt.__itemsize__, sys.int_info.sizeof_digit)
1694
1695 for value, ndigits in test_values:
1696 with self.subTest(value):
1697 self.assertEqual(
1698 MyInt(value).__sizeof__(),
1699 MyInt.__basicsize__ + MyInt.__itemsize__ * ndigits
1700 )
1701
1702 # GH-117195 -- This shouldn't crash
1703 object.__sizeof__(1)
1704
1705 def test_hash(self):
1706 # gh-136599

Callers

nothing calls this directly

Calls 4

subTestMethod · 0.80
MyIntClass · 0.70
assertEqualMethod · 0.45
__sizeof__Method · 0.45

Tested by

no test coverage detected