Commit 64fe5235 authored by Fred Drake's avatar Fred Drake

Convert dospath test suite to PyUnit, adding a couple more cases for

isabs() (no false results were checked) and splitdrive().
parent 876dc70b
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) def test_abspath(self):
if wantResult != gotResult: self.assert_(dospath.abspath("C:\\") == "C:\\")
print "error!"
print "evaluated: " + str(fn) def test_isabs(self):
print "should be: " + str(wantResult) isabs = dospath.isabs
print " returned: " + str(gotResult) self.assert_(isabs("c:\\"))
print "" self.assert_(isabs("\\\\conky\\mountpoint\\"))
global errors self.assert_(isabs("\\foo"))
errors = errors + 1 self.assert_(isabs("\\foo\\bar"))
self.failIf(isabs("foo"))
tester('dospath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar')) self.failIf(isabs("foo\\"))
tester('dospath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar')) self.failIf(isabs("foo\\bar"))
self.failIf(isabs("c:foo"))
tester('dospath.split("c:\\foo\\bar")', ('c:\\foo', 'bar')) self.failIf(isabs("c:foo\\"))
tester('dospath.split("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint\\foo', 'bar')) 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"])
tester('dospath.split("c:/")', ('c:/', '')) == "/home/swen")
tester('dospath.split("//conky/mountpoint/")', ('//conky/mountpoint', '')) self.assert_(commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])
== "\\home\\swen\\")
tester('dospath.isabs("c:\\")', 1) self.assert_(commonprefix(["/home/swen/spam", "/home/swen/spam"])
tester('dospath.isabs("\\\\conky\\mountpoint\\")', 1) == "/home/swen/spam")
tester('dospath.isabs("\\foo")', 1)
tester('dospath.isabs("\\foo\\bar")', 1) def test_split(self):
split = dospath.split
tester('dospath.abspath("C:\\")', "C:\\") self.assertEquals(split("c:\\foo\\bar"),
('c:\\foo', 'bar'))
tester('dospath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])', self.assertEquals(split("\\\\conky\\mountpoint\\foo\\bar"),
"/home/swen") ('\\\\conky\\mountpoint\\foo', 'bar'))
tester('dospath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
"\\home\\swen\\") self.assertEquals(split("c:\\"), ('c:\\', ''))
tester('dospath.commonprefix(["/home/swen/spam", "/home/swen/spam"])', self.assertEquals(split("\\\\conky\\mountpoint\\"),
"/home/swen/spam") ('\\\\conky\\mountpoint', ''))
if errors: self.assertEquals(split("c:/"), ('c:/', ''))
print str(errors) + " errors." self.assertEquals(split("//conky/mountpoint/"),
else: ('//conky/mountpoint', ''))
print "No errors. Thank your lucky stars."
def test_splitdrive(self):
splitdrive = dospath.splitdrive
self.assertEquals(splitdrive("c:\\foo\\bar"), ('c:', '\\foo\\bar'))
self.assertEquals(splitdrive("c:/foo/bar"), ('c:', '/foo/bar'))
self.assertEquals(splitdrive("foo\\bar"), ('', 'foo\\bar'))
self.assertEquals(splitdrive("c:"), ('c:', ''))
test_support.run_unittest(DOSPathTestCase)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment