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_macpath.py

    r2 r391  
    1 import os
    2 import sys
    31import macpath
    4 from test import test_support
     2from test import test_support, test_genericpath
    53import unittest
    64
     
    97
    108    def test_abspath(self):
    11         self.assert_(macpath.abspath("xx:yy") == "xx:yy")
    12 
    13         # Issue 3426: check that abspath retuns unicode when the arg is unicode
    14         # and str when it's str, with both ASCII and non-ASCII cwds
    15         saved_cwd = os.getcwd()
    16         cwds = ['cwd']
    17         try:
    18             cwds.append(u'\xe7w\xf0'.encode(sys.getfilesystemencoding()
    19                                             or 'ascii'))
    20         except UnicodeEncodeError:
    21             pass # the cwd can't be encoded -- test with ascii cwd only
    22         for cwd in cwds:
    23             try:
    24                 os.mkdir(cwd)
    25                 os.chdir(cwd)
    26                 for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
    27                     self.assertTrue(isinstance(macpath.abspath(path), str))
    28                 for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
    29                     self.assertTrue(isinstance(macpath.abspath(upath), unicode))
    30             finally:
    31                 os.chdir(saved_cwd)
    32                 os.rmdir(cwd)
    33 
     9        self.assertEqual(macpath.abspath("xx:yy"), "xx:yy")
    3410
    3511    def test_isabs(self):
    3612        isabs = macpath.isabs
    37         self.assert_(isabs("xx:yy"))
    38         self.assert_(isabs("xx:yy:"))
    39         self.assert_(isabs("xx:"))
    40         self.failIf(isabs("foo"))
    41         self.failIf(isabs(":foo"))
    42         self.failIf(isabs(":foo:bar"))
    43         self.failIf(isabs(":foo:bar:"))
    44 
    45 
    46     def test_commonprefix(self):
    47         commonprefix = macpath.commonprefix
    48         self.assert_(commonprefix(["home:swenson:spam", "home:swen:spam"])
    49                      == "home:swen")
    50         self.assert_(commonprefix([":home:swen:spam", ":home:swen:eggs"])
    51                      == ":home:swen:")
    52         self.assert_(commonprefix([":home:swen:spam", ":home:swen:spam"])
    53                      == ":home:swen:spam")
     13        self.assertTrue(isabs("xx:yy"))
     14        self.assertTrue(isabs("xx:yy:"))
     15        self.assertTrue(isabs("xx:"))
     16        self.assertFalse(isabs("foo"))
     17        self.assertFalse(isabs(":foo"))
     18        self.assertFalse(isabs(":foo:bar"))
     19        self.assertFalse(isabs(":foo:bar:"))
    5420
    5521    def test_split(self):
    5622        split = macpath.split
    57         self.assertEquals(split("foo:bar"),
     23        self.assertEqual(split("foo:bar"),
    5824                          ('foo:', 'bar'))
    59         self.assertEquals(split("conky:mountpoint:foo:bar"),
     25        self.assertEqual(split("conky:mountpoint:foo:bar"),
    6026                          ('conky:mountpoint:foo', 'bar'))
    6127
    62         self.assertEquals(split(":"), ('', ''))
    63         self.assertEquals(split(":conky:mountpoint:"),
     28        self.assertEqual(split(":"), ('', ''))
     29        self.assertEqual(split(":conky:mountpoint:"),
    6430                          (':conky:mountpoint', ''))
    65 
    66     def test_splitdrive(self):
    67         splitdrive = macpath.splitdrive
    68         self.assertEquals(splitdrive("foo:bar"), ('', 'foo:bar'))
    69         self.assertEquals(splitdrive(":foo:bar"), ('', ':foo:bar'))
    7031
    7132    def test_splitext(self):
    7233        splitext = macpath.splitext
    73         self.assertEquals(splitext(":foo.ext"), (':foo', '.ext'))
    74         self.assertEquals(splitext("foo:foo.ext"), ('foo:foo', '.ext'))
    75         self.assertEquals(splitext(".ext"), ('.ext', ''))
    76         self.assertEquals(splitext("foo.ext:foo"), ('foo.ext:foo', ''))
    77         self.assertEquals(splitext(":foo.ext:"), (':foo.ext:', ''))
    78         self.assertEquals(splitext(""), ('', ''))
    79         self.assertEquals(splitext("foo.bar.ext"), ('foo.bar', '.ext'))
     34        self.assertEqual(splitext(":foo.ext"), (':foo', '.ext'))
     35        self.assertEqual(splitext("foo:foo.ext"), ('foo:foo', '.ext'))
     36        self.assertEqual(splitext(".ext"), ('.ext', ''))
     37        self.assertEqual(splitext("foo.ext:foo"), ('foo.ext:foo', ''))
     38        self.assertEqual(splitext(":foo.ext:"), (':foo.ext:', ''))
     39        self.assertEqual(splitext(""), ('', ''))
     40        self.assertEqual(splitext("foo.bar.ext"), ('foo.bar', '.ext'))
     41
     42    def test_normpath(self):
     43        # Issue 5827: Make sure normpath preserves unicode
     44        for path in (u'', u'.', u'/', u'\\', u':', u'///foo/.//bar//'):
     45            self.assertIsInstance(macpath.normpath(path), unicode,
     46                                  'normpath() returned str instead of unicode')
     47
     48class MacCommonTest(test_genericpath.CommonTest):
     49    pathmodule = macpath
    8050
    8151
    8252def test_main():
    83     test_support.run_unittest(MacPathTestCase)
     53    test_support.run_unittest(MacPathTestCase, MacCommonTest)
    8454
    8555
Note: See TracChangeset for help on using the changeset viewer.