mirror of
https://github.com/python/cpython.git
synced 2025-09-10 18:58:35 +00:00
Convert dospath test suite to PyUnit, adding a couple more cases for
isabs() (no false results were checked) and splitdrive().
This commit is contained in:
parent
876dc70b2e
commit
64fe52351a
1 changed files with 45 additions and 36 deletions
|
@ -1,47 +1,56 @@
|
||||||
import dospath
|
import dospath
|
||||||
import os
|
import test_support
|
||||||
|
import unittest
|
||||||
|
|
||||||
errors = 0
|
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
class DOSPathTestCase(unittest.TestCase):
|
||||||
fn = fn.replace("\\", "\\\\")
|
|
||||||
gotResult = eval(fn)
|
|
||||||
if wantResult != gotResult:
|
|
||||||
print "error!"
|
|
||||||
print "evaluated: " + str(fn)
|
|
||||||
print "should be: " + str(wantResult)
|
|
||||||
print " returned: " + str(gotResult)
|
|
||||||
print ""
|
|
||||||
global errors
|
|
||||||
errors = errors + 1
|
|
||||||
|
|
||||||
tester('dospath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
|
def test_abspath(self):
|
||||||
tester('dospath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar'))
|
self.assert_(dospath.abspath("C:\\") == "C:\\")
|
||||||
|
|
||||||
tester('dospath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
|
def test_isabs(self):
|
||||||
tester('dospath.split("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint\\foo', 'bar'))
|
isabs = dospath.isabs
|
||||||
|
self.assert_(isabs("c:\\"))
|
||||||
|
self.assert_(isabs("\\\\conky\\mountpoint\\"))
|
||||||
|
self.assert_(isabs("\\foo"))
|
||||||
|
self.assert_(isabs("\\foo\\bar"))
|
||||||
|
self.failIf(isabs("foo"))
|
||||||
|
self.failIf(isabs("foo\\"))
|
||||||
|
self.failIf(isabs("foo\\bar"))
|
||||||
|
self.failIf(isabs("c:foo"))
|
||||||
|
self.failIf(isabs("c:foo\\"))
|
||||||
|
self.failIf(isabs("c:foo\\bar"))
|
||||||
|
|
||||||
tester('dospath.split("c:\\")', ('c:\\', ''))
|
def test_commonprefix(self):
|
||||||
tester('dospath.split("\\\\conky\\mountpoint\\")', ('\\\\conky\\mountpoint', ''))
|
commonprefix = dospath.commonprefix
|
||||||
|
self.assert_(commonprefix(["/home/swenson/spam", "/home/swen/spam"])
|
||||||
|
== "/home/swen")
|
||||||
|
self.assert_(commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])
|
||||||
|
== "\\home\\swen\\")
|
||||||
|
self.assert_(commonprefix(["/home/swen/spam", "/home/swen/spam"])
|
||||||
|
== "/home/swen/spam")
|
||||||
|
|
||||||
tester('dospath.split("c:/")', ('c:/', ''))
|
def test_split(self):
|
||||||
tester('dospath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
|
split = dospath.split
|
||||||
|
self.assertEquals(split("c:\\foo\\bar"),
|
||||||
|
('c:\\foo', 'bar'))
|
||||||
|
self.assertEquals(split("\\\\conky\\mountpoint\\foo\\bar"),
|
||||||
|
('\\\\conky\\mountpoint\\foo', 'bar'))
|
||||||
|
|
||||||
tester('dospath.isabs("c:\\")', 1)
|
self.assertEquals(split("c:\\"), ('c:\\', ''))
|
||||||
tester('dospath.isabs("\\\\conky\\mountpoint\\")', 1)
|
self.assertEquals(split("\\\\conky\\mountpoint\\"),
|
||||||
tester('dospath.isabs("\\foo")', 1)
|
('\\\\conky\\mountpoint', ''))
|
||||||
tester('dospath.isabs("\\foo\\bar")', 1)
|
|
||||||
|
|
||||||
tester('dospath.abspath("C:\\")', "C:\\")
|
self.assertEquals(split("c:/"), ('c:/', ''))
|
||||||
|
self.assertEquals(split("//conky/mountpoint/"),
|
||||||
|
('//conky/mountpoint', ''))
|
||||||
|
|
||||||
tester('dospath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
|
def test_splitdrive(self):
|
||||||
"/home/swen")
|
splitdrive = dospath.splitdrive
|
||||||
tester('dospath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
|
self.assertEquals(splitdrive("c:\\foo\\bar"), ('c:', '\\foo\\bar'))
|
||||||
"\\home\\swen\\")
|
self.assertEquals(splitdrive("c:/foo/bar"), ('c:', '/foo/bar'))
|
||||||
tester('dospath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
|
self.assertEquals(splitdrive("foo\\bar"), ('', 'foo\\bar'))
|
||||||
"/home/swen/spam")
|
self.assertEquals(splitdrive("c:"), ('c:', ''))
|
||||||
|
|
||||||
if errors:
|
|
||||||
print str(errors) + " errors."
|
test_support.run_unittest(DOSPathTestCase)
|
||||||
else:
|
|
||||||
print "No errors. Thank your lucky stars."
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue