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