blob: fe997b31284825d65cb6d54382e3350b8e34d689 [file] [log] [blame]
Guido van Rossumead9d8d1999-02-03 17:21:21 +00001import ntpath
Tim Petersd4f7f602001-07-19 19:11:41 +00002from test_support import verbose, TestFailed
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):
Tim Petersd4f7f602001-07-19 19:11:41 +00008 global errors
Eric S. Raymondfc170b12001-02-09 11:51:27 +00009 fn = fn.replace("\\", "\\\\")
Fred Drake004d5e62000-10-23 17:22:08 +000010 gotResult = eval(fn)
11 if wantResult != gotResult:
12 print "error!"
13 print "evaluated: " + str(fn)
14 print "should be: " + str(wantResult)
15 print " returned: " + str(gotResult)
16 print ""
Fred Drake004d5e62000-10-23 17:22:08 +000017 errors = errors + 1
Guido van Rossumead9d8d1999-02-03 17:21:21 +000018
Tim Peters3b5e4d12001-07-19 19:02:12 +000019tester('ntpath.splitdrive("c:\\foo\\bar")',
20 ('c:', '\\foo\\bar'))
21tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
22 ('\\\\conky\\mountpoint', '\\foo\\bar'))
23tester('ntpath.splitdrive("c:/foo/bar")',
24 ('c:', '/foo/bar'))
25tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
26 ('//conky/mountpoint', '/foo/bar'))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000027
28tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
Tim Peters3b5e4d12001-07-19 19:02:12 +000029tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
30 ('\\\\conky\\mountpoint\\foo', 'bar'))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000031
32tester('ntpath.split("c:\\")', ('c:\\', ''))
Tim Peters3b5e4d12001-07-19 19:02:12 +000033tester('ntpath.split("\\\\conky\\mountpoint\\")',
34 ('\\\\conky\\mountpoint', ''))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000035
36tester('ntpath.split("c:/")', ('c:/', ''))
Guido van Rossum630a9a61999-04-06 19:38:18 +000037tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
Guido van Rossumead9d8d1999-02-03 17:21:21 +000038
39tester('ntpath.isabs("c:\\")', 1)
40tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
41tester('ntpath.isabs("\\foo")', 1)
42tester('ntpath.isabs("\\foo\\bar")', 1)
43
Mark Hammond673c6cf2000-08-14 06:21:26 +000044tester('ntpath.abspath("C:\\")', "C:\\")
Mark Hammond673c6cf2000-08-14 06:21:26 +000045
Skip Montanaro877d62e2000-08-23 16:54:27 +000046tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
47 "/home/swen")
48tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
49 "\\home\\swen\\")
50tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
51 "/home/swen/spam")
Mark Hammond673c6cf2000-08-14 06:21:26 +000052
Tim Petersd4f7f602001-07-19 19:11:41 +000053tester('ntpath.join("")', '')
54tester('ntpath.join("", "", "")', '')
55tester('ntpath.join("a")', 'a')
56tester('ntpath.join("/a")', '/a')
57tester('ntpath.join("\\a")', '\\a')
58tester('ntpath.join("a:")', 'a:')
59tester('ntpath.join("a:", "b")', 'a:b')
60tester('ntpath.join("a:", "/b")', 'a:/b')
61tester('ntpath.join("a:", "\\b")', 'a:\\b')
62tester('ntpath.join("a", "/b")', '/b')
63tester('ntpath.join("a", "\\b")', '\\b')
64tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
65tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
66tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
67tester('ntpath.join("a", "b", "\\c")', '\\c')
Tim Peters4223f892001-07-26 21:54:37 +000068tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
Tim Peters33dc0a12001-07-27 08:09:54 +000069tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
70tester("ntpath.join('c:', '/a')", 'c:/a')
71tester("ntpath.join('c:/', '/a')", 'c:/a')
72tester("ntpath.join('c:/a', '/b')", '/b')
73tester("ntpath.join('c:', 'd:/')", 'd:/')
74tester("ntpath.join('c:/', 'd:/')", 'd:/')
75tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
Tim Petersd4f7f602001-07-19 19:11:41 +000076
Guido van Rossumead9d8d1999-02-03 17:21:21 +000077if errors:
Tim Petersd4f7f602001-07-19 19:11:41 +000078 raise TestFailed(str(errors) + " errors.")
Tim Peters3b5e4d12001-07-19 19:02:12 +000079elif verbose:
Fred Drake004d5e62000-10-23 17:22:08 +000080 print "No errors. Thank your lucky stars."