示例#1
0
 def test_xpath_element(self):
     doc = xml.etree.ElementTree.Element('root')
     div = xml.etree.ElementTree.SubElement(doc, 'div')
     p = xml.etree.ElementTree.SubElement(div, 'p')
     p.text = 'Foo'
     self.assertEqual(xpath_element(doc, 'div/p'), p)
     self.assertEqual(xpath_element(doc, 'div/bar', default='default'), 'default')
     self.assertTrue(xpath_element(doc, 'div/bar') is None)
     self.assertRaises(ExtractorError, xpath_element, doc, 'div/bar', fatal=True)
示例#2
0
 def test_xpath_element(self):
     doc = xml.etree.ElementTree.Element('root')
     div = xml.etree.ElementTree.SubElement(doc, 'div')
     p = xml.etree.ElementTree.SubElement(div, 'p')
     p.text = 'Foo'
     self.assertEqual(xpath_element(doc, 'div/p'), p)
     self.assertEqual(xpath_element(doc, ['div/p']), p)
     self.assertEqual(xpath_element(doc, ['div/bar', 'div/p']), p)
     self.assertEqual(xpath_element(doc, 'div/bar', default='default'),
                      'default')
     self.assertEqual(xpath_element(doc, ['div/bar'], default='default'),
                      'default')
     self.assertTrue(xpath_element(doc, 'div/bar') is None)
     self.assertTrue(xpath_element(doc, ['div/bar']) is None)
     self.assertTrue(xpath_element(doc, ['div/bar'], 'div/baz') is None)
     self.assertRaises(ExtractorError,
                       xpath_element,
                       doc,
                       'div/bar',
                       fatal=True)
     self.assertRaises(ExtractorError,
                       xpath_element,
                       doc, ['div/bar'],
                       fatal=True)
     self.assertRaises(ExtractorError,
                       xpath_element,
                       doc, ['div/bar', 'div/baz'],
                       fatal=True)
示例#3
0
 def test_xpath_element(self):
     doc = xml.etree.ElementTree.Element("root")
     div = xml.etree.ElementTree.SubElement(doc, "div")
     p = xml.etree.ElementTree.SubElement(div, "p")
     p.text = "Foo"
     self.assertEqual(xpath_element(doc, "div/p"), p)
     self.assertEqual(xpath_element(doc, ["div/p"]), p)
     self.assertEqual(xpath_element(doc, ["div/bar", "div/p"]), p)
     self.assertEqual(xpath_element(doc, "div/bar", default="default"), "default")
     self.assertEqual(xpath_element(doc, ["div/bar"], default="default"), "default")
     self.assertTrue(xpath_element(doc, "div/bar") is None)
     self.assertTrue(xpath_element(doc, ["div/bar"]) is None)
     self.assertTrue(xpath_element(doc, ["div/bar"], "div/baz") is None)
     self.assertRaises(ExtractorError, xpath_element, doc, "div/bar", fatal=True)
     self.assertRaises(ExtractorError, xpath_element, doc, ["div/bar"], fatal=True)
     self.assertRaises(ExtractorError, xpath_element, doc, ["div/bar", "div/baz"], fatal=True)