2021-06-03 03:43:42 -06:00
|
|
|
#!/usr/bin/env python3
|
2022-06-24 05:06:16 -06:00
|
|
|
|
2014-11-02 03:23:40 -07:00
|
|
|
# Allow direct execution
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
2022-04-11 16:32:57 -06:00
|
|
|
|
2014-11-02 03:23:40 -07:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
|
2022-06-24 02:10:17 -06:00
|
|
|
import struct
|
|
|
|
|
2022-04-24 10:28:18 -06:00
|
|
|
from yt_dlp import compat
|
2023-07-22 06:26:53 -06:00
|
|
|
from yt_dlp.compat import urllib # isort: split
|
2024-11-16 16:24:11 -07:00
|
|
|
from yt_dlp.compat import compat_etree_fromstring, compat_expanduser
|
2023-07-22 06:26:53 -06:00
|
|
|
from yt_dlp.compat.urllib.request import getproxies
|
2014-11-02 03:23:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
class TestCompat(unittest.TestCase):
|
2022-04-24 10:28:18 -06:00
|
|
|
def test_compat_passthrough(self):
|
|
|
|
with self.assertWarns(DeprecationWarning):
|
2024-06-11 17:09:58 -06:00
|
|
|
_ = compat.compat_basestring
|
2022-04-24 10:28:18 -06:00
|
|
|
|
2022-06-24 04:10:13 -06:00
|
|
|
with self.assertWarns(DeprecationWarning):
|
2024-06-11 17:09:58 -06:00
|
|
|
_ = compat.WINDOWS_VT_MODE
|
2022-06-24 04:10:13 -06:00
|
|
|
|
2023-07-22 06:26:53 -06:00
|
|
|
self.assertEqual(urllib.request.getproxies, getproxies)
|
2022-04-24 10:28:18 -06:00
|
|
|
|
2023-02-06 14:52:29 -07:00
|
|
|
with self.assertWarns(DeprecationWarning):
|
2024-06-11 17:09:58 -06:00
|
|
|
_ = compat.compat_pycrypto_AES # Must not raise error
|
2023-02-06 14:52:29 -07:00
|
|
|
|
2014-11-02 03:23:40 -07:00
|
|
|
def test_compat_expanduser(self):
|
2014-11-18 15:34:46 -07:00
|
|
|
old_home = os.environ.get('HOME')
|
2022-04-17 14:58:28 -06:00
|
|
|
test_str = R'C:\Documents and Settings\тест\Application Data'
|
|
|
|
try:
|
2022-06-24 02:10:17 -06:00
|
|
|
os.environ['HOME'] = test_str
|
2022-04-17 14:58:28 -06:00
|
|
|
self.assertEqual(compat_expanduser('~'), test_str)
|
|
|
|
finally:
|
2022-06-24 02:10:17 -06:00
|
|
|
os.environ['HOME'] = old_home or ''
|
2014-11-02 03:23:40 -07:00
|
|
|
|
2015-10-25 13:04:55 -06:00
|
|
|
def test_compat_etree_fromstring(self):
|
2015-10-26 09:41:24 -06:00
|
|
|
xml = '''
|
|
|
|
<root foo="bar" spam="中文">
|
|
|
|
<normal>foo</normal>
|
|
|
|
<chinese>中文</chinese>
|
|
|
|
<foo><bar>spam</bar></foo>
|
|
|
|
</root>
|
|
|
|
'''
|
2022-05-09 05:54:28 -06:00
|
|
|
doc = compat_etree_fromstring(xml.encode())
|
2022-06-24 04:54:43 -06:00
|
|
|
self.assertTrue(isinstance(doc.attrib['foo'], str))
|
|
|
|
self.assertTrue(isinstance(doc.attrib['spam'], str))
|
|
|
|
self.assertTrue(isinstance(doc.find('normal').text, str))
|
|
|
|
self.assertTrue(isinstance(doc.find('chinese').text, str))
|
|
|
|
self.assertTrue(isinstance(doc.find('foo/bar').text, str))
|
2015-10-25 13:04:55 -06:00
|
|
|
|
2016-05-22 11:34:08 -06:00
|
|
|
def test_compat_etree_fromstring_doctype(self):
|
|
|
|
xml = '''<?xml version="1.0"?>
|
|
|
|
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd">
|
|
|
|
<smil xmlns="http://www.w3.org/2001/SMIL20/Language"></smil>'''
|
|
|
|
compat_etree_fromstring(xml)
|
|
|
|
|
2016-04-23 04:28:49 -06:00
|
|
|
def test_struct_unpack(self):
|
2022-06-24 02:10:17 -06:00
|
|
|
self.assertEqual(struct.unpack('!B', b'\x00'), (0,))
|
2016-04-23 04:28:49 -06:00
|
|
|
|
|
|
|
|
2014-11-02 03:23:40 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|