2 from 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.splitdrive("c:\\foo\\bar")',
21 tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
22 ('\\\\conky\\mountpoint', '\\foo\\bar'))
23 tester('ntpath.splitdrive("c:/foo/bar")',
25 tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
26 ('//conky/mountpoint', '/foo/bar'))
28 tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
29 tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
30 ('\\\\conky\\mountpoint\\foo', 'bar'))
32 tester('ntpath.split("c:\\")', ('c:\\', ''))
33 tester('ntpath.split("\\\\conky\\mountpoint\\")',
34 ('\\\\conky\\mountpoint', ''))
36 tester('ntpath.split("c:/")', ('c:/', ''))
37 tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
39 tester('ntpath.isabs("c:\\")', 1)
40 tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
41 tester('ntpath.isabs("\\foo")', 1)
42 tester('ntpath.isabs("\\foo\\bar")', 1)
44 tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
46 tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
48 tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
51 tester('ntpath.join("")', '')
52 tester('ntpath.join("", "", "")', '')
53 tester('ntpath.join("a")', 'a')
54 tester('ntpath.join("/a")', '/a')
55 tester('ntpath.join("\\a")', '\\a')
56 tester('ntpath.join("a:")', 'a:')
57 tester('ntpath.join("a:", "b")', 'a:b')
58 tester('ntpath.join("a:", "/b")', 'a:/b')
59 tester('ntpath.join("a:", "\\b")', 'a:\\b')
60 tester('ntpath.join("a", "/b")', '/b')
61 tester('ntpath.join("a", "\\b")', '\\b')
62 tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
63 tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
64 tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
65 tester('ntpath.join("a", "b", "\\c")', '\\c')
66 tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
67 tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
68 tester("ntpath.join('c:', '/a')", 'c:/a')
69 tester("ntpath.join('c:/', '/a')", 'c:/a')
70 tester("ntpath.join('c:/a', '/b')", '/b')
71 tester("ntpath.join('c:', 'd:/')", 'd:/')
72 tester("ntpath.join('c:/', 'd:/')", 'd:/')
73 tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
75 tester("ntpath.join('')", '')
76 tester("ntpath.join('', '', '', '', '')", '')
77 tester("ntpath.join('a')", 'a')
78 tester("ntpath.join('', 'a')", 'a')
79 tester("ntpath.join('', '', '', '', 'a')", 'a')
80 tester("ntpath.join('a', '')", 'a\\')
81 tester("ntpath.join('a', '', '', '', '')", 'a\\')
82 tester("ntpath.join('a\\', '')", 'a\\')
83 tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
85 tester("ntpath.normpath('A//////././//.//B')", r
'A\B')
86 tester("ntpath.normpath('A/./B')", r
'A\B')
87 tester("ntpath.normpath('A/foo/../B')", r
'A\B')
88 tester("ntpath.normpath('C:A//B')", r
'C:A\B')
89 tester("ntpath.normpath('D:A/./B')", r
'D:A\B')
90 tester("ntpath.normpath('e:A/foo/../B')", r
'e:A\B')
92 # Next 3 seem dubious, and especially the 3rd, but normpath is possibly
93 # trying to leave UNC paths alone without actually knowing anything about
95 tester("ntpath.normpath('C:///A//B')", r
'C:\\\A\B')
96 tester("ntpath.normpath('D:///A/./B')", r
'D:\\\A\B')
97 tester("ntpath.normpath('e:///A/foo/../B')", r
'e:\\\A\B')
99 tester("ntpath.normpath('..')", r
'..')
100 tester("ntpath.normpath('.')", r
'.')
101 tester("ntpath.normpath('')", r
'.')
102 tester("ntpath.normpath('/')", '\\')
103 tester("ntpath.normpath('c:/')", 'c:\\')
104 tester("ntpath.normpath('/../.././..')", '\\')
105 tester("ntpath.normpath('c:/../../..')", 'c:\\')
106 tester("ntpath.normpath('../.././..')", r
'..\..\..')
107 tester("ntpath.normpath('K:../.././..')", r
'K:..\..\..')
109 # ntpath.abspath() can only be used on a system with the "nt" module
110 # (reasonably), so we protect this test with "import nt". This allows
111 # the rest of the tests for the ntpath module to be run to completion
112 # on any platform, since most of the module is intended to be usable
119 tester('ntpath.abspath("C:\\")', "C:\\")
122 raise TestFailed(str(errors
) + " errors.")
124 print "No errors. Thank your lucky stars."