Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_ntpath.NtCommonTest Class Reference
Inheritance diagram for test.test_ntpath.NtCommonTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_ntpath.NtCommonTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_normcase
def test_splitdrive
def test_expandvars
def test_abspath
def test_realpath
def test_normpath_issue5827
def test_abspath_issue3426
def test_nonascii_abspath
def test_no_argument
def test_commonprefix
def test_getsize
def test_time
def test_exists
def test_isdir
def test_isfile

Static Public Attributes

 pathmodule = ntpath
list attributes = ['relpath', 'splitunc']
list common_attributes

Detailed Description

Definition at line 257 of file test_ntpath.py.


Member Function Documentation

Definition at line 259 of file test_genericpath.py.

00259 
00260     def test_abspath(self):
00261         self.assertIn("foo", self.pathmodule.abspath("foo"))
00262         self.assertIn(b"foo", self.pathmodule.abspath(b"foo"))
00263 
00264         # Abspath returns bytes when the arg is bytes
00265         for path in (b'', b'foo', b'f\xf2\xf2', b'/foo', b'C:\\'):
00266             self.assertIsInstance(self.pathmodule.abspath(path), bytes)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 276 of file test_genericpath.py.

00276 
00277     def test_abspath_issue3426(self):
00278         # Check that abspath returns unicode when the arg is unicode
00279         # with both ASCII and non-ASCII cwds.
00280         abspath = self.pathmodule.abspath
00281         for path in ('', 'fuu', 'f\xf9\xf9', '/fuu', 'U:\\'):
00282             self.assertIsInstance(abspath(path), str)
00283 
00284         unicwd = '\xe7w\xf0'
00285         try:
00286             fsencoding = support.TESTFN_ENCODING or "ascii"
00287             unicwd.encode(fsencoding)
00288         except (AttributeError, UnicodeEncodeError):
00289             # FS encoding is probably ASCII
00290             pass
00291         else:
00292             with support.temp_cwd(unicwd):
00293                 for path in ('', 'fuu', 'f\xf9\xf9', '/fuu', 'U:\\'):
00294                     self.assertIsInstance(abspath(path), str)

Here is the call graph for this function:

Definition at line 33 of file test_genericpath.py.

00033 
00034     def test_commonprefix(self):
00035         commonprefix = self.pathmodule.commonprefix
00036         self.assertEqual(
00037             commonprefix([]),
00038             ""
00039         )
00040         self.assertEqual(
00041             commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
00042             "/home/swen"
00043         )
00044         self.assertEqual(
00045             commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
00046             "/home/swen/"
00047         )
00048         self.assertEqual(
00049             commonprefix(["/home/swen/spam", "/home/swen/spam"]),
00050             "/home/swen/spam"
00051         )
00052         self.assertEqual(
00053             commonprefix(["home:swenson:spam", "home:swen:spam"]),
00054             "home:swen"
00055         )
00056         self.assertEqual(
00057             commonprefix([":home:swen:spam", ":home:swen:eggs"]),
00058             ":home:swen:"
00059         )
00060         self.assertEqual(
00061             commonprefix([":home:swen:spam", ":home:swen:spam"]),
00062             ":home:swen:spam"
00063         )
00064 
00065         self.assertEqual(
00066             commonprefix([b"/home/swenson/spam", b"/home/swen/spam"]),
00067             b"/home/swen"
00068         )
00069         self.assertEqual(
00070             commonprefix([b"/home/swen/spam", b"/home/swen/eggs"]),
00071             b"/home/swen/"
00072         )
00073         self.assertEqual(
00074             commonprefix([b"/home/swen/spam", b"/home/swen/spam"]),
00075             b"/home/swen/spam"
00076         )
00077         self.assertEqual(
00078             commonprefix([b"home:swenson:spam", b"home:swen:spam"]),
00079             b"home:swen"
00080         )
00081         self.assertEqual(
00082             commonprefix([b":home:swen:spam", b":home:swen:eggs"]),
00083             b":home:swen:"
00084         )
00085         self.assertEqual(
00086             commonprefix([b":home:swen:spam", b":home:swen:spam"]),
00087             b":home:swen:spam"
00088         )
00089 
00090         testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd',
00091                     'aXc', 'abd', 'ab', 'aX', 'abcX']
00092         for s1 in testlist:
00093             for s2 in testlist:
00094                 p = commonprefix([s1, s2])
00095                 self.assertTrue(s1.startswith(p))
00096                 self.assertTrue(s2.startswith(p))
00097                 if s1 != s2:
00098                     n = len(p)
00099                     self.assertNotEqual(s1[n:n+1], s2[n:n+1])

Here is the call graph for this function:

Definition at line 133 of file test_genericpath.py.

