From 94b9cd980a6907bcc183542d0ad1cb291c2efdf8 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Thu, 11 Jul 2024 14:46:36 +0200 Subject: [PATCH] Added minor tests --- aidge_core/unit_tests/test_operator_binding.py | 17 +++++++++++++++++ python_binding/utils/pybind_Attributes.cpp | 1 + 2 files changed, 18 insertions(+) diff --git a/aidge_core/unit_tests/test_operator_binding.py b/aidge_core/unit_tests/test_operator_binding.py index 384a82de8..8d6f2686d 100644 --- a/aidge_core/unit_tests/test_operator_binding.py +++ b/aidge_core/unit_tests/test_operator_binding.py @@ -100,6 +100,23 @@ class test_operator_binding(unittest.TestCase): attrs.d = 23.89 self.assertEqual(aidge_core.test_DynamicAttributes_binding_check(attrs), 23.89) + op = aidge_core.GenericOperatorOp("any_type", 1,0,1) + with self.assertRaises(RuntimeError): + op.attr.something + + op.attr.something = aidge_core.DynamicAttributes() + try: + self.assertEqual(str(op.attr), "AttrDict({'something': AttrDict({})})") + except Exception: + self.fail("op.attr.something raised Exception unexpectedly!") + + op.attr.something.arg1 = 4 + self.assertEqual(op.attr.something.arg1, 4) + + # auto create the namespace another_thing (not enabled) + #op.attr.another_thing.arg = 44 + #self.assertEqual(op.attr.another_thing.arg, 44) + def test_forward_dims(self): in_dims=[25, 25] input = aidge_core.Producer(in_dims, name="In") diff --git a/python_binding/utils/pybind_Attributes.cpp b/python_binding/utils/pybind_Attributes.cpp index 135ebb48e..bc0ccb3f4 100644 --- a/python_binding/utils/pybind_Attributes.cpp +++ b/python_binding/utils/pybind_Attributes.cpp @@ -47,6 +47,7 @@ void init_Attributes(py::module& m){ py::class_<DynamicAttributes, std::shared_ptr<DynamicAttributes>, Attributes>(m, "DynamicAttributes") + .def(py::init<>()) .def("add_attr", &DynamicAttributes::addAttrPy, py::arg("name"), py::arg("value")) .def("del_attr", &DynamicAttributes::delAttr, py::arg("name")); -- GitLab