Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / test / test_ntpath.py
CommitLineData
920dae64
AT
1import ntpath
2from test.test_support import verbose, TestFailed
3import os
4
5errors = 0
6
7def tester(fn, wantResult):
8 global errors
9 fn = fn.replace("\\", "\\\\")
10 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 ""
17 errors = errors + 1
18
19tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
20tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
21tester('ntpath.splitext(".ext")', ('', '.ext'))
22tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
23tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
24tester('ntpath.splitext("")', ('', ''))
25tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
26tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
27tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
28
29tester('ntpath.splitdrive("c:\\foo\\bar")',
30 ('c:', '\\foo\\bar'))
31tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
32 ('\\\\conky\\mountpoint', '\\foo\\bar'))
33tester('ntpath.splitdrive("c:/foo/bar")',
34 ('c:', '/foo/bar'))
35tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
36 ('//conky/mountpoint', '/foo/bar'))
37
38tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
39tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
40 ('\\\\conky\\mountpoint\\foo', 'bar'))
41
42tester('ntpath.split("c:\\")', ('c:\\', ''))
43tester('ntpath.split("\\\\conky\\mountpoint\\")',
44 ('\\\\conky\\mountpoint', ''))
45
46tester('ntpath.split("c:/")', ('c:/', ''))
47tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
48
49tester('ntpath.isabs("c:\\")', 1)
50tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
51tester('ntpath.isabs("\\foo")', 1)
52tester('ntpath.isabs("\\foo\\bar")', 1)
53
54tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
55 "/home/swen")
56tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
57 "\\home\\swen\\")
58tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
59 "/home/swen/spam")
60
61tester('ntpath.join("")', '')
62tester('ntpath.join("", "", "")', '')
63tester('ntpath.join("a")', 'a')
64tester('ntpath.join("/a")', '/a')
65tester('ntpath.join("\\a")', '\\a')
66tester('ntpath.join("a:")', 'a:')
67tester('ntpath.join("a:", "b")', 'a:b')
68tester('ntpath.join("a:", "/b")', 'a:/b')
69tester('ntpath.join("a:", "\\b")', 'a:\\b')
70tester('ntpath.join("a", "/b")', '/b')
71tester('ntpath.join("a", "\\b")', '\\b')
72tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
73tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
74tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
75tester('ntpath.join("a", "b", "\\c")', '\\c')
76tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
77tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
78tester("ntpath.join('c:', '/a')", 'c:/a')
79tester("ntpath.join('c:/', '/a')", 'c:/a')
80tester("ntpath.join('c:/a', '/b')", '/b')
81tester("ntpath.join('c:', 'd:/')", 'd:/')
82tester("ntpath.join('c:/', 'd:/')", 'd:/')
83tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
84
85tester("ntpath.join('')", '')
86tester("ntpath.join('', '', '', '', '')", '')
87tester("ntpath.join('a')", 'a')
88tester("ntpath.join('', 'a')", 'a')
89tester("ntpath.join('', '', '', '', 'a')", 'a')
90tester("ntpath.join('a', '')", 'a\\')
91tester("ntpath.join('a', '', '', '', '')", 'a\\')
92tester("ntpath.join('a\\', '')", 'a\\')
93tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
94
95tester("ntpath.normpath('A//////././//.//B')", r'A\B')
96tester("ntpath.normpath('A/./B')", r'A\B')
97tester("ntpath.normpath('A/foo/../B')", r'A\B')
98tester("ntpath.normpath('C:A//B')", r'C:A\B')
99tester("ntpath.normpath('D:A/./B')", r'D:A\B')
100tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
101
102tester("ntpath.normpath('C:///A//B')", r'C:\A\B')
103tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')
104tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')
105
106tester("ntpath.normpath('..')", r'..')
107tester("ntpath.normpath('.')", r'.')
108tester("ntpath.normpath('')", r'.')
109tester("ntpath.normpath('/')", '\\')
110tester("ntpath.normpath('c:/')", 'c:\\')
111tester("ntpath.normpath('/../.././..')", '\\')
112tester("ntpath.normpath('c:/../../..')", 'c:\\')
113tester("ntpath.normpath('../.././..')", r'..\..\..')
114tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
115tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
116tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
117
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
122# from any platform.
123try:
124 import nt
125except ImportError:
126 pass
127else:
128 tester('ntpath.abspath("C:\\")', "C:\\")
129
130if errors:
131 raise TestFailed(str(errors) + " errors.")
132elif verbose:
133 print "No errors. Thank your lucky stars."