Back to index

python3.2  3.2.2
Public Member Functions
test.test_ntpath.TestNtpath Class Reference

List of all members.

Public Member Functions

def test_splitext
def test_splitdrive
def test_split
def test_isabs
def test_commonprefix
def test_join
def test_normpath
def test_expandvars
def test_abspath
def test_relpath
def test_sameopenfile

Detailed Description

Definition at line 36 of file test_ntpath.py.


Member Function Documentation

Definition at line 208 of file test_ntpath.py.

00208 
00209     def test_abspath(self):
00210         # ntpath.abspath() can only be used on a system with the "nt" module
00211         # (reasonably), so we protect this test with "import nt".  This allows
00212         # the rest of the tests for the ntpath module to be run to completion
00213         # on any platform, since most of the module is intended to be usable
00214         # from any platform.
00215         try:
00216             import nt
00217             tester('ntpath.abspath("C:\\")', "C:\\")
00218         except ImportError:
00219             pass

Here is the call graph for this function:

Definition at line 85 of file test_ntpath.py.

00085 
00086     def test_commonprefix(self):
00087         tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
00088                "/home/swen")
00089         tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
00090                "\\home\\swen\\")
00091         tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
00092                "/home/swen/spam")

Here is the call graph for this function:

Definition at line 182 of file test_ntpath.py.

00182 
00183     def test_expandvars(self):
00184         with support.EnvironmentVarGuard() as env:
00185             env.clear()
00186             env["foo"] = "bar"
00187             env["{foo"] = "baz1"
00188             env["{foo}"] = "baz2"
00189             tester('ntpath.expandvars("foo")', "foo")
00190             tester('ntpath.expandvars("$foo bar")', "bar bar")
00191             tester('ntpath.expandvars("${foo}bar")', "barbar")
00192             tester('ntpath.expandvars("$[foo]bar")', "$[foo]bar")
00193             tester('ntpath.expandvars("$bar bar")', "$bar bar")
00194             tester('ntpath.expandvars("$?bar")', "$?bar")
00195             tester('ntpath.expandvars("${foo}bar")', "barbar")
00196             tester('ntpath.expandvars("$foo}bar")', "bar}bar")
00197             tester('ntpath.expandvars("${foo")', "${foo")
00198             tester('ntpath.expandvars("${{foo}}")', "baz1}")
00199             tester('ntpath.expandvars("$foo$foo")', "barbar")
00200             tester('ntpath.expandvars("$bar$bar")', "$bar$bar")
00201             tester('ntpath.expandvars("%foo% bar")', "bar bar")
00202             tester('ntpath.expandvars("%foo%bar")', "barbar")
00203             tester('ntpath.expandvars("%foo%%foo%")', "barbar")
00204             tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar")
00205             tester('ntpath.expandvars("%?bar%")', "%?bar%")
00206             tester('ntpath.expandvars("%foo%%bar")', "bar%bar")
00207             tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")

Here is the call graph for this function:

Definition at line 79 of file test_ntpath.py.

00079 
00080     def test_isabs(self):
00081         tester('ntpath.isabs("c:\\")', 1)
00082         tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
00083         tester('ntpath.isabs("\\foo")', 1)
00084         tester('ntpath.isabs("\\foo\\bar")', 1)

Here is the call graph for this function:

Definition at line 93 of file test_ntpath.py.

