diff options
author | Sergey M․ <[email protected]> | 2016-02-07 06:12:53 +0600 |
---|---|---|
committer | Sergey M․ <[email protected]> | 2016-02-07 06:12:53 +0600 |
commit | cbecc9b9039d5166185a41ca4d9d6c4d11595c52 (patch) | |
tree | bc0fc97d71af4a36b5deb236f7e957240ea9efa0 /test | |
parent | b8b465af3e83fb19c1818c2fa83f0c5f753dd917 (diff) | |
download | youtube-dl-cbecc9b9039d5166185a41ca4d9d6c4d11595c52.tar.gz youtube-dl-cbecc9b9039d5166185a41ca4d9d6c4d11595c52.zip |
[utils] Add dict_get convenience method
Diffstat (limited to 'test')
-rw-r--r-- | test/test_utils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index 1c3290d9b..e3dd019af 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -22,6 +22,7 @@ from youtube_dl.utils import ( DateRange, detect_exe_version, determine_ext, + dict_get, encode_compat_str, encodeFilename, escape_rfc3986, @@ -450,6 +451,19 @@ class TestUtil(unittest.TestCase): data = urlencode_postdata({'username': '[email protected]', 'password': '1234'}) self.assertTrue(isinstance(data, bytes)) + def test_dict_get(self): + d = { + 'a': 42, + } + self.assertEqual(dict_get(d, 'a'), 42) + self.assertEqual(dict_get(d, 'b'), None) + self.assertEqual(dict_get(d, 'b', 42), 42) + self.assertEqual(dict_get(d, ('a', )), 42) + self.assertEqual(dict_get(d, ('b', 'a', )), 42) + self.assertEqual(dict_get(d, ('b', 'c', 'a', 'd', )), 42) + self.assertEqual(dict_get(d, ('b', 'c', )), None) + self.assertEqual(dict_get(d, ('b', 'c', ), 42), 42) + def test_encode_compat_str(self): self.assertEqual(encode_compat_str(b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82', 'utf-8'), 'тест') self.assertEqual(encode_compat_str('тест', 'utf-8'), 'тест') |