00133 
00134     def test_exists(self):
00135         self.assertIs(self.pathmodule.exists(support.TESTFN), False)
00136         f = open(support.TESTFN, "wb")
00137         try:
00138             f.write(b"foo")
00139             f.close()
00140             self.assertIs(self.pathmodule.exists(support.TESTFN), True)
00141             if not self.pathmodule == genericpath:
00142                 self.assertIs(self.pathmodule.lexists(support.TESTFN),
00143                               True)
00144         finally:
00145             if not f.close():
00146                 f.close()
00147             support.unlink(support.TESTFN)

Here is the call graph for this function:

Definition at line 224 of file test_genericpath.py.

00224 
00225     def test_expandvars(self):
00226         if self.pathmodule.__name__ == 'macpath':
00227             self.skipTest('macpath.expandvars is a stub')
00228         expandvars = self.pathmodule.expandvars
00229         with support.EnvironmentVarGuard() as env:
00230             env.clear()
00231             env["foo"] = "bar"
00232             env["{foo"] = "baz1"
00233             env["{foo}"] = "baz2"
00234             self.assertEqual(expandvars("foo"), "foo")
00235             self.assertEqual(expandvars("$foo bar"), "bar bar")
00236             self.assertEqual(expandvars("${foo}bar"), "barbar")
00237             self.assertEqual(expandvars("$[foo]bar"), "$[foo]bar")
00238             self.assertEqual(expandvars("$bar bar"), "$bar bar")
00239             self.assertEqual(expandvars("$?bar"), "$?bar")
00240             self.assertEqual(expandvars("${foo}bar"), "barbar")
00241             self.assertEqual(expandvars("$foo}bar"), "bar}bar")
00242             self.assertEqual(expandvars("${foo"), "${foo")
00243             self.assertEqual(expandvars("${{foo}}"), "baz1}")
00244             self.assertEqual(expandvars("$foo$foo"), "barbar")
00245             self.assertEqual(expandvars("$bar$bar"), "$bar$bar")
00246 
00247             self.assertEqual(expandvars(b"foo"), b"foo")
00248             self.assertEqual(expandvars(b"$foo bar"), b"bar bar")
00249             self.assertEqual(expandvars(b"${foo}bar"), b"barbar")
00250             self.assertEqual(expandvars(b"$[foo]bar"), b"$[foo]bar")
00251             self.assertEqual(expandvars(b"$bar bar"), b"$bar bar")
00252             self.assertEqual(expandvars(b"$?bar"), b"$?bar")
00253             self.assertEqual(expandvars(b"${foo}bar"), b"barbar")
00254             self.assertEqual(expandvars(b"$foo}bar"), b"bar}bar")
00255             self.assertEqual(expandvars(b"${foo"), b"${foo")
00256             self.assertEqual(expandvars(b"${{foo}}"), b"baz1}")
00257             self.assertEqual(expandvars(b"$foo$foo"), b"barbar")
00258             self.assertEqual(expandvars(b"$bar$bar"), b"$bar$bar")

Here is the call graph for this function:

Definition at line 100 of file test_genericpath.py.

00100 
00101     def test_getsize(self):
00102         f = open(support.TESTFN, "wb")
00103         try:
00104             f.write(b"foo")
00105             f.close()
00106             self.assertEqual(self.pathmodule.getsize(support.TESTFN), 3)
00107         finally:
00108             if not f.closed:
00109                 f.close()
00110             support.unlink(support.TESTFN)

Here is the call graph for this function:

Definition at line 148 of file test_genericpath.py.

00148 
00149     def test_isdir(self):
00150         self.assertIs(self.pathmodule.isdir(support.TESTFN), False)
00151         f = open(support.TESTFN, "wb")
00152         try:
00153             f.write(b"foo")
00154             f.close()
00155             self.assertIs(self.pathmodule.isdir(support.TESTFN), False)
00156             os.remove(support.TESTFN)
00157             os.mkdir(support.TESTFN)
00158             self.assertIs(self.pathmodule.isdir(support.TESTFN), True)
00159             os.rmdir(support.TESTFN)
00160         finally:
00161             if not f.close():
00162                 f.close()
00163             support.unlink(support.TESTFN)
00164             safe_rmdir(support.TESTFN)

Here is the call graph for this function:

Definition at line 165 of file test_genericpath.py.

00165 
00166     def test_isfile(self):
00167         self.assertIs(self.pathmodule.isfile(support.TESTFN), False)
00168         f = open(support.TESTFN, "wb")
00169         try:
00170             f.write(b"foo")
00171             f.close()
00172             self.assertIs(self.pathmodule.isfile(support.TESTFN), True)
00173             os.remove(support.TESTFN)
00174             os.mkdir(support.TESTFN)
00175             self.assertIs(self.pathmodule.isfile(support.TESTFN), False)
00176             os.rmdir(support.TESTFN)
00177         finally:
00178             if not f.close():
00179                 f.close()
00180             support.unlink(support.TESTFN)
00181             safe_rmdir(support.TESTFN)
00182 
00183 
00184 # Following TestCase is not supposed to be run from test_genericpath.
00185 # It is inherited by other test modules (macpath, ntpath, posixpath).