00093 
00094     def test_join(self):
00095         tester('ntpath.join("")', '')
00096         tester('ntpath.join("", "", "")', '')
00097         tester('ntpath.join("a")', 'a')
00098         tester('ntpath.join("/a")', '/a')
00099         tester('ntpath.join("\\a")', '\\a')
00100         tester('ntpath.join("a:")', 'a:')
00101         tester('ntpath.join("a:", "b")', 'a:b')
00102         tester('ntpath.join("a:", "/b")', 'a:/b')
00103         tester('ntpath.join("a:", "\\b")', 'a:\\b')
00104         tester('ntpath.join("a", "/b")', '/b')
00105         tester('ntpath.join("a", "\\b")', '\\b')
00106         tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
00107         tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
00108         tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
00109         tester('ntpath.join("a", "b", "\\c")', '\\c')
00110         tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
00111         tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
00112         tester("ntpath.join('c:', '/a')", 'c:/a')
00113         tester("ntpath.join('c:/', '/a')", 'c:/a')
00114         tester("ntpath.join('c:/a', '/b')", '/b')
00115         tester("ntpath.join('c:', 'd:/')", 'd:/')
00116         tester("ntpath.join('c:/', 'd:/')", 'd:/')
00117         tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
00118 
00119         tester("ntpath.join('')", '')
00120         tester("ntpath.join('', '', '', '', '')", '')
00121         tester("ntpath.join('a')", 'a')
00122         tester("ntpath.join('', 'a')", 'a')
00123         tester("ntpath.join('', '', '', '', 'a')", 'a')
00124         tester("ntpath.join('a', '')", 'a\\')
00125         tester("ntpath.join('a', '', '', '', '')", 'a\\')
00126         tester("ntpath.join('a\\', '')", 'a\\')
00127         tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
00128 
00129         # from comment in ntpath.join
00130         tester("ntpath.join('c:', '/a')", 'c:/a')
00131         tester("ntpath.join('//computer/share', '/a')", '//computer/share/a')
00132         tester("ntpath.join('c:/', '/a')", 'c:/a')
00133         tester("ntpath.join('//computer/share/', '/a')", '//computer/share/a')
00134         tester("ntpath.join('c:/a', '/b')", '/b')
00135         tester("ntpath.join('//computer/share/a', '/b')", '/b')
00136         tester("ntpath.join('c:', 'd:/')", 'd:/')
00137         tester("ntpath.join('c:', '//computer/share/')", '//computer/share/')
00138         tester("ntpath.join('//computer/share', 'd:/')", 'd:/')
00139         tester("ntpath.join('//computer/share', '//computer/share/')", '//computer/share/')
00140         tester("ntpath.join('c:/', 'd:/')", 'd:/')
00141         tester("ntpath.join('c:/', '//computer/share/')", '//computer/share/')
00142         tester("ntpath.join('//computer/share/', 'd:/')", 'd:/')
00143         tester("ntpath.join('//computer/share/', '//computer/share/')", '//computer/share/')
00144 
00145         tester("ntpath.join('c:', '//computer/share/')", '//computer/share/')
00146         tester("ntpath.join('c:/', '//computer/share/')", '//computer/share/')
00147         tester("ntpath.join('c:/', '//computer/share/a/b')", '//computer/share/a/b')
00148 
00149         tester("ntpath.join('\\\\computer\\share\\', 'a', 'b')", '\\\\computer\\share\\a\\b')
00150         tester("ntpath.join('\\\\computer\\share', 'a', 'b')", '\\\\computer\\share\\a\\b')
00151         tester("ntpath.join('\\\\computer\\share', 'a\\b')", '\\\\computer\\share\\a\\b')
00152         tester("ntpath.join('//computer/share/', 'a', 'b')", '//computer/share/a\\b')
00153         tester("ntpath.join('//computer/share', 'a', 'b')", '//computer/share\\a\\b')
00154         tester("ntpath.join('//computer/share', 'a/b')", '//computer/share\\a/b')

Here is the call graph for this function:

Definition at line 155 of file test_ntpath.py.

00155 
00156     def test_normpath(self):
00157         tester("ntpath.normpath('A//////././//.//B')", r'A\B')
00158         tester("ntpath.normpath('A/./B')", r'A\B')
00159         tester("ntpath.normpath('A/foo/../B')", r'A\B')
00160         tester("ntpath.normpath('C:A//B')", r'C:A\B')
00161         tester("ntpath.normpath('D:A/./B')", r'D:A\B')
00162         tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
00163 
00164         tester("ntpath.normpath('C:///A//B')", r'C:\A\B')
00165         tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')
00166         tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')
00167 
00168         tester("ntpath.normpath('..')", r'..')
00169         tester("ntpath.normpath('.')", r'.')
00170         tester("ntpath.normpath('')", r'.')
00171         tester("ntpath.normpath('/')", '\\')
00172         tester("ntpath.normpath('c:/')", 'c:\\')
00173         tester("ntpath.normpath('/../.././..')", '\\')
00174         tester("ntpath.normpath('c:/../../..')", 'c:\\')
00175         tester("ntpath.normpath('../.././..')", r'..\..\..')
00176         tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
00177         tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
00178         tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
00179 
00180         tester("ntpath.normpath('\\\\.\\NUL')", r'\\.\NUL')
00181         tester("ntpath.normpath('\\\\?\\D:/XY\\Z')", r'\\?\D:/XY\Z')

Here is the call graph for this function:

Definition at line 220 of file test_ntpath.py.

00220 
00221     def test_relpath(self):
00222         currentdir = os.path.split(os.getcwd())[-1]
00223         tester('ntpath.relpath("a")', 'a')
00224         tester('ntpath.relpath(os.path.abspath("a"))', 'a')
00225         tester('ntpath.relpath("a/b")', 'a\\b')
00226         tester('ntpath.relpath("../a/b")', '..\\a\\b')
00227         tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
00228         tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
00229         tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
00230         tester('ntpath.relpath("c:/foo/bar/bat", "c:/x/y")', '..\\..\\foo\\bar\\bat')
00231         tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
00232         tester('ntpath.relpath("a", "a")', '.')
00233         tester('ntpath.relpath("/foo/bar/bat", "/x/y/z")', '..\\..\\..\\foo\\bar\\bat')
00234         tester('ntpath.relpath("/foo/bar/bat", "/foo/bar")', 'bat')
00235         tester('ntpath.relpath("/foo/bar/bat", "/")', 'foo\\bar\\bat')
00236         tester('ntpath.relpath("/", "/foo/bar/bat")', '..\\..\\..')
00237         tester('ntpath.relpath("/foo/bar/bat", "/x")', '..\\foo\\bar\\bat')
00238         tester('ntpath.relpath("/x", "/foo/bar/bat")', '..\\..\\..\\x')
00239         tester('ntpath.relpath("/", "/")', '.')
00240         tester('ntpath.relpath("/a", "/a")', '.')
00241         tester('ntpath.relpath("/a/b", "/a/b")', '.')
00242         tester('ntpath.relpath("c:/foo", "C:/FOO")', '.')

Here is the call graph for this function:

Definition at line 243 of file test_ntpath.py.

00243 
00244     def test_sameopenfile(self):
00245         with TemporaryFile() as tf1, TemporaryFile() as tf2:
00246             # Make sure the same file is really the same
00247             self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno()))
00248             # Make sure different files are really different
00249             self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno()))
00250             # Make sure invalid values don't cause issues on win32
00251             if sys.platform == "win32":
00252                 with self.assertRaises(OSError):
00253                     # Invalid file descriptors shouldn't display assert
00254                     # dialogs (#4804)
00255                     ntpath.sameopenfile(-1, -1)
00256 

Here is the call graph for this function:

Definition at line 67 of file test_ntpath.py.

00067 
00068     def test_split(self):
00069         tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
00070         tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
00071                ('\\\\conky\\mountpoint\\foo', 'bar'))
00072 
00073         tester('ntpath.split("c:\\")', ('c:\\', ''))
00074         tester('ntpath.split("\\\\conky\\mountpoint\\")',
00075                ('\\\\conky\\mountpoint\\', ''))
00076 
00077         tester('ntpath.split("c:/")', ('c:/', ''))
00078         tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint/', ''))

Here is the call graph for this function:

Definition at line 49 of file test_ntpath.py.

00049 
00050     def test_splitdrive(self):
00051         tester('ntpath.splitdrive("c:\\foo\\bar")',
00052                ('c:', '\\foo\\bar'))
00053         tester('ntpath.splitdrive("c:/foo/bar")',
00054                ('c:', '/foo/bar'))
00055         tester('ntpath.splitdrive("\\\\conky\\mountpoint\\foo\\bar")',
00056                ('\\\\conky\\mountpoint', '\\foo\\bar'))
00057         tester('ntpath.splitdrive("//conky/mountpoint/foo/bar")',
00058                ('//conky/mountpoint', '/foo/bar'))
00059         tester('ntpath.splitdrive("\\\\\\conky\\mountpoint\\foo\\bar")',
00060             ('', '\\\\\\conky\\mountpoint\\foo\\bar'))
00061         tester('ntpath.splitdrive("///conky/mountpoint/foo/bar")',
00062             ('', '///conky/mountpoint/foo/bar'))
00063         tester('ntpath.splitdrive("\\\\conky\\\\mountpoint\\foo\\bar")',
00064                ('', '\\\\conky\\\\mountpoint\\foo\\bar'))
00065         tester('ntpath.splitdrive("//conky//mountpoint/foo/bar")',
00066                ('', '//conky//mountpoint/foo/bar'))

Here is the call graph for this function:

Definition at line 37 of file test_ntpath.py.

00037 
00038     def test_splitext(self):
00039         tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
00040         tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
00041         tester('ntpath.splitext(".ext")', ('.ext', ''))
00042         tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
00043         tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
00044         tester('ntpath.splitext("")', ('', ''))
00045         tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
00046         tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
00047         tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
00048         tester('ntpath.splitext("c:a/b\\c.d")', ('c:a/b\\c', '.d'))

Here is the call graph for this function:


The documentation for this class was generated from the following file: