def test_accessors(): from pybind11_tests import test_accessor_api, test_tuple_accessor, test_accessor_assignment class SubTestObject: attr_obj = 1 attr_char = 2 class TestObject: basic_attr = 1 begin_end = [1, 2, 3] d = {"operator[object]": 1, "operator[char *]": 2} sub = SubTestObject() def func(self, x, *args): return self.basic_attr + x + sum(args) d = test_accessor_api(TestObject()) assert d["basic_attr"] == 1 assert d["begin_end"] == [1, 2, 3] assert d["operator[object]"] == 1 assert d["operator[char *]"] == 2 assert d["attr(object)"] == 1 assert d["attr(char *)"] == 2 assert d["missing_attr_ptr"] == "raised" assert d["missing_attr_chain"] == "raised" assert d["is_none"] is False assert d["operator()"] == 2 assert d["operator*"] == 7 assert test_tuple_accessor(tuple()) == (0, 1, 2) d = test_accessor_assignment() assert d["get"] == 0 assert d["deferred_get"] == 0 assert d["set"] == 1 assert d["deferred_set"] == 1 assert d["var"] == 99
def test_accessors(): from pybind11_tests import test_accessor_api, test_tuple_accessor, test_accessor_assignment class SubTestObject: attr_obj = 1 attr_char = 2 class TestObject: basic_attr = 1 begin_end = [1, 2, 3] d = {"operator[object]": 1, "operator[char *]": 2} sub = SubTestObject() def func(self, x, *args): return self.basic_attr + x + sum(args) d = test_accessor_api(TestObject()) assert d["basic_attr"] == 1 assert d["begin_end"] == [1, 2, 3] assert d["operator[object]"] == 1 assert d["operator[char *]"] == 2 assert d["attr(object)"] == 1 assert d["attr(char *)"] == 2 assert d["missing_attr_ptr"] == "raised" assert d["missing_attr_chain"] == "raised" assert d["is_none"] is False assert d["operator()"] == 2 assert d["operator*"] == 7 assert test_tuple_accessor(tuple()) == (0, 1, 2) d = test_accessor_assignment() assert d["get"] == 0 assert d["deferred_get"] == 0 assert d["set"] == 1 assert d["deferred_set"] == 1 assert d["var"] == 99