def decodeParam(p): if isinstance(p, str): v = json_loads_byteified(p) else: v = p if len(v['values']) > 0: return param.Param(v['key'], v['description'], decode(v['values'], v['type']), v['specType']) else: return param.Param(v['key'], v['description'], getTypeFromStr(v['type']).__class__, v['specType'])
def test_serialize_ParamMap(self): ph = param.ParamHandler() ph.addParam("MyDict", dict, param.ParamTypes.Required) s_param_map = utils.serializeParamMap(ph._params) self.assertSameItems(s_param_map_strings[0], str(s_param_map)) ph.addParam("MyList", list, param.ParamTypes.Required) s_param_map = utils.serializeParamMap(ph._params) self.assertSameItems(s_param_map_strings[1], str(s_param_map)) params = {} params["MyDict"] = param.Param("MyDict", "", dict, param.ParamTypes.Required) s_param_map = utils.serializeParamMap(params) self.assertSameItems(s_param_map_strings[0], str(s_param_map)) params = {} params["MyString"] = param.Param("MyString", "", "String", param.ParamTypes.Required) s_param_map = utils.serializeParamMap(params) self.assertSameItems(s_param_map_strings[2], str(s_param_map))
def test_toElement(self): p = params.Param("MyProp", "", 0, params.ParamTypes.Required) element = p.toElement() self.assertEqual(int, element.getProperty("skiros:DataType").dataType()) self.assertEqual([0], element.getProperty("skiros:Default").values) self.assertEqual([0], element.getProperty("skiros:Value").values) e = we.Element("MyType", eid="1") p = params.Param("MyElement", "", e, params.ParamTypes.Required) element = p.toElement() self.assertEqual(["MyType"], element.getProperty("skiros:DataType").values) expected = { "src": "-1", "dst": "1", "type": "skiros:hasValue", "state": True, "abstract": False } self.assertEqual(expected, element.getRelation("-1", "skiros:hasValue", "1"))
def test_hasChanges(self): p = params.Param("MyProp", "", 0, params.ParamTypes.Required) self.assertEqual(0, p.value) msg = """ hasChanges should return False if Parameter has not changed recently""" t = p.last_update self.assertEqual(False, p.hasChanges(t), msg) msg = """ hasChanges should return True if Parameter has changed recently""" p.value = 1 self.assertEqual(True, p.hasChanges(t), msg)