summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-03 21:57:20 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-03 21:57:20 (GMT)
commitb186f3438419a6c881705a42db1ecc4e52f5241e (patch)
tree6415831b75a16b3a01a975d8cd720d54cf57dd26 /Lib/test
parentf60fe81030834800869151fe0414ddc3e7c21939 (diff)
downloadcpython-b186f3438419a6c881705a42db1ecc4e52f5241e.zip
cpython-b186f3438419a6c881705a42db1ecc4e52f5241e.tar.gz
cpython-b186f3438419a6c881705a42db1ecc4e52f5241e.tar.bz2
Issue3187 for Macintosh platform:
macpath.py now accepts both unicode string and bytes as file names. Also add more tests for these functions. Reviewed by Benjamin.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_macpath.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/Lib/test/test_macpath.py b/Lib/test/test_macpath.py
index 38b85e5..368d8f5 100644
--- a/Lib/test/test_macpath.py
+++ b/Lib/test/test_macpath.py
@@ -18,6 +18,14 @@ class MacPathTestCase(unittest.TestCase):
self.failIf(isabs(":foo:bar"))
self.failIf(isabs(":foo:bar:"))
+ self.assert_(isabs(b"xx:yy"))
+ self.assert_(isabs(b"xx:yy:"))
+ self.assert_(isabs(b"xx:"))
+ self.failIf(isabs(b"foo"))
+ self.failIf(isabs(b":foo"))
+ self.failIf(isabs(b":foo:bar"))
+ self.failIf(isabs(b":foo:bar:"))
+
def test_commonprefix(self):
commonprefix = macpath.commonprefix
@@ -28,6 +36,13 @@ class MacPathTestCase(unittest.TestCase):
self.assert_(commonprefix([":home:swen:spam", ":home:swen:spam"])
== ":home:swen:spam")
+ self.assert_(commonprefix([b"home:swenson:spam", b"home:swen:spam"])
+ == b"home:swen")
+ self.assert_(commonprefix([b":home:swen:spam", b":home:swen:eggs"])
+ == b":home:swen:")
+ self.assert_(commonprefix([b":home:swen:spam", b":home:swen:spam"])
+ == b":home:swen:spam")
+
def test_split(self):
split = macpath.split
self.assertEquals(split("foo:bar"),
@@ -39,11 +54,37 @@ class MacPathTestCase(unittest.TestCase):
self.assertEquals(split(":conky:mountpoint:"),
(':conky:mountpoint', ''))
+ self.assertEquals(split(b"foo:bar"),
+ (b'foo:', b'bar'))
+ self.assertEquals(split(b"conky:mountpoint:foo:bar"),
+ (b'conky:mountpoint:foo', b'bar'))
+
+ self.assertEquals(split(b":"), (b'', b''))
+ self.assertEquals(split(b":conky:mountpoint:"),
+ (b':conky:mountpoint', b''))
+
+ def test_join(self):
+ join = macpath.join
+ self.assertEquals(join('a', 'b'), ':a:b')
+ self.assertEquals(join('', 'a:b'), 'a:b')
+ self.assertEquals(join('a:b', 'c'), 'a:b:c')
+ self.assertEquals(join('a:b', ':c'), 'a:b:c')
+ self.assertEquals(join('a', ':b', ':c'), ':a:b:c')
+
+ self.assertEquals(join(b'a', b'b'), b':a:b')
+ self.assertEquals(join(b'', b'a:b'), b'a:b')
+ self.assertEquals(join(b'a:b', b'c'), b'a:b:c')
+ self.assertEquals(join(b'a:b', b':c'), b'a:b:c')
+ self.assertEquals(join(b'a', b':b', b':c'), b':a:b:c')
+
def test_splitdrive(self):
splitdrive = macpath.splitdrive
self.assertEquals(splitdrive("foo:bar"), ('', 'foo:bar'))
self.assertEquals(splitdrive(":foo:bar"), ('', ':foo:bar'))
+ self.assertEquals(splitdrive(b"foo:bar"), (b'', b'foo:bar'))
+ self.assertEquals(splitdrive(b":foo:bar"), (b'', b':foo:bar'))
+
def test_splitext(self):
splitext = macpath.splitext
self.assertEquals(splitext(":foo.ext"), (':foo', '.ext'))
@@ -54,6 +95,49 @@ class MacPathTestCase(unittest.TestCase):
self.assertEquals(splitext(""), ('', ''))
self.assertEquals(splitext("foo.bar.ext"), ('foo.bar', '.ext'))
+ self.assertEquals(splitext(b":foo.ext"), (b':foo', b'.ext'))
+ self.assertEquals(splitext(b"foo:foo.ext"), (b'foo:foo', b'.ext'))
+ self.assertEquals(splitext(b".ext"), (b'.ext', b''))
+ self.assertEquals(splitext(b"foo.ext:foo"), (b'foo.ext:foo', b''))
+ self.assertEquals(splitext(b":foo.ext:"), (b':foo.ext:', b''))
+ self.assertEquals(splitext(b""), (b'', b''))
+ self.assertEquals(splitext(b"foo.bar.ext"), (b'foo.bar', b'.ext'))
+
+ def test_ismount(self):
+ ismount = macpath.ismount
+ self.assertEquals(ismount("a:"), True)
+ self.assertEquals(ismount("a:b"), False)
+ self.assertEquals(ismount("a:b:"), True)
+ self.assertEquals(ismount(""), False)
+ self.assertEquals(ismount(":"), False)
+
+ self.assertEquals(ismount(b"a:"), True)
+ self.assertEquals(ismount(b"a:b"), False)
+ self.assertEquals(ismount(b"a:b:"), True)
+ self.assertEquals(ismount(b""), False)
+ self.assertEquals(ismount(b":"), False)
+
+ def test_normpath(self):
+ normpath = macpath.normpath
+ self.assertEqual(normpath("a:b"), "a:b")
+ self.assertEqual(normpath("a"), ":a")
+ self.assertEqual(normpath("a:b::c"), "a:c")
+ self.assertEqual(normpath("a:b:c:::d"), "a:d")
+ self.assertRaises(macpath.norm_error, normpath, "a::b")
+ self.assertRaises(macpath.norm_error, normpath, "a:b:::c")
+ self.assertEqual(normpath(":"), ":")
+ self.assertEqual(normpath("a:"), "a:")
+ self.assertEqual(normpath("a:b:"), "a:b")
+
+ self.assertEqual(normpath(b"a:b"), b"a:b")
+ self.assertEqual(normpath(b"a"), b":a")
+ self.assertEqual(normpath(b"a:b::c"), b"a:c")
+ self.assertEqual(normpath(b"a:b:c:::d"), b"a:d")
+ self.assertRaises(macpath.norm_error, normpath, b"a::b")
+ self.assertRaises(macpath.norm_error, normpath, b"a:b:::c")
+ self.assertEqual(normpath(b":"), b":")
+ self.assertEqual(normpath(b"a:"), b"a:")
+ self.assertEqual(normpath(b"a:b:"), b"a:b")
def test_main():
support.run_unittest(MacPathTestCase)