blob: 1b49c035909a4279df99a2cf722977d91b1ef75f [file] [log] [blame]
Guido van Rossumead9d8d1999-02-03 17:21:21 +00001import ntpath
2import string
Mark Hammond673c6cf2000-08-14 06:21:26 +00003import os
Guido van Rossumead9d8d1999-02-03 17:21:21 +00004
5errors = 0
6
7def tester(fn, wantResult):
Fred Drake004d5e62000-10-23 17:22:08 +00008 fn = string.replace(fn, "\\", "\\\\")
9 gotResult = eval(fn)
10 if wantResult != gotResult:
11 print "error!"
12 print "evaluated: " + str(fn)
13 print "should be: " + str(wantResult)
14 print " returned: " + str(gotResult)
15 print ""
16 global errors
17 errors = errors + 1
Guido van Rossumead9d8d1999-02-03 17:21:21 +000018
19tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
Guido van Rossum630a9a61999-04-06 19:38:18 +000020tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint', '\\foo\\bar'))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000021tester('ntpath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar'))
Guido van Rossum630a9a61999-04-06 19:38:18 +000022tester('ntpath.splitunc("//conky/mountpoint/foo/bar")', ('//conky/mountpoint', '/foo/bar'))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000023
24tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
25tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint\\foo', 'bar'))
26
27tester('ntpath.split("c:\\")', ('c:\\', ''))
Guido van Rossum630a9a61999-04-06 19:38:18 +000028tester('ntpath.split("\\\\conky\\mountpoint\\")', ('\\\\conky\\mountpoint', ''))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000029
30tester('ntpath.split("c:/")', ('c:/', ''))
Guido van Rossum630a9a61999-04-06 19:38:18 +000031tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000032
33tester('ntpath.isabs("c:\\")', 1)
34tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
35tester('ntpath.isabs("\\foo")', 1)
36tester('ntpath.isabs("\\foo\\bar")', 1)
37
Mark Hammond673c6cf2000-08-14 06:21:26 +000038tester('ntpath.abspath("C:\\")', "C:\\")
Mark Hammond673c6cf2000-08-14 06:21:26 +000039
Skip Montanaro877d62e2000-08-23 16:54:27 +000040tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
41 "/home/swen")
42tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
43 "\\home\\swen\\")
44tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
45 "/home/swen/spam")
Mark Hammond673c6cf2000-08-14 06:21:26 +000046
Guido van Rossumead9d8d1999-02-03 17:21:21 +000047if errors:
Fred Drake004d5e62000-10-23 17:22:08 +000048 print str(errors) + " errors."
Guido van Rossumead9d8d1999-02-03 17:21:21 +000049else:
Fred Drake004d5e62000-10-23 17:22:08 +000050 print "No errors. Thank your lucky stars."