def test_init_with_queries(self): root = TemplateSelectNode(queries=[ Query(TemplateWordNode("subj"), TemplateWordNode("pred"), TemplateWordNode("obj")) ]) self.assertEqual(1, len(root.queries)) self.assertEqual(0, len(root.vars)) self.assertEqual( "<select><q><subj>subj</subj><pred>pred</pred><obj>obj</obj></q></select>", root.to_xml(self._client_context))
def test_tuples_no_tuples(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) select = TemplateSelectNode() self.assertIsNotNone(select) node = TemplateGetNode() node.name = TemplateWordNode("?x ?y") node.tuples = select root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("[GET [Tuples] - ([WORD]?x ?y)]", node.to_string()) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual( '<template><get var="?x ?y"><select /></get></template>', xml_str) result = root.resolve_to_string(self._client_context) self.assertEquals("unknown", result)
def test_node_default(self): root = TemplateNode() node = TemplateSelectNode() root.append(node) result = root.resolve(self._client_context) self.assertIsNotNone(result) self.assertEquals("", result)
def test_to_xml(self): root = TemplateNode() node = TemplateSelectNode() root.append(node) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual("<template><select /></template>", xml_str)
def test_node_default(self): root = TemplateNode() node = TemplateSelectNode() self.assertIsNotNone(node.query) self.assertIsInstance(node.query, RDFSelectStatement) root.append(node) result = root.resolve(self.bot, self.clientid) self.assertIsNotNone(result) self.assertEquals("", result)
def test_to_xml_vars(self): root = TemplateNode() node = TemplateSelectNode(vars=["?x", "?y"]) root.append(node) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual( "<template><select><vars>?x ?y</vars></select></template>", xml_str)
def test_to_xml_not_query(self): root = TemplateNode() not_query = NotQuery("subject", "predicate", "object") node = TemplateSelectNode(queries=[not_query]) root.append(node) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual( "<template><select><notq><subj>subject</subj><pred>predicate</pred><obj>object</obj></notq></select></template>", xml_str)
def test_tuples(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) select = TemplateSelectNode() self.assertIsNotNone(select) node = TemplateGetNode() node.name = TemplateWordNode("?x ?y") node.tuples = select root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("[GET [Tuples] - ([WORD]?x ?y)]", node.to_string()) xml = root.xml_tree(self.bot, self.clientid) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual('<template><get var="?x ?y"><select><vars /></select></get></template>', xml_str)
def __init__(self): TemplateSelectNode.__init__(self)
def test_to_string(self): root = TemplateSelectNode() self.assertIsNotNone(root) self.assertEquals("SELECT", root.to_string())
def test_init(self): root = TemplateSelectNode() self.assertEqual([], root.queries) self.assertEqual([], root.vars) self.assertEqual("<select></select>", root.to_xml(self._client_context))