def test_meta() -> None: meta = ParameterMeta(param_name, StringEnumPlugin.type_name()) StringEnumPlugin.meta( meta, TestObject.action, find_function(TestObject.action.__name__, parse_def(TestObject))) assert meta.extra extra = IntegerEnumExtra.from_json(meta.extra) assert extra.allowed_values == TestEnum.set()
def built_in_types_data() -> ObjectTypeDict: ret: ObjectTypeDict = {} # built-in object types / services for _, type_def in built_in_types(): assert issubclass(type_def, Generic) ast = parse_def(type_def) d = ObjectTypeData(meta_from_def(type_def, built_in=True), type_def, object_actions(type_def, ast), ast) ret[d.meta.type] = d return ret
def test_object_actions() -> None: actions = object_actions(TestObject, parse_def(TestObject)) assert len(actions) == 2 for act in actions.values(): if act.name == TestObject.action_1.__name__: expected_meta = ActionMetadata(blocking=True) expected_meta.cancellable = True assert act.meta == expected_meta assert not act.returns assert act.description == "Short description." assert not act.disabled assert act.origins is None assert len(act.parameters) == 3 for param in act.parameters: if param.name == "param1": assert param.description == "str param" elif param.name == "param2": assert param.description == "int param" elif param.name == "param3": assert param.description == "bool param" else: pytest.fail( f"Unknown parameter: {param.name} of action {act.name}." ) elif act.name == TestObject.action_2.__name__: assert act.meta == ActionMetadata() assert len(act.returns) == 1 assert act.description == "Short description" assert not act.disabled assert act.origins is None assert not act.parameters else: pytest.fail(f"Unknown action: {act.name}.")
def func_4(self, param: int) -> bool: """Exceptions different from Arcor2NotImplemented are ok. :param param: :return: """ if param == 1: raise Exception("Exception!") return True def func_5(self) -> None: raise Arcor2NotImplemented def func_6(self) -> None: raise Arcor2NotImplemented(1) module_tree = parse_def(TestType) def test_function_implemented(): assert function_implemented(module_tree, TestType.func_1.__name__) assert not function_implemented(module_tree, TestType.func_2.__name__) assert not function_implemented(module_tree, TestType.func_3.__name__) assert function_implemented(module_tree, TestType.func_4.__name__) assert not function_implemented(module_tree, TestType.func_5.__name__) assert not function_implemented(module_tree, TestType.func_6.__name__)