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

Function test_map_string_double

tests/test_stl_binders.py:152–195  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150
151
152def test_map_string_double():
153 mm = m.MapStringDouble()
154 mm["a"] = 1
155 mm["b"] = 2.5
156
157 assert list(mm) == ["a", "b"]
158 assert str(mm) == "MapStringDouble{a: 1, b: 2.5}"
159 assert "b" in mm
160 assert "c" not in mm
161 assert 123 not in mm
162
163 # Check that keys, values, items are views, not merely iterable
164 keys = mm.keys()
165 values = mm.values()
166 items = mm.items()
167 assert list(keys) == ["a", "b"]
168 assert len(keys) == 2
169 assert "a" in keys
170 assert "c" not in keys
171 assert 123 not in keys
172 assert list(items) == [("a", 1), ("b", 2.5)]
173 assert len(items) == 2
174 assert ("b", 2.5) in items
175 assert "hello" not in items
176 assert ("b", 2.5, None) not in items
177 assert list(values) == [1, 2.5]
178 assert len(values) == 2
179 assert 1 in values
180 assert 2 not in values
181 # Check that views update when the map is updated
182 mm["c"] = -1
183 assert list(keys) == ["a", "b", "c"]
184 assert list(values) == [1, 2.5, -1]
185 assert list(items) == [("a", 1), ("b", 2.5), ("c", -1)]
186
187 um = m.UnorderedMapStringDouble()
188 um["ua"] = 1.1
189 um["ub"] = 2.6
190
191 assert sorted(um) == ["ua", "ub"]
192 assert list(um.keys()) == list(um)
193 assert sorted(um.items()) == [("ua", 1.1), ("ub", 2.6)]
194 assert list(zip(um.keys(), um.values())) == list(um.items())
195 assert "UnorderedMapStringDouble" in str(um)
196
197
198def test_map_string_double_const():

Callers

nothing calls this directly

Calls 5

listClass · 0.85
strClass · 0.85
lenFunction · 0.85
valuesMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected