Changeset 391 for python/trunk/Lib/test/test_ntpath.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_ntpath.py
r2 r391 1 1 import ntpath 2 2 import os 3 from test.test_support import verbose,TestFailed4 import test.test_support as test_support 3 from test.test_support import TestFailed 4 from test import test_support, test_genericpath 5 5 import unittest 6 6 … … 124 124 tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b') 125 125 126 # Issue 5827: Make sure normpath preserves unicode 127 for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'): 128 self.assertTrue(isinstance(ntpath.normpath(path), unicode), 129 'normpath() returned str instead of unicode') 126 tester("ntpath.normpath('\\\\.\\NUL')", r'\\.\NUL') 127 tester("ntpath.normpath('\\\\?\\D:/XY\\Z')", r'\\?\D:/XY\Z') 130 128 131 129 def test_expandvars(self): 132 oldenv = os.environ.copy() 133 try: 134 os.environ.clear() 135 os.environ["foo"] = "bar" 136 os.environ["{foo"] = "baz1" 137 os.environ["{foo}"] = "baz2" 130 with test_support.EnvironmentVarGuard() as env: 131 env.clear() 132 env["foo"] = "bar" 133 env["{foo"] = "baz1" 134 env["{foo}"] = "baz2" 138 135 tester('ntpath.expandvars("foo")', "foo") 139 136 tester('ntpath.expandvars("$foo bar")', "bar bar") … … 155 152 tester('ntpath.expandvars("%foo%%bar")', "bar%bar") 156 153 tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar") 157 finally:158 os.environ.clear()159 os.environ.update(oldenv)160 154 161 155 def test_abspath(self): … … 174 168 tester('ntpath.abspath("C:\\")', "C:\\") 175 169 176 # Issue 3426: check that abspath retuns unicode when the arg is177 # unicode and str when it's str, with both ASCII and non-ASCII cwds178 saved_cwd = os.getcwd()179 for cwd in (u'cwd', u'\xe7w\xf0'):180 try:181 os.mkdir(cwd)182 os.chdir(cwd)183 for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):184 self.assertTrue(isinstance(ntpath.abspath(path), str))185 for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):186 self.assertTrue(isinstance(ntpath.abspath(upath),187 unicode))188 finally:189 os.chdir(saved_cwd)190 os.rmdir(cwd)191 192 193 170 def test_relpath(self): 194 171 currentdir = os.path.split(os.getcwd())[-1] … … 202 179 tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a') 203 180 tester('ntpath.relpath("a", "a")', '.') 181 tester('ntpath.relpath("/foo/bar/bat", "/x/y/z")', '..\\..\\..\\foo\\bar\\bat') 182 tester('ntpath.relpath("/foo/bar/bat", "/foo/bar")', 'bat') 183 tester('ntpath.relpath("/foo/bar/bat", "/")', 'foo\\bar\\bat') 184 tester('ntpath.relpath("/", "/foo/bar/bat")', '..\\..\\..') 185 tester('ntpath.relpath("/foo/bar/bat", "/x")', '..\\foo\\bar\\bat') 186 tester('ntpath.relpath("/x", "/foo/bar/bat")', '..\\..\\..\\x') 187 tester('ntpath.relpath("/", "/")', '.') 188 tester('ntpath.relpath("/a", "/a")', '.') 189 tester('ntpath.relpath("/a/b", "/a/b")', '.') 190 tester('ntpath.relpath("c:/foo", "C:/FOO")', '.') 191 192 193 class NtCommonTest(test_genericpath.CommonTest): 194 pathmodule = ntpath 195 attributes = ['relpath', 'splitunc'] 204 196 205 197 206 198 def test_main(): 207 test_support.run_unittest(TestNtpath )199 test_support.run_unittest(TestNtpath, NtCommonTest) 208 200 209 201
Note:
See TracChangeset
for help on using the changeset viewer.