annotate Lib/test/test_genericpath.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 1da7733e8f24
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
1 """
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
2 Tests common to genericpath, macpath, ntpath and posixpath
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
3 """
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
4
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
5 import unittest
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
6 from test import test_support
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
7 import os
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
8 import genericpath
61548
68bc35775d31 Issue #8422, test_genericpath: skip the creation of a directory with an invalid
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59468
diff changeset
9 import sys
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
10
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
11
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
12 def safe_rmdir(dirname):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
13 try:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
14 os.rmdir(dirname)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
15 except OSError:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
16 pass
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
17
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
18
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
19 class GenericTest(unittest.TestCase):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
20 # The path module to be tested
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
21 pathmodule = genericpath
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
22 common_attributes = ['commonprefix', 'getsize', 'getatime', 'getctime',
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
23 'getmtime', 'exists', 'isdir', 'isfile']
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
24 attributes = []
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
25
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
26 def test_no_argument(self):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
27 for attr in self.common_attributes + self.attributes:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
28 with self.assertRaises(TypeError):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
29 getattr(self.pathmodule, attr)()
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
30 raise self.fail("{}.{}() did not raise a TypeError"
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
31 .format(self.pathmodule.__name__, attr))
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
32
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
33 def test_commonprefix(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
34 commonprefix = self.pathmodule.commonprefix
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
35 self.assertEqual(
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
36 commonprefix([]),
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
37 ""
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
38 )
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
39 self.assertEqual(
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
40 commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
41 "/home/swen"
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
42 )
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
43 self.assertEqual(
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
44 commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
45 "/home/swen/"
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
46 )
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
47 self.assertEqual(
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
48 commonprefix(["/home/swen/spam", "/home/swen/spam"]),
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
49 "/home/swen/spam"
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
50 )
59468
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
51 self.assertEqual(
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
52 commonprefix(["home:swenson:spam", "home:swen:spam"]),
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
53 "home:swen"
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
54 )
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
55 self.assertEqual(
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
56 commonprefix([":home:swen:spam", ":home:swen:eggs"]),
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
57 ":home:swen:"
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
58 )
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
59 self.assertEqual(
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
60 commonprefix([":home:swen:spam", ":home:swen:spam"]),
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
61 ":home:swen:spam"
14616df92407 Move some tests from test_macpath to test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59409
diff changeset
62 )
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
63
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
64 testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd',
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
65 'aXc', 'abd', 'ab', 'aX', 'abcX']
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
66 for s1 in testlist:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
67 for s2 in testlist:
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
68 p = commonprefix([s1, s2])
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
69 self.assertTrue(s1.startswith(p))
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
70 self.assertTrue(s2.startswith(p))
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
71 if s1 != s2:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
72 n = len(p)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
73 self.assertNotEqual(s1[n:n+1], s2[n:n+1])
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
74
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
75 def test_getsize(self):
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
76 f = open(test_support.TESTFN, "wb")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
77 try:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
78 f.write("foo")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
79 f.close()
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
80 self.assertEqual(self.pathmodule.getsize(test_support.TESTFN), 3)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
81 finally:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
82 if not f.closed:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
83 f.close()
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
84 test_support.unlink(test_support.TESTFN)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
85
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
86 def test_time(self):
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
87 f = open(test_support.TESTFN, "wb")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
88 try:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
89 f.write("foo")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
90 f.close()
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
91 f = open(test_support.TESTFN, "ab")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
92 f.write("bar")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
93 f.close()
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
94 f = open(test_support.TESTFN, "rb")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
95 d = f.read()
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
96 f.close()
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
97 self.assertEqual(d, "foobar")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
98
58965
3a7132f65623 Remove e assertIs definitions and use correct assert* methods.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55002
diff changeset
99 self.assertLessEqual(
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
100 self.pathmodule.getctime(test_support.TESTFN),
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
101 self.pathmodule.getmtime(test_support.TESTFN)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
102 )
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
103 finally:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
104 if not f.closed:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
105 f.close()
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
106 test_support.unlink(test_support.TESTFN)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
107
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
108 def test_exists(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
109 self.assertIs(self.pathmodule.exists(test_support.TESTFN), False)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
110 f = open(test_support.TESTFN, "wb")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
111 try:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
112 f.write("foo")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
113 f.close()
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
114 self.assertIs(self.pathmodule.exists(test_support.TESTFN), True)
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
115 if not self.pathmodule == genericpath:
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
116 self.assertIs(self.pathmodule.lexists(test_support.TESTFN),
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
117 True)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
118 finally:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
119 if not f.close():
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
120 f.close()
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
121 test_support.unlink(test_support.TESTFN)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
122
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
123 def test_isdir(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
124 self.assertIs(self.pathmodule.isdir(test_support.TESTFN), False)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
125 f = open(test_support.TESTFN, "wb")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
126 try:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
127 f.write("foo")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
128 f.close()
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
129 self.assertIs(self.pathmodule.isdir(test_support.TESTFN), False)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
130 os.remove(test_support.TESTFN)
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
131 os.mkdir(test_support.TESTFN)
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
132 self.assertIs(self.pathmodule.isdir(test_support.TESTFN), True)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
133 os.rmdir(test_support.TESTFN)
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
134 finally:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
135 if not f.close():
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
136 f.close()
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
137 test_support.unlink(test_support.TESTFN)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
138 safe_rmdir(test_support.TESTFN)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
139
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
140 def test_isfile(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
141 self.assertIs(self.pathmodule.isfile(test_support.TESTFN), False)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
142 f = open(test_support.TESTFN, "wb")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
143 try:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
144 f.write("foo")
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
145 f.close()
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
146 self.assertIs(self.pathmodule.isfile(test_support.TESTFN), True)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
147 os.remove(test_support.TESTFN)
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
148 os.mkdir(test_support.TESTFN)
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
149 self.assertIs(self.pathmodule.isfile(test_support.TESTFN), False)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
150 os.rmdir(test_support.TESTFN)
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
151 finally:
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
152 if not f.close():
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
153 f.close()
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
154 test_support.unlink(test_support.TESTFN)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
155 safe_rmdir(test_support.TESTFN)
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
156
58971
dcda985c6403 skip tests with a non-ascii cwd when the file system encoding is ascii
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58965
diff changeset
157
62386
1da7733e8f24 Add few words about test.test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 61550
diff changeset
158 # Following TestCase is not supposed to be run from test_genericpath.
1da7733e8f24 Add few words about test.test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 61550
diff changeset
159 # It is inherited by other test modules (macpath, ntpath, posixpath).
1da7733e8f24 Add few words about test.test_genericpath.CommonTest
Florent Xicluna <florent.xicluna@gmail.com>
parents: 61550
diff changeset
160
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
161 class CommonTest(GenericTest):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
162 # The path module to be tested
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
163 pathmodule = None
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
164 common_attributes = GenericTest.common_attributes + [
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
165 # Properties
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
166 'curdir', 'pardir', 'extsep', 'sep',
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
167 'pathsep', 'defpath', 'altsep', 'devnull',
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
168 # Methods
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
169 'normcase', 'splitdrive', 'expandvars', 'normpath', 'abspath',
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
170 'join', 'split', 'splitext', 'isabs', 'basename', 'dirname',
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
171 'lexists', 'islink', 'ismount', 'expanduser', 'normpath', 'realpath',
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
172 ]
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
173
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
174 def test_normcase(self):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
175 # Check that normcase() is idempotent
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
176 p = "FoO/./BaR"
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
177 p = self.pathmodule.normcase(p)
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
178 self.assertEqual(p, self.pathmodule.normcase(p))
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
179
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
180 def test_splitdrive(self):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
181 # splitdrive for non-NT paths
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
182 splitdrive = self.pathmodule.splitdrive
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
183 self.assertEqual(splitdrive("/foo/bar"), ("", "/foo/bar"))
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
184 self.assertEqual(splitdrive("foo:bar"), ("", "foo:bar"))
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
185 self.assertEqual(splitdrive(":foo:bar"), ("", ":foo:bar"))
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
186
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
187 def test_expandvars(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
188 if self.pathmodule.__name__ == 'macpath':
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
189 self.skipTest('macpath.expandvars is a stub')
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
190 expandvars = self.pathmodule.expandvars
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
191 with test_support.EnvironmentVarGuard() as env:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
192 env.clear()
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
193 env["foo"] = "bar"
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
194 env["{foo"] = "baz1"
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
195 env["{foo}"] = "baz2"
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
196 self.assertEqual(expandvars("foo"), "foo")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
197 self.assertEqual(expandvars("$foo bar"), "bar bar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
198 self.assertEqual(expandvars("${foo}bar"), "barbar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
199 self.assertEqual(expandvars("$[foo]bar"), "$[foo]bar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
200 self.assertEqual(expandvars("$bar bar"), "$bar bar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
201 self.assertEqual(expandvars("$?bar"), "$?bar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
202 self.assertEqual(expandvars("${foo}bar"), "barbar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
203 self.assertEqual(expandvars("$foo}bar"), "bar}bar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
204 self.assertEqual(expandvars("${foo"), "${foo")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
205 self.assertEqual(expandvars("${{foo}}"), "baz1}")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
206 self.assertEqual(expandvars("$foo$foo"), "barbar")
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
207 self.assertEqual(expandvars("$bar$bar"), "$bar$bar")
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
208
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
209 def test_abspath(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
210 self.assertIn("foo", self.pathmodule.abspath("foo"))
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
211
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
212 # Abspath returns bytes when the arg is bytes
58971
dcda985c6403 skip tests with a non-ascii cwd when the file system encoding is ascii
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58965
diff changeset
213 for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
214 self.assertIsInstance(self.pathmodule.abspath(path), str)
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
215
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
216 def test_realpath(self):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
217 self.assertIn("foo", self.pathmodule.realpath("foo"))
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
218
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
219 def test_normpath_issue5827(self):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
220 # Make sure normpath preserves unicode
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
221 for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
222 self.assertIsInstance(self.pathmodule.normpath(path), unicode)
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
223
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
224 def test_abspath_issue3426(self):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
225 # Check that abspath returns unicode when the arg is unicode
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
226 # with both ASCII and non-ASCII cwds.
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
227 abspath = self.pathmodule.abspath
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
228 for path in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
229 self.assertIsInstance(abspath(path), unicode)
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
230
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
231 unicwd = u'\xe7w\xf0'
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
232 try:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
233 fsencoding = test_support.TESTFN_ENCODING or "ascii"
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
234 unicwd.encode(fsencoding)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
235 except (AttributeError, UnicodeEncodeError):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
236 # FS encoding is probably ASCII
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
237 pass
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
238 else:
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
239 with test_support.temp_cwd(unicwd):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
240 for path in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
241 self.assertIsInstance(abspath(path), unicode)
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
242
61548
68bc35775d31 Issue #8422, test_genericpath: skip the creation of a directory with an invalid
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59468
diff changeset
243 @unittest.skipIf(sys.platform == 'darwin',
61550
eba49478aad9 Fix verb tense in skip message.
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61548
diff changeset
244 "Mac OS X denies the creation of a directory with an invalid utf8 name")
61548
68bc35775d31 Issue #8422, test_genericpath: skip the creation of a directory with an invalid
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59468
diff changeset
245 def test_nonascii_abspath(self):
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
246 # Test non-ASCII, non-UTF8 bytes in the path.
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
247 with test_support.temp_cwd('\xe7w\xf0'):
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
248 self.test_abspath()
58971
dcda985c6403 skip tests with a non-ascii cwd when the file system encoding is ascii
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58965
diff changeset
249
dcda985c6403 skip tests with a non-ascii cwd when the file system encoding is ascii
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58965
diff changeset
250
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
251 def test_main():
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
252 test_support.run_unittest(GenericTest)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
253
39689
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
254
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
255 if __name__=="__main__":
d0ed7dbaad56 - Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff changeset
256 test_main()