2
from test.test_support import verbose, TestFailed
7
def tester(fn, wantResult):
9
fn = fn.replace("\\", "\\\\")
11
if wantResult != gotResult:
13
print "evaluated: " + str(fn)
14
print "should be: " + str(wantResult)
15
print " returned: " + str(gotResult)
19
tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
20
tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
21
tester('ntpath.splitext(".ext")', ('', '.ext'))
22
tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
23
tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
24
tester('ntpath.splitext("")', ('', ''))
25
tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
26
tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
27
tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
29
tester('ntpath.splitdrive("c:\\foo\\bar")',
31
tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
32
('\\\\conky\\mountpoint', '\\foo\\bar'))
33
tester('ntpath.splitdrive("c:/foo/bar")',
35
tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
36
('//conky/mountpoint', '/foo/bar'))
38
tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
39
tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
40
('\\\\conky\\mountpoint\\foo', 'bar'))
42
tester('ntpath.split("c:\\")', ('c:\\', ''))
43
tester('ntpath.split("\\\\conky\\mountpoint\\")',
44
('\\\\conky\\mountpoint', ''))
46
tester('ntpath.split("c:/")', ('c:/', ''))
47
tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
49
tester('ntpath.isabs("c:\\")', 1)
50
tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
51
tester('ntpath.isabs("\\foo")', 1)
52
tester('ntpath.isabs("\\foo\\bar")', 1)
54
tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
56
tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
58
tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
61
tester('ntpath.join("")', '')
62
tester('ntpath.join("", "", "")', '')
63
tester('ntpath.join("a")', 'a')
64
tester('ntpath.join("/a")', '/a')
65
tester('ntpath.join("\\a")', '\\a')
66
tester('ntpath.join("a:")', 'a:')
67
tester('ntpath.join("a:", "b")', 'a:b')
68
tester('ntpath.join("a:", "/b")', 'a:/b')
69
tester('ntpath.join("a:", "\\b")', 'a:\\b')
70
tester('ntpath.join("a", "/b")', '/b')
71
tester('ntpath.join("a", "\\b")', '\\b')
72
tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
73
tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
74
tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
75
tester('ntpath.join("a", "b", "\\c")', '\\c')
76
tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
77
tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
78
tester("ntpath.join('c:', '/a')", 'c:/a')
79
tester("ntpath.join('c:/', '/a')", 'c:/a')
80
tester("ntpath.join('c:/a', '/b')", '/b')
81
tester("ntpath.join('c:', 'd:/')", 'd:/')
82
tester("ntpath.join('c:/', 'd:/')", 'd:/')
83
tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
85
tester("ntpath.join('')", '')
86
tester("ntpath.join('', '', '', '', '')", '')
87
tester("ntpath.join('a')", 'a')
88
tester("ntpath.join('', 'a')", 'a')
89
tester("ntpath.join('', '', '', '', 'a')", 'a')
90
tester("ntpath.join('a', '')", 'a\\')
91
tester("ntpath.join('a', '', '', '', '')", 'a\\')
92
tester("ntpath.join('a\\', '')", 'a\\')
93
tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
95
tester("ntpath.normpath('A//////././//.//B')", r'A\B')
96
tester("ntpath.normpath('A/./B')", r'A\B')
97
tester("ntpath.normpath('A/foo/../B')", r'A\B')
98
tester("ntpath.normpath('C:A//B')", r'C:A\B')
99
tester("ntpath.normpath('D:A/./B')", r'D:A\B')
100
tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
102
tester("ntpath.normpath('C:///A//B')", r'C:\A\B')
103
tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')
104
tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')
106
tester("ntpath.normpath('..')", r'..')
107
tester("ntpath.normpath('.')", r'.')
108
tester("ntpath.normpath('')", r'.')
109
tester("ntpath.normpath('/')", '\\')
110
tester("ntpath.normpath('c:/')", 'c:\\')
111
tester("ntpath.normpath('/../.././..')", '\\')
112
tester("ntpath.normpath('c:/../../..')", 'c:\\')
113
tester("ntpath.normpath('../.././..')", r'..\..\..')
114
tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
115
tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
116
tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
118
# ntpath.abspath() can only be used on a system with the "nt" module
119
# (reasonably), so we protect this test with "import nt". This allows
120
# the rest of the tests for the ntpath module to be run to completion
121
# on any platform, since most of the module is intended to be usable
128
tester('ntpath.abspath("C:\\")', "C:\\")
131
raise TestFailed(str(errors) + " errors.")
133
print "No errors. Thank your lucky stars."