[test_utils] Fix expand_path tests
authorSergey M․ <dstftw@gmail.com>
Sat, 25 Mar 2017 20:07:56 +0000 (03:07 +0700)
committerSergey M․ <dstftw@gmail.com>
Sat, 25 Mar 2017 20:07:56 +0000 (03:07 +0700)
test/test_utils.py

index 8c50b46e8283ee40522ca623cc77c967b33b6ac6..b9a02666d45c93174767b3d42ca7933ee2021cb1 100644 (file)
@@ -218,11 +218,16 @@ class TestUtil(unittest.TestCase):
         self.assertEqual(sanitize_path('./../abc'), '..\\abc')
 
     def test_expand_path(self):
+        def env(var):
+            return '%{0}%'.format(var) if sys.platform == 'win32' else '${0}'.format(var)
+
         compat_setenv('YOUTUBE-DL-EXPATH-PATH', 'expanded')
-        self.assertEqual(expand_path('%YOUTUBE-DL-EXPATH-PATH%'), 'expanded')
-        self.assertEqual(expand_path('%HOMEPATH%'), compat_getenv('HOMEPATH'))
+        self.assertEqual(expand_path(env('YOUTUBE-DL-EXPATH-PATH')), 'expanded')
+        self.assertEqual(expand_path(env('HOMEPATH')), compat_getenv('HOMEPATH'))
         self.assertEqual(expand_path('~'), compat_getenv('HOME'))
-        self.assertEqual(expand_path('~/%YOUTUBE-DL-EXPATH-PATH%'), '%s/expanded' % compat_getenv('HOME'))
+        self.assertEqual(
+            expand_path('~/%s' % env('YOUTUBE-DL-EXPATH-PATH')),
+            '%s/expanded' % compat_getenv('HOME'))
 
     def test_prepend_extension(self):
         self.assertEqual(prepend_extension('abc.ext', 'temp'), 'abc.temp.ext')