summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorThomas Christlieb <[email protected]>2017-02-11 10:16:54 +0100
committerSergey M <[email protected]>2017-02-11 17:16:54 +0800
commit2af12ad9d2c3e41d0e91fe6e2f35827469d587bf (patch)
tree10a9f3ac350b00538df8ba710af8ca6f68145040 /test
parent97eb9bd2acffd352558b626f923862d039efbcb7 (diff)
downloadyoutube-dl-2af12ad9d2c3e41d0e91fe6e2f35827469d587bf.tar.gz
youtube-dl-2af12ad9d2c3e41d0e91fe6e2f35827469d587bf.zip
Introduce get_elements_by_class and get_elements_by_attribute utility functions
Diffstat (limited to 'test')
-rw-r--r--test/test_utils.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index edc712f07..3cdb21d40 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -34,6 +34,9 @@ from youtube_dl.utils import (
find_xpath_attr,
fix_xml_ampersands,
get_element_by_class,
+ get_element_by_attribute,
+ get_elements_by_class,
+ get_elements_by_attribute,
InAdvancePagedList,
intlist_to_bytes,
is_html,
@@ -1124,6 +1127,32 @@ The first line
self.assertEqual(get_element_by_class('foo', html), 'nice')
self.assertEqual(get_element_by_class('no-such-class', html), None)
+ def test_get_element_by_attribute(self):
+ html = '''
+ <span class="foo bar">nice</span>
+ '''
+
+ self.assertEqual(get_element_by_attribute('class', 'foo bar', html), 'nice')
+ self.assertEqual(get_element_by_attribute('class', 'foo', html), None)
+ self.assertEqual(get_element_by_attribute('class', 'no-such-foo', html), None)
+
+ def test_get_elements_by_class(self):
+ html = '''
+ <span class="foo bar">nice</span><span class="foo bar">also nice</span>
+ '''
+
+ self.assertEqual(get_elements_by_class('foo', html), ['nice', 'also nice'])
+ self.assertEqual(get_elements_by_class('no-such-class', html), [])
+
+ def test_get_elements_by_attribute(self):
+ html = '''
+ <span class="foo bar">nice</span><span class="foo bar">also nice</span>
+ '''
+
+ self.assertEqual(get_elements_by_attribute('class', 'foo bar', html), ['nice', 'also nice'])
+ self.assertEqual(get_elements_by_attribute('class', 'foo', html), [])
+ self.assertEqual(get_elements_by_attribute('class', 'no-such-foo', html), [])
+
if __name__ == '__main__':
unittest.main()