diff options
Diffstat (limited to 'Lib/test/test_ntpath.py')
| -rw-r--r-- | Lib/test/test_ntpath.py | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 11e66fb..1f1a971 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -1,16 +1,19 @@ import ntpath import os +import sys from test.test_support import TestFailed from test import test_support, test_genericpath import unittest +def tester0(fn, wantResult): + gotResult = eval(fn) + if wantResult != gotResult: + raise TestFailed, "%s should return: %r but returned: %r" \ + %(fn, wantResult, gotResult) def tester(fn, wantResult): fn = fn.replace("\\", "\\\\") - gotResult = eval(fn) - if wantResult != gotResult: - raise TestFailed, "%s should return: %s but returned: %s" \ - %(str(fn), str(wantResult), str(gotResult)) + tester0(fn, wantResult) class TestNtpath(unittest.TestCase): @@ -173,7 +176,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}") @@ -187,6 +189,30 @@ class TestNtpath(unittest.TestCase): tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar") + @unittest.skipUnless(test_support.FS_NONASCII, 'need test_support.FS_NONASCII') + def test_expandvars_nonascii(self): + encoding = sys.getfilesystemencoding() + def check(value, expected): + tester0("ntpath.expandvars(%r)" % value, expected) + tester0("ntpath.expandvars(%r)" % value.decode(encoding), + expected.decode(encoding)) + with test_support.EnvironmentVarGuard() as env: + env.clear() + unonascii = test_support.FS_NONASCII + snonascii = unonascii.encode(encoding) + env['spam'] = snonascii + env[snonascii] = 'ham' + snonascii + check('$spam bar', '%s bar' % snonascii) + check('$%s bar' % snonascii, '$%s bar' % snonascii) + check('${spam}bar', '%sbar' % snonascii) + check('${%s}bar' % snonascii, 'ham%sbar' % snonascii) + check('$spam}bar', '%s}bar' % snonascii) + check('$%s}bar' % snonascii, '$%s}bar' % snonascii) + check('%spam% bar', '%s bar' % snonascii) + check('%{}% bar'.format(snonascii), 'ham%s bar' % snonascii) + check('%spam%bar', '%sbar' % snonascii) + check('%{}%bar'.format(snonascii), 'ham%sbar' % snonascii) + 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 |
