add dict tests

This commit is contained in:
Taiju Yamada 2022-06-15 14:10:51 +09:00
parent 6fa2bb161e
commit bf238d91ed
2 changed files with 15 additions and 0 deletions

View File

@ -120,6 +120,18 @@ TEST_SUBMODULE(pytypes, m) {
[](const py::dict &dict, py::object val) { return dict.contains(val); });
m.def("dict_contains",
[](const py::dict &dict, const char *val) { return dict.contains(val); });
m.def("access_dict_with_str", []() {
py::dict d1 = py::dict();
d1["x"] = 1;
py::object d2 = d1;
return d2["x"];
});
m.def("access_dict_with_int", []() {
py::dict d1 = py::dict();
d1[1] = 1;
py::object d2 = d1;
return d2[1];
});
// test_tuple
m.def("tuple_no_args", []() { return py::tuple{}; });

View File

@ -146,6 +146,9 @@ def test_dict(capture, doc):
assert m.dict_keyword_constructor() == {"x": 1, "y": 2, "z": 3}
assert m.access_dict_with_str() == 1
assert m.access_dict_with_int() == 1
def test_tuple():
assert m.tuple_no_args() == ()