Here is the call graph for this function:

Definition at line 26 of file test_genericpath.py.

00026 
00027     def test_no_argument(self):
00028         for attr in self.common_attributes + self.attributes:
00029             with self.assertRaises(TypeError):
00030                 getattr(self.pathmodule, attr)()
00031                 raise self.fail("{}.{}() did not raise a TypeError"
00032                                 .format(self.pathmodule.__name__, attr))

Here is the call graph for this function:

Definition at line 297 of file test_genericpath.py.

00297 
00298     def test_nonascii_abspath(self):
00299         # Test non-ASCII, non-UTF8 bytes in the path.
00300         with support.temp_cwd(b'\xe7w\xf0'):
00301             self.test_abspath()
00302 

Here is the call graph for this function:

Definition at line 199 of file test_genericpath.py.

00199 
00200     def test_normcase(self):
00201         normcase = self.pathmodule.normcase
00202         # check that normcase() is idempotent
00203         for p in ["FoO/./BaR", b"FoO/./BaR"]:
00204             p = normcase(p)
00205             self.assertEqual(p, normcase(p))
00206 
00207         self.assertEqual(normcase(''), '')
00208         self.assertEqual(normcase(b''), b'')
00209 
00210         # check that normcase raises a TypeError for invalid types
00211         for path in (None, True, 0, 2.5, [], bytearray(b''), {'o','o'}):
00212             self.assertRaises(TypeError, normcase, path)

Here is the call graph for this function:

Definition at line 271 of file test_genericpath.py.

00271 
00272     def test_normpath_issue5827(self):
00273         # Make sure normpath preserves unicode
00274         for path in ('', '.', '/', '\\', '///foo/.//bar//'):
00275             self.assertIsInstance(self.pathmodule.normpath(path), str)

Here is the call graph for this function:

Definition at line 267 of file test_genericpath.py.

00267 
00268     def test_realpath(self):
00269         self.assertIn("foo", self.pathmodule.realpath("foo"))
00270         self.assertIn(b"foo", self.pathmodule.realpath(b"foo"))

Here is the call graph for this function:

Definition at line 213 of file test_genericpath.py.

00213 
00214     def test_splitdrive(self):
00215         # splitdrive for non-NT paths
00216         splitdrive = self.pathmodule.splitdrive
00217         self.assertEqual(splitdrive("/foo/bar"), ("", "/foo/bar"))
00218         self.assertEqual(splitdrive("foo:bar"), ("", "foo:bar"))
00219         self.assertEqual(splitdrive(":foo:bar"), ("", ":foo:bar"))
00220 
00221         self.assertEqual(splitdrive(b"/foo/bar"), (b"", b"/foo/bar"))
00222         self.assertEqual(splitdrive(b"foo:bar"), (b"", b"foo:bar"))
00223         self.assertEqual(splitdrive(b":foo:bar"), (b"", b":foo:bar"))

Here is the call graph for this function:

def test.test_genericpath.GenericTest.test_time (   self) [inherited]

Definition at line 111 of file test_genericpath.py.

00111 
00112     def test_time(self):
00113         f = open(support.TESTFN, "wb")
00114         try:
00115             f.write(b"foo")
00116             f.close()
00117             f = open(support.TESTFN, "ab")
00118             f.write(b"bar")
00119             f.close()
00120             f = open(support.TESTFN, "rb")
00121             d = f.read()
00122             f.close()
00123             self.assertEqual(d, b"foobar")
00124 
00125             self.assertLessEqual(
00126                 self.pathmodule.getctime(support.TESTFN),
00127                 self.pathmodule.getmtime(support.TESTFN)
00128             )
00129         finally:
00130             if not f.closed:
00131                 f.close()
00132             support.unlink(support.TESTFN)

Here is the call graph for this function:


Member Data Documentation

list test.test_ntpath.NtCommonTest.attributes = ['relpath', 'splitunc'] [static]

Reimplemented from test.test_genericpath.GenericTest.

Definition at line 259 of file test_ntpath.py.

Initial value:
GenericTest.common_attributes+[
        # Properties
        'curdir', 'pardir', 'extsep', 'sep',
        'pathsep', 'defpath', 'altsep', 'devnull',
        # Methods
        'normcase', 'splitdrive', 'expandvars', 'normpath', 'abspath',
        'join', 'split', 'splitext', 'isabs', 'basename', 'dirname',
        'lexists', 'islink', 'ismount', 'expanduser', 'normpath', 'realpath',
    ]

Reimplemented from test.test_genericpath.GenericTest.

Definition at line 189 of file test_genericpath.py.

Reimplemented from test.test_genericpath.CommonTest.

Definition at line 258 of file test_ntpath.py.


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