def test_getElementParams(self): ph1 = self.ph1 e1 = we.Element("Type1") e2 = we.Element("Type2") ph1.addParam("e1", e1, params.ParamTypes.Optional) ph1.addParam("e2", e2, params.ParamTypes.Optional) elements = {k: v.value for k, v in ph1.getElementParams().items()} self.assertEqual({"e1": e1, "e2": e2}, elements)
def decodeElement(json_string): # TODO json_string['last_update'] e = we.Element(json_string['type'], json_string['label'], json_string['id']) for k, p in json_string['properties'].iteritems(): e._properties[k] = decodeProperty(p) e._relations = json_string['relations'] return e
def msg2element(msg): e = we.Element() e._id = msg.id e._label = msg.label e._type = msg.type e._properties = deserializePropertyMap(msg.properties) for r in msg.relations: e.addRelation(r.subjectId, r.predicate, r.objectId) return e
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"))