mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-24 14:15:11 +00:00
add dict tests
This commit is contained in:
parent
6fa2bb161e
commit
bf238d91ed
@ -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{}; });
|
||||
|
@ -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() == ()
|
||||
|
Loading…
Reference in New Issue
Block a user