def test_position(self): """ Test finding element at position. """ xp = XPathQuery("/foo/bar[2]") self.assertEquals(xp.matches(self.e), 1) self.assertEquals(xp.queryForNodes(self.e), [self.bar1])
def test_attributeWithValueAny(self): """ Test find nodes with attribute having value. """ xp = XPathQuery("/foo/*[@attrib2='value2']") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [self.bar2])
def test_orOperator(self): """ Test boolean or operator in condition. """ xp = XPathQuery("//bar[@attrib5='value4' or @attrib5='value5']") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [self.bar5, self.bar6])
def test_booleanOperatorsParens(self): """ Test multiple boolean operators in condition with parens. """ xp = XPathQuery("""//bar[@attrib4='value4' and (@attrib5='value4' or @attrib5='value6')]""") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [self.bar6, self.bar7])
def test_queryForNodes(self): """ Test finding nodes. """ xp = XPathQuery("/foo/bar") self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
def test_queryForNodes(self): """ Test finding nodes. """ xp = XPathQuery("/foo/bar") self.assertEquals( xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
def test_locationFooBarFoo(self): """ Test finding foos at the second level. """ xp = XPathQuery("/foo/bar/foo") self.assertEquals(xp.matches(self.e), 1) self.assertEquals(xp.queryForNodes(self.e), [self.subfoo, self.subfoo3, self.subfoo4])
def test_locationAllChilds(self): """ Test finding childs of foo. """ xp = XPathQuery("/foo/*") self.assertEquals(xp.matches(self.e), True) self.assertEquals( xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
def test_locationAllChilds(self): """ Test finding childs of foo. """ xp = XPathQuery("/foo/*") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
def test_anyLocationAndText(self): """ Test finding any nodes named gar and getting their text contents. """ xp = XPathQuery("//gar") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [self.gar1, self.gar2, self.gar3, self.gar4]) self.assertEquals(xp.queryForStringList(self.e), ["DEF", "ABC", "JKL", "MNO"])
def test_anyLocation(self): """ Test finding any nodes named bar. """ xp = XPathQuery("//bar") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [ self.bar1, self.bar2, self.bar3, self.bar4, self.bar5, self.bar6, self.bar7 ])
def test_anyLocation(self): """ Test finding any nodes named bar. """ xp = XPathQuery("//bar") self.assertEquals(xp.matches(self.e), True) self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar3, self.bar4, self.bar5, self.bar6, self.bar7])