MCPcopy
hub / github.com/urllib3/urllib3 / test_disposal

Method test_disposal

test/test_collections.py:105–126  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

103 d[5]
104
105 def test_disposal(self) -> None:
106 evicted_items: list[int] = []
107
108 def dispose_func(arg: int) -> None:
109 # Save the evicted datum for inspection
110 evicted_items.append(arg)
111
112 d: Container[int, int] = Container(5, dispose_func=dispose_func)
113 for i in range(5):
114 d[i] = i
115 assert list(d._container.keys()) == list(range(5))
116 assert evicted_items == [] # Nothing disposed
117
118 d[5] = 5
119 assert list(d._container.keys()) == list(range(1, 6))
120 assert evicted_items == [0]
121
122 del d[1]
123 assert evicted_items == [0, 1]
124
125 d.clear()
126 assert evicted_items == [0, 1, 2, 3, 4, 5]
127
128 def test_iter(self) -> None:
129 d: Container[str, str] = Container()

Callers

nothing calls this directly

Calls 2

keysMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected