diff options
author | Sergey M․ <dstftw@gmail.com> | 2019-03-23 01:08:54 +0700 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2019-03-23 01:08:54 +0700 |
commit | 5e1271c56dbf3f96fbf928ccd3facf5fc70493b4 (patch) | |
tree | 739bb713f329e5f28a475b1dfca459d80881c453 /test/test_utils.py | |
parent | 050afa60c6685f0b0aff68d943d48b3b6b9c85a0 (diff) |
[utils] Improve int_or_none and float_or_none (#20403)
Diffstat (limited to 'test/test_utils.py')
-rw-r--r-- | test/test_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index acd994bd7..ca6d832a4 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -33,11 +33,13 @@ from youtube_dl.utils import ( ExtractorError, find_xpath_attr, fix_xml_ampersands, + float_or_none, get_element_by_class, get_element_by_attribute, get_elements_by_class, get_elements_by_attribute, InAdvancePagedList, + int_or_none, intlist_to_bytes, is_html, js_to_json, @@ -468,6 +470,21 @@ class TestUtil(unittest.TestCase): shell_quote(args), """ffmpeg -i 'ñ€ß'"'"'.mp4'""" if compat_os_name != 'nt' else '''ffmpeg -i "ñ€ß'.mp4"''') + def test_float_or_none(self): + self.assertEqual(float_or_none('42.42'), 42.42) + self.assertEqual(float_or_none('42'), 42.0) + self.assertEqual(float_or_none(''), None) + self.assertEqual(float_or_none(None), None) + self.assertEqual(float_or_none([]), None) + self.assertEqual(float_or_none(set()), None) + + def test_int_or_none(self): + self.assertEqual(int_or_none('42'), 42) + self.assertEqual(int_or_none(''), None) + self.assertEqual(int_or_none(None), None) + self.assertEqual(int_or_none([]), None) + self.assertEqual(int_or_none(set()), None) + def test_str_to_int(self): self.assertEqual(str_to_int('123,456'), 123456) self.assertEqual(str_to_int('123.456'), 123456) |