Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
This commit is contained in:
parent
19b02d4558
commit
e3ed2e02be
|
@ -47,6 +47,18 @@ class GenericTest(unittest.TestCase):
|
|||
commonprefix(["/home/swen/spam", "/home/swen/spam"]),
|
||||
"/home/swen/spam"
|
||||
)
|
||||
self.assertEqual(
|
||||
commonprefix(["home:swenson:spam", "home:swen:spam"]),
|
||||
"home:swen"
|
||||
)
|
||||
self.assertEqual(
|
||||
commonprefix([":home:swen:spam", ":home:swen:eggs"]),
|
||||
":home:swen:"
|
||||
)
|
||||
self.assertEqual(
|
||||
commonprefix([":home:swen:spam", ":home:swen:spam"]),
|
||||
":home:swen:spam"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
commonprefix([b"/home/swenson/spam", b"/home/swen/spam"]),
|
||||
|
@ -60,6 +72,18 @@ class GenericTest(unittest.TestCase):
|
|||
commonprefix([b"/home/swen/spam", b"/home/swen/spam"]),
|
||||
b"/home/swen/spam"
|
||||
)
|
||||
self.assertEqual(
|
||||
commonprefix([b"home:swenson:spam", b"home:swen:spam"]),
|
||||
b"home:swen"
|
||||
)
|
||||
self.assertEqual(
|
||||
commonprefix([b":home:swen:spam", b":home:swen:eggs"]),
|
||||
b":home:swen:"
|
||||
)
|
||||
self.assertEqual(
|
||||
commonprefix([b":home:swen:spam", b":home:swen:spam"]),
|
||||
b":home:swen:spam"
|
||||
)
|
||||
|
||||
testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd',
|
||||
'aXc', 'abd', 'ab', 'aX', 'abcX']
|
||||
|
|
|
@ -26,23 +26,6 @@ class MacPathTestCase(unittest.TestCase):
|
|||
self.assertFalse(isabs(b":foo:bar"))
|
||||
self.assertFalse(isabs(b":foo:bar:"))
|
||||
|
||||
|
||||
def test_commonprefix(self):
|
||||
commonprefix = macpath.commonprefix
|
||||
self.assertEqual(commonprefix(["home:swenson:spam", "home:swen:spam"]),
|
||||
"home:swen")
|
||||
self.assertEqual(commonprefix([":home:swen:spam", ":home:swen:eggs"]),
|
||||
":home:swen:")
|
||||
self.assertEqual(commonprefix([":home:swen:spam", ":home:swen:spam"]),
|
||||
":home:swen:spam")
|
||||
|
||||
self.assertTrue(commonprefix([b"home:swenson:spam", b"home:swen:spam"])
|
||||
== b"home:swen")
|
||||
self.assertTrue(commonprefix([b":home:swen:spam", b":home:swen:eggs"])
|
||||
== b":home:swen:")
|
||||
self.assertTrue(commonprefix([b":home:swen:spam", b":home:swen:spam"])
|
||||
== b":home:swen:spam")
|
||||
|
||||
def test_split(self):
|
||||
split = macpath.split
|
||||
self.assertEqual(split("foo:bar"),
|
||||
|
@ -54,36 +37,28 @@ class MacPathTestCase(unittest.TestCase):
|
|||
self.assertEqual(split(":conky:mountpoint:"),
|
||||
(':conky:mountpoint', ''))
|
||||
|
||||
self.assertEquals(split(b"foo:bar"),
|
||||
self.assertEqual(split(b"foo:bar"),
|
||||
(b'foo:', b'bar'))
|
||||
self.assertEquals(split(b"conky:mountpoint:foo:bar"),
|
||||
self.assertEqual(split(b"conky:mountpoint:foo:bar"),
|
||||
(b'conky:mountpoint:foo', b'bar'))
|
||||
|
||||
self.assertEquals(split(b":"), (b'', b''))
|
||||
self.assertEquals(split(b":conky:mountpoint:"),
|
||||
self.assertEqual(split(b":"), (b'', b''))
|
||||
self.assertEqual(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.assertEqual(join('a', 'b'), ':a:b')
|
||||
self.assertEqual(join('', 'a:b'), 'a:b')
|
||||
self.assertEqual(join('a:b', 'c'), 'a:b:c')
|
||||
self.assertEqual(join('a:b', ':c'), 'a:b:c')
|
||||
self.assertEqual(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.assertEqual(splitdrive("foo:bar"), ('', 'foo:bar'))
|
||||
self.assertEqual(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'))
|
||||
self.assertEqual(join(b'a', b'b'), b':a:b')
|
||||
self.assertEqual(join(b'', b'a:b'), b'a:b')
|
||||
self.assertEqual(join(b'a:b', b'c'), b'a:b:c')
|
||||
self.assertEqual(join(b'a:b', b':c'), b'a:b:c')
|
||||
self.assertEqual(join(b'a', b':b', b':c'), b':a:b:c')
|
||||
|
||||
def test_splitext(self):
|
||||
splitext = macpath.splitext
|
||||
|
@ -95,27 +70,27 @@ class MacPathTestCase(unittest.TestCase):
|
|||
self.assertEqual(splitext(""), ('', ''))
|
||||
self.assertEqual(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'))
|
||||
self.assertEqual(splitext(b":foo.ext"), (b':foo', b'.ext'))
|
||||
self.assertEqual(splitext(b"foo:foo.ext"), (b'foo:foo', b'.ext'))
|
||||
self.assertEqual(splitext(b".ext"), (b'.ext', b''))
|
||||
self.assertEqual(splitext(b"foo.ext:foo"), (b'foo.ext:foo', b''))
|
||||
self.assertEqual(splitext(b":foo.ext:"), (b':foo.ext:', b''))
|
||||
self.assertEqual(splitext(b""), (b'', b''))
|
||||
self.assertEqual(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.assertEqual(ismount("a:"), True)
|
||||
self.assertEqual(ismount("a:b"), False)
|
||||
self.assertEqual(ismount("a:b:"), True)
|
||||
self.assertEqual(ismount(""), False)
|
||||
self.assertEqual(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)
|
||||
self.assertEqual(ismount(b"a:"), True)
|
||||
self.assertEqual(ismount(b"a:b"), False)
|
||||
self.assertEqual(ismount(b"a:b:"), True)
|
||||
self.assertEqual(ismount(b""), False)
|
||||
self.assertEqual(ismount(b":"), False)
|
||||
|
||||
def test_normpath(self):
|
||||
normpath = macpath.normpath
|
||||
|
|
|
@ -136,78 +136,6 @@ class PosixPathTest(unittest.TestCase):
|
|||
self.assertEqual(posixpath.dirname(b"////foo"), b"////")
|
||||
self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo")
|
||||
|
||||
def test_commonprefix(self):
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix([]),
|
||||
""
|
||||
)
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
|
||||
"/home/swen"
|
||||
)
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
|
||||
"/home/swen/"
|
||||
)
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"]),
|
||||
"/home/swen/spam"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix([b"/home/swenson/spam", b"/home/swen/spam"]),
|
||||
b"/home/swen"
|
||||
)
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix([b"/home/swen/spam", b"/home/swen/eggs"]),
|
||||
b"/home/swen/"
|
||||
)
|
||||
self.assertEqual(
|
||||
posixpath.commonprefix([b"/home/swen/spam", b"/home/swen/spam"]),
|
||||
b"/home/swen/spam"
|
||||
)
|
||||
|
||||
testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd', 'aXc', 'abd', 'ab', 'aX', 'abcX']
|
||||
for s1 in testlist:
|
||||
for s2 in testlist:
|
||||
p = posixpath.commonprefix([s1, s2])
|
||||
self.assertTrue(s1.startswith(p))
|
||||
self.assertTrue(s2.startswith(p))
|
||||
if s1 != s2:
|
||||
n = len(p)
|
||||
self.assertNotEqual(s1[n:n+1], s2[n:n+1])
|
||||
|
||||
def test_getsize(self):
|
||||
f = open(support.TESTFN, "wb")
|
||||
try:
|
||||
f.write(b"foo")
|
||||
f.close()
|
||||
self.assertEqual(posixpath.getsize(support.TESTFN), 3)
|
||||
finally:
|
||||
if not f.closed:
|
||||
f.close()
|
||||
|
||||
def test_time(self):
|
||||
f = open(support.TESTFN, "wb")
|
||||
try:
|
||||
f.write(b"foo")
|
||||
f.close()
|
||||
f = open(support.TESTFN, "ab")
|
||||
f.write(b"bar")
|
||||
f.close()
|
||||
f = open(support.TESTFN, "rb")
|
||||
d = f.read()
|
||||
f.close()
|
||||
self.assertEqual(d, b"foobar")
|
||||
|
||||
self.assertLessEqual(
|
||||
posixpath.getctime(support.TESTFN),
|
||||
posixpath.getmtime(support.TESTFN)
|
||||
)
|
||||
finally:
|
||||
if not f.closed:
|
||||
f.close()
|
||||
|
||||
def test_islink(self):
|
||||
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
|
||||
f = open(support.TESTFN + "1", "wb")
|
||||
|
|
Loading…
Reference in New Issue