summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericpath.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-02-13 08:14:48 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-02-13 08:14:48 (GMT)
commit7dfaa27fddb57ffcaf79bf21c49fd2a2cd741ab9 (patch)
treee5795f29cb7a2be5c2ed8d6b6bdab8091b231cdd /Lib/test/test_genericpath.py
parentb58f053e48923cba2708410bd215371a7d1d5250 (diff)
parentdbb101909d4bcc7cfe7a8063bb4ac4ec879ecac8 (diff)
downloadcpython-7dfaa27fddb57ffcaf79bf21c49fd2a2cd741ab9.zip
cpython-7dfaa27fddb57ffcaf79bf21c49fd2a2cd741ab9.tar.gz
cpython-7dfaa27fddb57ffcaf79bf21c49fd2a2cd741ab9.tar.bz2
Issue #6815: os.path.expandvars() now supports non-ASCII environment
variables names and values.
Diffstat (limited to 'Lib/test/test_genericpath.py')
-rw-r--r--Lib/test/test_genericpath.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index e967897..e59ed4d 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -329,7 +329,6 @@ class CommonTest(GenericTest):
self.assertEqual(expandvars("$[foo]bar"), "$[foo]bar")
self.assertEqual(expandvars("$bar bar"), "$bar bar")
self.assertEqual(expandvars("$?bar"), "$?bar")
- self.assertEqual(expandvars("${foo}bar"), "barbar")
self.assertEqual(expandvars("$foo}bar"), "bar}bar")
self.assertEqual(expandvars("${foo"), "${foo")
self.assertEqual(expandvars("${{foo}}"), "baz1}")
@@ -342,13 +341,40 @@ class CommonTest(GenericTest):
self.assertEqual(expandvars(b"$[foo]bar"), b"$[foo]bar")
self.assertEqual(expandvars(b"$bar bar"), b"$bar bar")
self.assertEqual(expandvars(b"$?bar"), b"$?bar")
- self.assertEqual(expandvars(b"${foo}bar"), b"barbar")
self.assertEqual(expandvars(b"$foo}bar"), b"bar}bar")
self.assertEqual(expandvars(b"${foo"), b"${foo")
self.assertEqual(expandvars(b"${{foo}}"), b"baz1}")
self.assertEqual(expandvars(b"$foo$foo"), b"barbar")
self.assertEqual(expandvars(b"$bar$bar"), b"$bar$bar")
+ @unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII')
+ def test_expandvars_nonascii(self):
+ if self.pathmodule.__name__ == 'macpath':
+ self.skipTest('macpath.expandvars is a stub')
+ expandvars = self.pathmodule.expandvars
+ def check(value, expected):
+ self.assertEqual(expandvars(value), expected)
+ with support.EnvironmentVarGuard() as env:
+ env.clear()
+ nonascii = support.FS_NONASCII
+ env['spam'] = nonascii
+ env[nonascii] = 'ham' + nonascii
+ check(nonascii, nonascii)
+ check('$spam bar', '%s bar' % nonascii)
+ check('${spam}bar', '%sbar' % nonascii)
+ check('${%s}bar' % nonascii, 'ham%sbar' % nonascii)
+ check('$bar%s bar' % nonascii, '$bar%s bar' % nonascii)
+ check('$spam}bar', '%s}bar' % nonascii)
+
+ check(os.fsencode(nonascii), os.fsencode(nonascii))
+ check(b'$spam bar', os.fsencode('%s bar' % nonascii))
+ check(b'${spam}bar', os.fsencode('%sbar' % nonascii))
+ check(os.fsencode('${%s}bar' % nonascii),
+ os.fsencode('ham%sbar' % nonascii))
+ check(os.fsencode('$bar%s bar' % nonascii),
+ os.fsencode('$bar%s bar' % nonascii))
+ check(b'$spam}bar', os.fsencode('%s}bar' % nonascii))
+
def test_abspath(self):
self.assertIn("foo", self.pathmodule.abspath("foo"))
with warnings.catch_warnings():