コード例 #1
0
ファイル: test_utils.py プロジェクト: hakatashi/youtube-dl
 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
ファイル: test_utils.py プロジェクト: nyuszika7h/youtube-dl
 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)