summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYen Chi Hsuan <[email protected]>2016-02-27 03:19:50 +0800
committerYen Chi Hsuan <[email protected]>2016-02-27 03:22:52 +0800
commit5eb6bdced4765cdeb70411c6aa93ecb4163a9ffe (patch)
tree48d5ee30bd44b7d2fe637cea2fbb90dabda3c4f6 /test
parent5633b4d39d178402c6d89146c8c9c34e3bf58619 (diff)
downloadyoutube-dl-5eb6bdced4765cdeb70411c6aa93ecb4163a9ffe.tar.gz
youtube-dl-5eb6bdced4765cdeb70411c6aa93ecb4163a9ffe.zip
[utils] Multiple changes to base_n()
1. Renamed to encode_base_n() 2. Allow tables longer than 62 characters 3. Raise ValueError instead of AssertionError for invalid input data 4. Return the first character in the table instead of '0' for number 0 5. Add tests
Diffstat (limited to 'test')
-rw-r--r--test/test_utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index d0736f435..97587ad2f 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -18,6 +18,7 @@ import xml.etree.ElementTree
from youtube_dl.utils import (
age_restricted,
args_to_str,
+ encode_base_n,
clean_html,
DateRange,
detect_exe_version,
@@ -802,5 +803,16 @@ The first line
ohdave_rsa_encrypt(b'aa111222', e, N),
'726664bd9a23fd0c70f9f1b84aab5e3905ce1e45a584e9cbcf9bcc7510338fc1986d6c599ff990d923aa43c51c0d9013cd572e13bc58f4ae48f2ed8c0b0ba881')
+ def test_encode_base_n(self):
+ self.assertEqual(encode_base_n(0, 30), '0')
+ self.assertEqual(encode_base_n(80, 30), '2k')
+
+ custom_table = '9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA'
+ self.assertEqual(encode_base_n(0, 30, custom_table), '9')
+ self.assertEqual(encode_base_n(80, 30, custom_table), '7P')
+
+ self.assertRaises(ValueError, encode_base_n, 0, 70)
+ self.assertRaises(ValueError, encode_base_n, 0, 60, custom_table)
+
if __name__ == '__main__':
unittest.main()