MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_map_iterator

Function test_map_iterator

tests/test_sequences_and_iterators.py:211–232  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

209
210
211def test_map_iterator():
212 sm = m.StringMap({"hi": "bye", "black": "white"})
213 assert sm["hi"] == "bye"
214 assert len(sm) == 2
215 assert sm["black"] == "white"
216
217 with pytest.raises(KeyError):
218 assert sm["orange"]
219 sm["orange"] = "banana"
220 assert sm["orange"] == "banana"
221
222 expected = {"hi": "bye", "black": "white", "orange": "banana"}
223 for k in sm:
224 assert sm[k] == expected[k]
225 for k, v in sm.items():
226 assert v == expected[k]
227 assert list(sm.values()) == [expected[k] for k in sm]
228
229 it = iter(m.StringMap({}))
230 for _ in range(3): # __next__ must continue to raise StopIteration
231 with pytest.raises(StopIteration):
232 next(it)
233
234
235def test_python_iterator_in_cpp():

Callers

nothing calls this directly

Calls 6

lenFunction · 0.85
listClass · 0.85
iterFunction · 0.85
StringMapMethod · 0.80
valuesMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected