PyXR

c:\python24\lib \ test \ test_ntpath.py



0001 import ntpath
0002 from test.test_support import verbose, TestFailed
0003 import os
0004 
0005 errors = 0
0006 
0007 def tester(fn, wantResult):
0008     global errors
0009     fn = fn.replace("\\", "\\\\")
0010     gotResult = eval(fn)
0011     if wantResult != gotResult:
0012         print "error!"
0013         print "evaluated: " + str(fn)
0014         print "should be: " + str(wantResult)
0015         print " returned: " + str(gotResult)
0016         print ""
0017         errors = errors + 1
0018 
0019 tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
0020 tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
0021 tester('ntpath.splitext(".ext")', ('', '.ext'))
0022 tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
0023 tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
0024 tester('ntpath.splitext("")', ('', ''))
0025 tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
0026 tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
0027 tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
0028 
0029 tester('ntpath.splitdrive("c:\\foo\\bar")',
0030        ('c:', '\\foo\\bar'))
0031 tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
0032        ('\\\\conky\\mountpoint', '\\foo\\bar'))
0033 tester('ntpath.splitdrive("c:/foo/bar")',
0034        ('c:', '/foo/bar'))
0035 tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
0036        ('//conky/mountpoint', '/foo/bar'))
0037 
0038 tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
0039 tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
0040        ('\\\\conky\\mountpoint\\foo', 'bar'))
0041 
0042 tester('ntpath.split("c:\\")', ('c:\\', ''))
0043 tester('ntpath.split("\\\\conky\\mountpoint\\")',
0044        ('\\\\conky\\mountpoint', ''))
0045 
0046 tester('ntpath.split("c:/")', ('c:/', ''))
0047 tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
0048 
0049 tester('ntpath.isabs("c:\\")', 1)
0050 tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
0051 tester('ntpath.isabs("\\foo")', 1)
0052 tester('ntpath.isabs("\\foo\\bar")', 1)
0053 
0054 tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
0055        "/home/swen")
0056 tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
0057        "\\home\\swen\\")
0058 tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
0059        "/home/swen/spam")
0060 
0061 tester('ntpath.join("")', '')
0062 tester('ntpath.join("", "", "")', '')
0063 tester('ntpath.join("a")', 'a')
0064 tester('ntpath.join("/a")', '/a')
0065 tester('ntpath.join("\\a")', '\\a')
0066 tester('ntpath.join("a:")', 'a:')
0067 tester('ntpath.join("a:", "b")', 'a:b')
0068 tester('ntpath.join("a:", "/b")', 'a:/b')
0069 tester('ntpath.join("a:", "\\b")', 'a:\\b')
0070 tester('ntpath.join("a", "/b")', '/b')
0071 tester('ntpath.join("a", "\\b")', '\\b')
0072 tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
0073 tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
0074 tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
0075 tester('ntpath.join("a", "b", "\\c")', '\\c')
0076 tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
0077 tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
0078 tester("ntpath.join('c:', '/a')", 'c:/a')
0079 tester("ntpath.join('c:/', '/a')", 'c:/a')
0080 tester("ntpath.join('c:/a', '/b')", '/b')
0081 tester("ntpath.join('c:', 'd:/')", 'd:/')
0082 tester("ntpath.join('c:/', 'd:/')", 'd:/')
0083 tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
0084 
0085 tester("ntpath.join('')", '')
0086 tester("ntpath.join('', '', '', '', '')", '')
0087 tester("ntpath.join('a')", 'a')
0088 tester("ntpath.join('', 'a')", 'a')
0089 tester("ntpath.join('', '', '', '', 'a')", 'a')
0090 tester("ntpath.join('a', '')", 'a\\')
0091 tester("ntpath.join('a', '', '', '', '')", 'a\\')
0092 tester("ntpath.join('a\\', '')", 'a\\')
0093 tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
0094 
0095 tester("ntpath.normpath('A//////././//.//B')", r'A\B')
0096 tester("ntpath.normpath('A/./B')", r'A\B')
0097 tester("ntpath.normpath('A/foo/../B')", r'A\B')
0098 tester("ntpath.normpath('C:A//B')", r'C:A\B')
0099 tester("ntpath.normpath('D:A/./B')", r'D:A\B')
0100 tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
0101 
0102 tester("ntpath.normpath('C:///A//B')", r'C:\A\B')
0103 tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')
0104 tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')
0105 
0106 tester("ntpath.normpath('..')", r'..')
0107 tester("ntpath.normpath('.')", r'.')
0108 tester("ntpath.normpath('')", r'.')
0109 tester("ntpath.normpath('/')", '\\')
0110 tester("ntpath.normpath('c:/')", 'c:\\')
0111 tester("ntpath.normpath('/../.././..')", '\\')
0112 tester("ntpath.normpath('c:/../../..')", 'c:\\')
0113 tester("ntpath.normpath('../.././..')", r'..\..\..')
0114 tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
0115 tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
0116 tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
0117 
0118 # ntpath.abspath() can only be used on a system with the "nt" module
0119 # (reasonably), so we protect this test with "import nt".  This allows
0120 # the rest of the tests for the ntpath module to be run to completion
0121 # on any platform, since most of the module is intended to be usable
0122 # from any platform.
0123 try:
0124     import nt
0125 except ImportError:
0126     pass
0127 else:
0128     tester('ntpath.abspath("C:\\")', "C:\\")
0129 
0130 if errors:
0131     raise TestFailed(str(errors) + " errors.")
0132 elif verbose:
0133     print "No errors.  Thank your lucky stars."
0134 

Generated by PyXR 0.9.4
SourceForge.net Logo