本文整理汇总了Python中twisted.words.xish.xpath.XPathQuery类的典型用法代码示例。如果您正苦于以下问题:Python XPathQuery类的具体用法?Python XPathQuery怎么用?Python XPathQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XPathQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_orOperator
def test_orOperator(self):
"""
Test boolean or operator in condition.
"""
xp = XPathQuery("//bar[@attrib5='value4' or @attrib5='value5']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar5, self.bar6])
示例2: test_attributeWithValueAny
def test_attributeWithValueAny(self):
"""
Test find nodes with attribute having value.
"""
xp = XPathQuery("/foo/*[@attrib2='value2']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar2])
示例3: test_locationFooBarFoo
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])
示例4: test_queryForStringListAnyLocation
def test_queryForStringListAnyLocation(self):
"""
queryforStringList on relative paths returns all their CDATA.
"""
xp = XPathQuery("//foo")
self.assertEqual(xp.queryForStringList(self.e),
["somecontent", "somemorecontent"])
示例5: test_queryForString
def test_queryForString(self):
"""
Test for queryForString and queryForStringList.
"""
xp = XPathQuery("/foo")
self.assertEquals(xp.queryForString(self.e), "somecontent")
self.assertEquals(xp.queryForStringList(self.e), ["somecontent", "somemorecontent"])
示例6: test_position
def test_position(self):
"""
Test finding element at position.
"""
xp = XPathQuery("/foo/bar[2]")
self.assertEqual(xp.matches(self.e), 1)
self.assertEqual(xp.queryForNodes(self.e), [self.bar1])
示例7: test_locationAllChilds
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])
示例8: test_textConditionUnicode
def test_textConditionUnicode(self):
"""
A node can be matched by text with non-ascii code points.
"""
xp = XPathQuery(u"//*[text()='\N{SNOWMAN}']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.quux])
示例9: test_andOperator
def test_andOperator(self):
"""
Test boolean and operator in condition.
"""
xp = XPathQuery("//bar[@attrib4='value4' and @attrib5='value5']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar5])
示例10: test_locationWithValueUnicode
def test_locationWithValueUnicode(self):
"""
Nodes' attributes can be matched with non-ASCII values.
"""
xp = XPathQuery(u"/foo/*[@attrib6='á']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar7])
示例11: test_anyLocationAndText
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"])
示例12: test_booleanOperatorsParens
def test_booleanOperatorsParens(self):
"""
Test multiple boolean operators in condition with parens.
"""
xp = XPathQuery("""//bar[@attrib4='value4' and
(@attrib5='value4' or @attrib5='value6')]""")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar6, self.bar7])
示例13: test_queryForNodes
def test_queryForNodes(self):
"""
Test finding nodes.
"""
xp = XPathQuery("/foo/bar")
self.assertEqual(xp.queryForNodes(self.e), [self.bar1, self.bar2,
self.bar4, self.bar5,
self.bar6, self.bar7])
示例14: test_anyLocation
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]
)
示例15: test_textNotOperator
def test_textNotOperator(self):
"""
Test for not operator.
"""
xp = XPathQuery("/foo[not(@nosuchattrib)]")
self.assertEqual(xp.matches(self.e), True)