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