X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=test%2Ftest_utils.py;h=e4e8d382518874378b003e2a73dd546ab32c4ab7;hb=d890b4cc0ac6b88daa917a1a791afe7541cd0411;hp=032d3656ae21ec733a11d946e52693ebd560af16;hpb=f943b7ddce1a426c9168cf0d8bd47e539fc17694;p=youtube-dl
diff --git a/test/test_utils.py b/test/test_utils.py
index 032d3656a..e4e8d3825 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -21,6 +21,7 @@ from youtube_dl.utils import (
clean_html,
DateRange,
detect_exe_version,
+ determine_ext,
encodeFilename,
escape_rfc3986,
escape_url,
@@ -40,9 +41,9 @@ from youtube_dl.utils import (
read_batch_urls,
sanitize_filename,
sanitize_path,
- sanitize_url_path_consecutive_slashes,
prepend_extension,
replace_extension,
+ remove_quotes,
shell_quote,
smuggle_url,
str_to_int,
@@ -58,11 +59,19 @@ from youtube_dl.utils import (
urlencode_postdata,
version_tuple,
xpath_with_ns,
+ xpath_element,
xpath_text,
+ xpath_attr,
render_table,
match_str,
parse_dfxp_time_expr,
dfxp2srt,
+ cli_option,
+ cli_valueless_option,
+ cli_bool_option,
+)
+from youtube_dl.compat import (
+ compat_etree_fromstring,
)
@@ -176,26 +185,6 @@ class TestUtil(unittest.TestCase):
self.assertEqual(sanitize_path('./abc'), 'abc')
self.assertEqual(sanitize_path('./../abc'), '..\\abc')
- def test_sanitize_url_path_consecutive_slashes(self):
- self.assertEqual(
- sanitize_url_path_consecutive_slashes('http://hostname/foo//bar/filename.html'),
- 'http://hostname/foo/bar/filename.html')
- self.assertEqual(
- sanitize_url_path_consecutive_slashes('http://hostname//foo/bar/filename.html'),
- 'http://hostname/foo/bar/filename.html')
- self.assertEqual(
- sanitize_url_path_consecutive_slashes('http://hostname//'),
- 'http://hostname/')
- self.assertEqual(
- sanitize_url_path_consecutive_slashes('http://hostname/foo/bar/filename.html'),
- 'http://hostname/foo/bar/filename.html')
- self.assertEqual(
- sanitize_url_path_consecutive_slashes('http://hostname/'),
- 'http://hostname/')
- self.assertEqual(
- sanitize_url_path_consecutive_slashes('http://hostname/abc//'),
- 'http://hostname/abc/')
-
def test_prepend_extension(self):
self.assertEqual(prepend_extension('abc.ext', 'temp'), 'abc.temp.ext')
self.assertEqual(prepend_extension('abc.ext', 'temp', 'ext'), 'abc.temp.ext')
@@ -212,6 +201,15 @@ class TestUtil(unittest.TestCase):
self.assertEqual(replace_extension('.abc', 'temp'), '.abc.temp')
self.assertEqual(replace_extension('.abc.ext', 'temp'), '.abc.temp')
+ def test_remove_quotes(self):
+ self.assertEqual(remove_quotes(None), None)
+ self.assertEqual(remove_quotes('"'), '"')
+ self.assertEqual(remove_quotes("'"), "'")
+ self.assertEqual(remove_quotes(';'), ';')
+ self.assertEqual(remove_quotes('";'), '";')
+ self.assertEqual(remove_quotes('""'), '')
+ self.assertEqual(remove_quotes('";"'), ';')
+
def test_ordered_set(self):
self.assertEqual(orderedSet([1, 1, 2, 3, 4, 4, 5, 6, 7, 3, 5]), [1, 2, 3, 4, 5, 6, 7])
self.assertEqual(orderedSet([]), [])
@@ -223,8 +221,8 @@ class TestUtil(unittest.TestCase):
self.assertEqual(unescapeHTML('%20;'), '%20;')
self.assertEqual(unescapeHTML('/'), '/')
self.assertEqual(unescapeHTML('/'), '/')
- self.assertEqual(
- unescapeHTML('é'), 'é')
+ self.assertEqual(unescapeHTML('é'), 'é')
+ self.assertEqual(unescapeHTML(''), '')
def test_daterange(self):
_20century = DateRange("19000101", "20000101")
@@ -249,6 +247,14 @@ class TestUtil(unittest.TestCase):
unified_strdate('2/2/2015 6:47:40 PM', day_first=False),
'20150202')
self.assertEqual(unified_strdate('25-09-2014'), '20140925')
+ self.assertEqual(unified_strdate('UNKNOWN DATE FORMAT'), None)
+
+ def test_determine_ext(self):
+ self.assertEqual(determine_ext('http://example.com/foo/bar.mp4/?download'), 'mp4')
+ self.assertEqual(determine_ext('http://example.com/foo/bar/?download', None), None)
+ self.assertEqual(determine_ext('http://example.com/foo/bar.nonext/?download', None), None)
+ self.assertEqual(determine_ext('http://example.com/foo/bar/mp4?download', None), None)
+ self.assertEqual(determine_ext('http://example.com/foo/bar.m3u8//?download'), 'm3u8')
def test_find_xpath_attr(self):
testxml = ''' Foo Foo
The following line contains Chinese characters and special symbols
第äºè¡
âªâª
Third
Line
Third
Line
Lines with invalid timestamps are ignored
+Ignore, two
+Ignored, three