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

Function test_map_delitem

tests/test_stl_binders.py:294–332  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

292
293
294def test_map_delitem():
295 mm = m.MapStringDouble()
296 mm["a"] = 1
297 mm["b"] = 2.5
298
299 assert list(mm) == ["a", "b"]
300 assert list(mm.items()) == [("a", 1), ("b", 2.5)]
301 del mm["a"]
302 assert list(mm) == ["b"]
303 assert list(mm.items()) == [("b", 2.5)]
304
305 with pytest.raises(KeyError) as excinfo:
306 mm["a_long_key"]
307 assert "a_long_key" in str(excinfo.value)
308
309 with pytest.raises(KeyError) as excinfo:
310 del mm["a_long_key"]
311 assert "a_long_key" in str(excinfo.value)
312
313 cut_length = 100
314 k_very_long = "ab" * cut_length + "xyz"
315 with pytest.raises(KeyError) as excinfo:
316 mm[k_very_long]
317 assert k_very_long in str(excinfo.value)
318 k_very_long += "@"
319 with pytest.raises(KeyError) as excinfo:
320 mm[k_very_long]
321 k_repr = k_very_long[:cut_length] + "✄✄✄" + k_very_long[-cut_length:]
322 assert k_repr in str(excinfo.value)
323
324 um = m.UnorderedMapStringDouble()
325 um["ua"] = 1.1
326 um["ub"] = 2.6
327
328 assert sorted(um) == ["ua", "ub"]
329 assert sorted(um.items()) == [("ua", 1.1), ("ub", 2.6)]
330 del um["ua"]
331 assert sorted(um) == ["ub"]
332 assert sorted(um.items()) == [("ub", 2.6)]
333
334
335def test_map_view_types():

Callers

nothing calls this directly

Calls 3

listClass · 0.85
strClass · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected