aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-08-01 20:22:13 +0600
committerSergey M․ <dstftw@gmail.com>2015-08-01 20:22:13 +0600
commitee114368ad0bb9822449295910263a99f9de4e1e (patch)
tree06a14cd6cbf2939f199fb80941f74c4a0841c48e /test
parent525a87f58ee9c4ee91b5b0384184dabf6d87eef3 (diff)
downloadyoutube-dl-ee114368ad0bb9822449295910263a99f9de4e1e.tar.xz
[utils] Make value optional for find_xpath_attr
This allows selecting particular attributes by name but without specifying the value and similar to xpath syntax `[@attrib]`
Diffstat (limited to 'test')
-rw-r--r--test/test_utils.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index 65692a9fb..a759b2da9 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -235,12 +235,21 @@ class TestUtil(unittest.TestCase):
<node x="a"/>
<node x="a" y="c" />
<node x="b" y="d" />
+ <node x="" />
</root>'''
doc = xml.etree.ElementTree.fromstring(testxml)
+ self.assertEqual(find_xpath_attr(doc, './/fourohfour', 'n'), None)
self.assertEqual(find_xpath_attr(doc, './/fourohfour', 'n', 'v'), None)
+ self.assertEqual(find_xpath_attr(doc, './/node', 'n'), None)
+ self.assertEqual(find_xpath_attr(doc, './/node', 'n', 'v'), None)
+ self.assertEqual(find_xpath_attr(doc, './/node', 'x'), doc[1])
self.assertEqual(find_xpath_attr(doc, './/node', 'x', 'a'), doc[1])
+ self.assertEqual(find_xpath_attr(doc, './/node', 'x', 'b'), doc[3])
+ self.assertEqual(find_xpath_attr(doc, './/node', 'y'), doc[2])
self.assertEqual(find_xpath_attr(doc, './/node', 'y', 'c'), doc[2])
+ self.assertEqual(find_xpath_attr(doc, './/node', 'y', 'd'), doc[3])
+ self.assertEqual(find_xpath_attr(doc, './/node', 'x', ''), doc[4])
def test_xpath_with_ns(self):
testxml = '''<root xmlns:media="http://example.com/">