From bf238d91ed222c5ade504b3adec5789506cbbdb5 Mon Sep 17 00:00:00 2001 From: Taiju Yamada Date: Wed, 15 Jun 2022 14:10:51 +0900 Subject: [PATCH] add dict tests --- tests/test_pytypes.cpp | 12 ++++++++++++ tests/test_pytypes.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 196114745..741a0b53c 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -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{}; }); diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 760f6236d..f63134c0c 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -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() == ()