Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_ntpath.py

    r2 r391  
    11import ntpath
    22import os
    3 from test.test_support import verbose, TestFailed
    4 import test.test_support as test_support
     3from test.test_support import TestFailed
     4from test import test_support, test_genericpath
    55import unittest
    66
     
    124124        tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
    125125
    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')
    130128
    131129    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"
    138135            tester('ntpath.expandvars("foo")', "foo")
    139136            tester('ntpath.expandvars("$foo bar")', "bar bar")
     
    155152            tester('ntpath.expandvars("%foo%%bar")', "bar%bar")
    156153            tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
    157         finally:
    158             os.environ.clear()
    159             os.environ.update(oldenv)
    160154
    161155    def test_abspath(self):
     
    174168            tester('ntpath.abspath("C:\\")', "C:\\")
    175169
    176             # Issue 3426: check that abspath retuns unicode when the arg is
    177             # unicode and str when it's str, with both ASCII and non-ASCII cwds
    178             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 
    193170    def test_relpath(self):
    194171        currentdir = os.path.split(os.getcwd())[-1]
     
    202179        tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
    203180        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
     193class NtCommonTest(test_genericpath.CommonTest):
     194    pathmodule = ntpath
     195    attributes = ['relpath', 'splitunc']
    204196
    205197
    206198def test_main():
    207     test_support.run_unittest(TestNtpath)
     199    test_support.run_unittest(TestNtpath, NtCommonTest)
    208200
    209201
Note: See TracChangeset for help on using the changeset viewer.