py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Lib / test / test_ntpath.py
blob7867fd9cfa1757c038443de4daab955c8f2326f6
1 import ntpath
2 import os
4 errors = 0
6 def tester(fn, wantResult):
7 fn = fn.replace("\\", "\\\\")
8 gotResult = eval(fn)
9 if wantResult != gotResult:
10 print "error!"
11 print "evaluated: " + str(fn)
12 print "should be: " + str(wantResult)
13 print " returned: " + str(gotResult)
14 print ""
15 global errors
16 errors = errors + 1
18 tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
19 tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint', '\\foo\\bar'))
20 tester('ntpath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar'))
21 tester('ntpath.splitunc("//conky/mountpoint/foo/bar")', ('//conky/mountpoint', '/foo/bar'))
23 tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
24 tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint\\foo', 'bar'))
26 tester('ntpath.split("c:\\")', ('c:\\', ''))
27 tester('ntpath.split("\\\\conky\\mountpoint\\")', ('\\\\conky\\mountpoint', ''))
29 tester('ntpath.split("c:/")', ('c:/', ''))
30 tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
32 tester('ntpath.isabs("c:\\")', 1)
33 tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
34 tester('ntpath.isabs("\\foo")', 1)
35 tester('ntpath.isabs("\\foo\\bar")', 1)
37 tester('ntpath.abspath("C:\\")', "C:\\")
39 tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
40 "/home/swen")
41 tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
42 "\\home\\swen\\")
43 tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
44 "/home/swen/spam")
46 if errors:
47 print str(errors) + " errors."
48 else:
49 print "No errors. Thank your lucky stars."