aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-04-18 02:28:28 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-04-18 02:28:28 +0530
commit19a0394044bfad36cd665450271b8eb048a41c02 (patch)
tree0db2a09d23293b47f1cc3bbd3a5989120f660c37 /test/test_utils.py
parentb6dc37fe2aee167bf11f863f960a4888f4886718 (diff)
downloadhypervideo-pre-19a0394044bfad36cd665450271b8eb048a41c02.tar.lz
hypervideo-pre-19a0394044bfad36cd665450271b8eb048a41c02.tar.xz
hypervideo-pre-19a0394044bfad36cd665450271b8eb048a41c02.zip
[cleanup] Misc cleanup and refactor (#2173)
Diffstat (limited to 'test/test_utils.py')
-rw-r--r--test/test_utils.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index 7909dc61c..5e220087b 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# Allow direct execution
+import contextlib
import os
import sys
import unittest
@@ -267,11 +268,18 @@ class TestUtil(unittest.TestCase):
compat_setenv('yt_dlp_EXPATH_PATH', 'expanded')
self.assertEqual(expand_path(env('yt_dlp_EXPATH_PATH')), 'expanded')
- self.assertEqual(expand_path(env('HOME')), compat_getenv('HOME'))
- self.assertEqual(expand_path('~'), compat_getenv('HOME'))
- self.assertEqual(
- expand_path('~/%s' % env('yt_dlp_EXPATH_PATH')),
- '%s/expanded' % compat_getenv('HOME'))
+
+ old_home = os.environ.get('HOME')
+ test_str = R'C:\Documents and Settings\ั‚ะตัั‚\Application Data'
+ try:
+ compat_setenv('HOME', test_str)
+ self.assertEqual(expand_path(env('HOME')), compat_getenv('HOME'))
+ self.assertEqual(expand_path('~'), compat_getenv('HOME'))
+ self.assertEqual(
+ expand_path('~/%s' % env('yt_dlp_EXPATH_PATH')),
+ '%s/expanded' % compat_getenv('HOME'))
+ finally:
+ compat_setenv('HOME', old_home or '')
def test_prepend_extension(self):
self.assertEqual(prepend_extension('abc.ext', 'temp'), 'abc.temp.ext')
@@ -1814,10 +1822,8 @@ Line 1
else:
self.assertFalse(testing_write, f'{test_mode} is not blocked by {lock_mode}')
finally:
- try:
+ with contextlib.suppress(OSError):
os.remove(FILE)
- except Exception:
- pass
if __name__ == '__main__':