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

Method test_slots

Lib/test/test_sys.py:1877–1902  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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/

Callers

nothing calls this directly

Calls 10

OrderedDictClass · 0.90
BAClass · 0.85
setFunction · 0.85
FSClass · 0.85
mytupleClass · 0.85
ODClass · 0.85
checkFunction · 0.70
DClass · 0.70
LClass · 0.70
SClass · 0.70

Tested by

no test coverage detected