summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ntpath.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-02-13 08:13:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-02-13 08:13:53 (GMT)
commitdbb101909d4bcc7cfe7a8063bb4ac4ec879ecac8 (patch)
treed4c26e5ec3c4b507d0694b0f65618c6b05b3f182 /Lib/test/test_ntpath.py
parent61e2493b8341be74928872ce6d7fb3a350bd1697 (diff)
downloadcpython-dbb101909d4bcc7cfe7a8063bb4ac4ec879ecac8.zip
cpython-dbb101909d4bcc7cfe7a8063bb4ac4ec879ecac8.tar.gz
cpython-dbb101909d4bcc7cfe7a8063bb4ac4ec879ecac8.tar.bz2
Issue #6815: os.path.expandvars() now supports non-ASCII environment
variables names and values.
Diffstat (limited to 'Lib/test/test_ntpath.py')
-rw-r--r--Lib/test/test_ntpath.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 2c4d27e..e9e1d71 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -22,13 +22,15 @@ def tester(fn, wantResult):
fn = fn.replace('["', '[b"')
fn = fn.replace(", '", ", b'")
fn = fn.replace(', "', ', b"')
+ fn = os.fsencode(fn).decode('latin1')
+ fn = fn.encode('ascii', 'backslashreplace').decode('ascii')
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
gotResult = eval(fn)
if isinstance(wantResult, str):
- wantResult = wantResult.encode('ascii')
+ wantResult = os.fsencode(wantResult)
elif isinstance(wantResult, tuple):
- wantResult = tuple(r.encode('ascii') for r in wantResult)
+ wantResult = tuple(os.fsencode(r) for r in wantResult)
gotResult = eval(fn)
if wantResult != gotResult:
@@ -223,7 +225,6 @@ class TestNtpath(unittest.TestCase):
tester('ntpath.expandvars("$[foo]bar")', "$[foo]bar")
tester('ntpath.expandvars("$bar bar")', "$bar bar")
tester('ntpath.expandvars("$?bar")', "$?bar")
- tester('ntpath.expandvars("${foo}bar")', "barbar")
tester('ntpath.expandvars("$foo}bar")', "bar}bar")
tester('ntpath.expandvars("${foo")', "${foo")
tester('ntpath.expandvars("${{foo}}")', "baz1}")
@@ -237,6 +238,26 @@ class TestNtpath(unittest.TestCase):
tester('ntpath.expandvars("%foo%%bar")', "bar%bar")
tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
+ @unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII')
+ def test_expandvars_nonascii(self):
+ def check(value, expected):
+ tester('ntpath.expandvars(%r)' % value, expected)
+ with support.EnvironmentVarGuard() as env:
+ env.clear()
+ nonascii = support.FS_NONASCII
+ env['spam'] = nonascii
+ env[nonascii] = 'ham' + nonascii
+ check('$spam bar', '%s bar' % nonascii)
+ check('$%s bar' % nonascii, '$%s bar' % nonascii)
+ check('${spam}bar', '%sbar' % nonascii)
+ check('${%s}bar' % nonascii, 'ham%sbar' % nonascii)
+ check('$spam}bar', '%s}bar' % nonascii)
+ check('$%s}bar' % nonascii, '$%s}bar' % nonascii)
+ check('%spam% bar', '%s bar' % nonascii)
+ check('%{}% bar'.format(nonascii), 'ham%s bar' % nonascii)
+ check('%spam%bar', '%sbar' % nonascii)
+ check('%{}%bar'.format(nonascii), 'ham%sbar' % nonascii)
+
def test_abspath(self):
# ntpath.abspath() can only be used on a system with the "nt" module
# (reasonably), so we protect this test with "import nt". This allows