| 1875 | self.assertEqual(sys.getsizeof(obj), expected) |
| 1876 | |
| 1877 | def test_slots(self): |
| 1878 | # check all subclassable types defined in Objects/ that allow |
| 1879 | # non-empty __slots__ |
| 1880 | check = self.check_slots |
| 1881 | class BA(bytearray): |
| 1882 | __slots__ = 'a', 'b', 'c' |
| 1883 | check(BA(), bytearray(), '3P') |
| 1884 | class D(dict): |
| 1885 | __slots__ = 'a', 'b', 'c' |
| 1886 | check(D(x=[]), {'x': []}, '3P') |
| 1887 | class L(list): |
| 1888 | __slots__ = 'a', 'b', 'c' |
| 1889 | check(L(), [], '3P') |
| 1890 | class S(set): |
| 1891 | __slots__ = 'a', 'b', 'c' |
| 1892 | check(S(), set(), '3P') |
| 1893 | class FS(frozenset): |
| 1894 | __slots__ = 'a', 'b', 'c' |
| 1895 | |
| 1896 | class mytuple(tuple): |
| 1897 | pass |
| 1898 | check(FS([mytuple()]), frozenset([mytuple()]), '3P') |
| 1899 | from collections import OrderedDict |
| 1900 | class OD(OrderedDict): |
| 1901 | __slots__ = 'a', 'b', 'c' |
| 1902 | check(OD(x=[]), OrderedDict(x=[]), '3P') |
| 1903 | |
| 1904 | def test_pythontypes(self): |
| 1905 | # check all types defined in Python/ |