blob: 295bf491644959b44f873f1b9305ea4ae138a8c6 [file] [log] [blame]
Brett Cannonb47243a2003-06-16 21:54:50 +00001import unittest
Florent Xiclunadc1531c2010-03-06 18:07:18 +00002from test import test_support, test_genericpath
Ezio Melotti9e9af212010-02-20 22:34:21 +00003
Serhiy Storchaka2bd8b222015-02-13 12:02:05 +02004import posixpath
5import os
6import sys
Georg Brandlb86d3fa2010-02-07 12:55:12 +00007from posixpath import realpath, abspath, dirname, basename
Johannes Gijsbers4ec40642004-08-14 15:01:53 +00008
9# An absolute path to a temporary filename for testing. We can't rely on TESTFN
10# being an absolute path, so we need this.
11
12ABSTFN = abspath(test_support.TESTFN)
Skip Montanaroe809b002000-07-12 00:20:08 +000013
Serhiy Storchakac8e75ba2013-02-18 13:32:06 +020014def skip_if_ABSTFN_contains_backslash(test):
15 """
16 On Windows, posixpath.abspath still returns paths with backslashes
17 instead of posix forward slashes. If this is the case, several tests
18 fail, so skip them.
19 """
20 found_backslash = '\\' in ABSTFN
21 msg = "ABSTFN is not a posix path - tests fail"
22 return [test, unittest.skip(msg)(test)][found_backslash]
23
Collin Winterdbead562007-03-10 02:23:40 +000024def safe_rmdir(dirname):
25 try:
26 os.rmdir(dirname)
27 except OSError:
28 pass
29
Brett Cannonb47243a2003-06-16 21:54:50 +000030class PosixPathTest(unittest.TestCase):
Skip Montanaroe809b002000-07-12 00:20:08 +000031
Collin Winterdbead562007-03-10 02:23:40 +000032 def setUp(self):
33 self.tearDown()
34
35 def tearDown(self):
36 for suffix in ["", "1", "2"]:
37 test_support.unlink(test_support.TESTFN + suffix)
38 safe_rmdir(test_support.TESTFN + suffix)
Tim Petersea5962f2007-03-12 18:07:52 +000039
Brett Cannonb47243a2003-06-16 21:54:50 +000040 def test_join(self):
41 self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"), "/bar/baz")
42 self.assertEqual(posixpath.join("/foo", "bar", "baz"), "/foo/bar/baz")
43 self.assertEqual(posixpath.join("/foo/", "bar/", "baz/"), "/foo/bar/baz/")
Skip Montanaroe809b002000-07-12 00:20:08 +000044
Brett Cannonb47243a2003-06-16 21:54:50 +000045 def test_split(self):
46 self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar"))
47 self.assertEqual(posixpath.split("/"), ("/", ""))
48 self.assertEqual(posixpath.split("foo"), ("", "foo"))
49 self.assertEqual(posixpath.split("////foo"), ("////", "foo"))
50 self.assertEqual(posixpath.split("//foo//bar"), ("//foo", "bar"))
51
Martin v. Löwis05c075d2007-03-07 11:04:33 +000052 def splitextTest(self, path, filename, ext):
53 self.assertEqual(posixpath.splitext(path), (filename, ext))
54 self.assertEqual(posixpath.splitext("/" + path), ("/" + filename, ext))
55 self.assertEqual(posixpath.splitext("abc/" + path), ("abc/" + filename, ext))
56 self.assertEqual(posixpath.splitext("abc.def/" + path), ("abc.def/" + filename, ext))
57 self.assertEqual(posixpath.splitext("/abc.def/" + path), ("/abc.def/" + filename, ext))
58 self.assertEqual(posixpath.splitext(path + "/"), (filename + ext + "/", ""))
Brett Cannonb47243a2003-06-16 21:54:50 +000059
Martin v. Löwis05c075d2007-03-07 11:04:33 +000060 def test_splitext(self):
61 self.splitextTest("foo.bar", "foo", ".bar")
62 self.splitextTest("foo.boo.bar", "foo.boo", ".bar")
63 self.splitextTest("foo.boo.biff.bar", "foo.boo.biff", ".bar")
64 self.splitextTest(".csh.rc", ".csh", ".rc")
65 self.splitextTest("nodots", "nodots", "")
66 self.splitextTest(".cshrc", ".cshrc", "")
67 self.splitextTest("...manydots", "...manydots", "")
68 self.splitextTest("...manydots.ext", "...manydots", ".ext")
69 self.splitextTest(".", ".", "")
70 self.splitextTest("..", "..", "")
71 self.splitextTest("........", "........", "")
72 self.splitextTest("", "", "")
Brett Cannonb47243a2003-06-16 21:54:50 +000073
74 def test_isabs(self):
75 self.assertIs(posixpath.isabs(""), False)
76 self.assertIs(posixpath.isabs("/"), True)
77 self.assertIs(posixpath.isabs("/foo"), True)
78 self.assertIs(posixpath.isabs("/foo/bar"), True)
79 self.assertIs(posixpath.isabs("foo/bar"), False)
80
Brett Cannonb47243a2003-06-16 21:54:50 +000081 def test_basename(self):
82 self.assertEqual(posixpath.basename("/foo/bar"), "bar")
83 self.assertEqual(posixpath.basename("/"), "")
84 self.assertEqual(posixpath.basename("foo"), "foo")
85 self.assertEqual(posixpath.basename("////foo"), "foo")
86 self.assertEqual(posixpath.basename("//foo//bar"), "bar")
87
Brett Cannonb47243a2003-06-16 21:54:50 +000088 def test_dirname(self):
89 self.assertEqual(posixpath.dirname("/foo/bar"), "/foo")
90 self.assertEqual(posixpath.dirname("/"), "/")
91 self.assertEqual(posixpath.dirname("foo"), "")
92 self.assertEqual(posixpath.dirname("////foo"), "////")
93 self.assertEqual(posixpath.dirname("//foo//bar"), "//foo")
94
Tim Petersea5962f2007-03-12 18:07:52 +000095 def test_islink(self):
Brett Cannonb47243a2003-06-16 21:54:50 +000096 self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
97 f = open(test_support.TESTFN + "1", "wb")
98 try:
99 f.write("foo")
100 f.close()
101 self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
102 if hasattr(os, "symlink"):
103 os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
104 self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
105 os.remove(test_support.TESTFN + "1")
106 self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
107 self.assertIs(posixpath.exists(test_support.TESTFN + "2"), False)
Johannes Gijsbersae882f72004-08-30 10:19:56 +0000108 self.assertIs(posixpath.lexists(test_support.TESTFN + "2"), True)
Brett Cannonb47243a2003-06-16 21:54:50 +0000109 finally:
110 if not f.close():
111 f.close()
Brett Cannonb47243a2003-06-16 21:54:50 +0000112
Collin Winterdbead562007-03-10 02:23:40 +0000113 def test_samefile(self):
114 f = open(test_support.TESTFN + "1", "wb")
115 try:
116 f.write("foo")
117 f.close()
118 self.assertIs(
119 posixpath.samefile(
120 test_support.TESTFN + "1",
121 test_support.TESTFN + "1"
122 ),
123 True
124 )
Benjamin Peterson8a1a17b2012-11-30 16:12:15 -0500125
126 # If we don't have links, assume that os.stat doesn't return
127 # reasonable inode information and thus, that samefile() doesn't
128 # work.
Collin Winterdbead562007-03-10 02:23:40 +0000129 if hasattr(os, "symlink"):
130 os.symlink(
131 test_support.TESTFN + "1",
132 test_support.TESTFN + "2"
133 )
134 self.assertIs(
135 posixpath.samefile(
136 test_support.TESTFN + "1",
137 test_support.TESTFN + "2"
138 ),
139 True
140 )
141 os.remove(test_support.TESTFN + "2")
142 f = open(test_support.TESTFN + "2", "wb")
143 f.write("bar")
Brett Cannonb47243a2003-06-16 21:54:50 +0000144 f.close()
145 self.assertIs(
146 posixpath.samefile(
147 test_support.TESTFN + "1",
Brett Cannonb47243a2003-06-16 21:54:50 +0000148 test_support.TESTFN + "2"
Collin Winterdbead562007-03-10 02:23:40 +0000149 ),
150 False
151 )
152 finally:
153 if not f.close():
154 f.close()
Brett Cannonb47243a2003-06-16 21:54:50 +0000155
Brett Cannonb47243a2003-06-16 21:54:50 +0000156 def test_samestat(self):
157 f = open(test_support.TESTFN + "1", "wb")
158 try:
159 f.write("foo")
160 f.close()
161 self.assertIs(
162 posixpath.samestat(
163 os.stat(test_support.TESTFN + "1"),
164 os.stat(test_support.TESTFN + "1")
165 ),
166 True
167 )
Benjamin Peterson71966052012-11-30 16:13:14 -0500168 # If we don't have links, assume that os.stat() doesn't return
169 # reasonable inode information and thus, that samestat() doesn't
170 # work.
Brett Cannonb47243a2003-06-16 21:54:50 +0000171 if hasattr(os, "symlink"):
Benjamin Peterson8a1a17b2012-11-30 16:12:15 -0500172 os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
173 self.assertIs(
174 posixpath.samestat(
175 os.stat(test_support.TESTFN + "1"),
176 os.stat(test_support.TESTFN + "2")
177 ),
178 True
179 )
180 os.remove(test_support.TESTFN + "2")
Brett Cannonb47243a2003-06-16 21:54:50 +0000181 f = open(test_support.TESTFN + "2", "wb")
182 f.write("bar")
183 f.close()
184 self.assertIs(
185 posixpath.samestat(
186 os.stat(test_support.TESTFN + "1"),
187 os.stat(test_support.TESTFN + "2")
188 ),
189 False
190 )
191 finally:
192 if not f.close():
193 f.close()
Brett Cannonb47243a2003-06-16 21:54:50 +0000194
Brett Cannonb47243a2003-06-16 21:54:50 +0000195 def test_ismount(self):
196 self.assertIs(posixpath.ismount("/"), True)
197
Brett Cannonb47243a2003-06-16 21:54:50 +0000198 def test_expanduser(self):
199 self.assertEqual(posixpath.expanduser("foo"), "foo")
Brett Cannonb47243a2003-06-16 21:54:50 +0000200 try:
201 import pwd
202 except ImportError:
203 pass
204 else:
Ezio Melottib0f5adc2010-01-24 16:58:36 +0000205 self.assertIsInstance(posixpath.expanduser("~/"), basestring)
Neal Norwitz168e73d2003-07-01 03:33:31 +0000206 # if home directory == root directory, this test makes no sense
207 if posixpath.expanduser("~") != '/':
208 self.assertEqual(
209 posixpath.expanduser("~") + "/",
210 posixpath.expanduser("~/")
211 )
Ezio Melottib0f5adc2010-01-24 16:58:36 +0000212 self.assertIsInstance(posixpath.expanduser("~root/"), basestring)
213 self.assertIsInstance(posixpath.expanduser("~foo/"), basestring)
Brett Cannonb47243a2003-06-16 21:54:50 +0000214
Walter Dörwald4b965f62009-04-26 20:51:44 +0000215 with test_support.EnvironmentVarGuard() as env:
Walter Dörwald6733bed2009-05-01 17:35:37 +0000216 env['HOME'] = '/'
Walter Dörwald4b965f62009-04-26 20:51:44 +0000217 self.assertEqual(posixpath.expanduser("~"), "/")
Jesus Ceaf2011e32012-05-10 05:01:11 +0200218 self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
Georg Brandl3f0ef202009-04-05 14:48:49 +0000219
Brett Cannonb47243a2003-06-16 21:54:50 +0000220 def test_normpath(self):
221 self.assertEqual(posixpath.normpath(""), ".")
222 self.assertEqual(posixpath.normpath("/"), "/")
223 self.assertEqual(posixpath.normpath("//"), "//")
224 self.assertEqual(posixpath.normpath("///"), "/")
225 self.assertEqual(posixpath.normpath("///foo/.//bar//"), "/foo/bar")
226 self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), "/foo/baz")
227 self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar")
228
Serhiy Storchakac8e75ba2013-02-18 13:32:06 +0200229 @skip_if_ABSTFN_contains_backslash
Serhiy Storchaka142d2bc2013-02-18 12:20:44 +0200230 def test_realpath_curdir(self):
231 self.assertEqual(realpath('.'), os.getcwd())
232 self.assertEqual(realpath('./.'), os.getcwd())
233 self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
234
Serhiy Storchakac8e75ba2013-02-18 13:32:06 +0200235 @skip_if_ABSTFN_contains_backslash
Serhiy Storchaka142d2bc2013-02-18 12:20:44 +0200236 def test_realpath_pardir(self):
237 self.assertEqual(realpath('..'), dirname(os.getcwd()))
238 self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd())))
239 self.assertEqual(realpath('/'.join(['..'] * 100)), '/')
240
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000241 if hasattr(os, "symlink"):
242 def test_realpath_basic(self):
243 # Basic operation.
244 try:
245 os.symlink(ABSTFN+"1", ABSTFN)
246 self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
247 finally:
Collin Winterdbead562007-03-10 02:23:40 +0000248 test_support.unlink(ABSTFN)
Tim Petersa45cacf2004-08-20 03:47:14 +0000249
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000250 def test_realpath_symlink_loops(self):
251 # Bug #930024, return the path unchanged if we get into an infinite
252 # symlink loop.
253 try:
254 old_path = abspath('.')
255 os.symlink(ABSTFN, ABSTFN)
256 self.assertEqual(realpath(ABSTFN), ABSTFN)
257
258 os.symlink(ABSTFN+"1", ABSTFN+"2")
259 os.symlink(ABSTFN+"2", ABSTFN+"1")
260 self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
261 self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")
262
Serhiy Storchaka0dd3d302013-02-10 12:21:49 +0200263 self.assertEqual(realpath(ABSTFN+"1/x"), ABSTFN+"1/x")
264 self.assertEqual(realpath(ABSTFN+"1/.."), dirname(ABSTFN))
265 self.assertEqual(realpath(ABSTFN+"1/../x"), dirname(ABSTFN) + "/x")
266 os.symlink(ABSTFN+"x", ABSTFN+"y")
267 self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "y"),
268 ABSTFN + "y")
269 self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "1"),
270 ABSTFN + "1")
271
272 os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a")
273 self.assertEqual(realpath(ABSTFN+"a"), ABSTFN+"a/b")
274
275 os.symlink("../" + basename(dirname(ABSTFN)) + "/" +
276 basename(ABSTFN) + "c", ABSTFN+"c")
277 self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c")
278
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000279 # Test using relative path as well.
280 os.chdir(dirname(ABSTFN))
281 self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
282 finally:
283 os.chdir(old_path)
Collin Winterdbead562007-03-10 02:23:40 +0000284 test_support.unlink(ABSTFN)
285 test_support.unlink(ABSTFN+"1")
286 test_support.unlink(ABSTFN+"2")
Serhiy Storchaka0dd3d302013-02-10 12:21:49 +0200287 test_support.unlink(ABSTFN+"y")
288 test_support.unlink(ABSTFN+"c")
Ezio Melottic86e8662013-03-01 20:56:13 +0200289 test_support.unlink(ABSTFN+"a")
Serhiy Storchaka0dd3d302013-02-10 12:21:49 +0200290
291 def test_realpath_repeated_indirect_symlinks(self):
292 # Issue #6975.
293 try:
294 os.mkdir(ABSTFN)
295 os.symlink('../' + basename(ABSTFN), ABSTFN + '/self')
296 os.symlink('self/self/self', ABSTFN + '/link')
297 self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN)
298 finally:
299 test_support.unlink(ABSTFN + '/self')
300 test_support.unlink(ABSTFN + '/link')
301 safe_rmdir(ABSTFN)
302
303 def test_realpath_deep_recursion(self):
304 depth = 10
305 old_path = abspath('.')
306 try:
307 os.mkdir(ABSTFN)
308 for i in range(depth):
309 os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1))
310 os.symlink('.', ABSTFN + '/0')
311 self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)
312
313 # Test using relative path as well.
314 os.chdir(ABSTFN)
315 self.assertEqual(realpath('%d' % depth), ABSTFN)
316 finally:
317 os.chdir(old_path)
318 for i in range(depth + 1):
319 test_support.unlink(ABSTFN + '/%d' % i)
320 safe_rmdir(ABSTFN)
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000321
Tim Petersa45cacf2004-08-20 03:47:14 +0000322 def test_realpath_resolve_parents(self):
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000323 # We also need to resolve any symlinks in the parents of a relative
324 # path passed to realpath. E.g.: current working directory is
325 # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
326 # realpath("a"). This should return /usr/share/doc/a/.
327 try:
328 old_path = abspath('.')
329 os.mkdir(ABSTFN)
330 os.mkdir(ABSTFN + "/y")
331 os.symlink(ABSTFN + "/y", ABSTFN + "/k")
332
333 os.chdir(ABSTFN + "/k")
334 self.assertEqual(realpath("a"), ABSTFN + "/y/a")
335 finally:
336 os.chdir(old_path)
Collin Winterdbead562007-03-10 02:23:40 +0000337 test_support.unlink(ABSTFN + "/k")
338 safe_rmdir(ABSTFN + "/y")
339 safe_rmdir(ABSTFN)
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000340
341 def test_realpath_resolve_before_normalizing(self):
342 # Bug #990669: Symbolic links should be resolved before we
343 # normalize the path. E.g.: if we have directories 'a', 'k' and 'y'
344 # in the following hierarchy:
345 # a/k/y
346 #
347 # and a symbolic link 'link-y' pointing to 'y' in directory 'a',
348 # then realpath("link-y/..") should return 'k', not 'a'.
349 try:
350 old_path = abspath('.')
351 os.mkdir(ABSTFN)
352 os.mkdir(ABSTFN + "/k")
353 os.mkdir(ABSTFN + "/k/y")
354 os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y")
355
356 # Absolute path.
357 self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
358 # Relative path.
359 os.chdir(dirname(ABSTFN))
Ezio Melottie3467d52010-02-20 09:40:07 +0000360 self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
361 ABSTFN + "/k")
Johannes Gijsbers4ec40642004-08-14 15:01:53 +0000362 finally:
363 os.chdir(old_path)
Collin Winterdbead562007-03-10 02:23:40 +0000364 test_support.unlink(ABSTFN + "/link-y")
365 safe_rmdir(ABSTFN + "/k/y")
366 safe_rmdir(ABSTFN + "/k")
367 safe_rmdir(ABSTFN)
Tim Peters5d36a552005-06-03 22:40:27 +0000368
Georg Brandl268e61c2005-06-03 14:28:50 +0000369 def test_realpath_resolve_first(self):
370 # Bug #1213894: The first component of the path, if not absolute,
371 # must be resolved too.
372
373 try:
374 old_path = abspath('.')
375 os.mkdir(ABSTFN)
376 os.mkdir(ABSTFN + "/k")
377 os.symlink(ABSTFN, ABSTFN + "link")
378 os.chdir(dirname(ABSTFN))
Tim Peters5d36a552005-06-03 22:40:27 +0000379
Georg Brandl268e61c2005-06-03 14:28:50 +0000380 base = basename(ABSTFN)
381 self.assertEqual(realpath(base + "link"), ABSTFN)
382 self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
383 finally:
384 os.chdir(old_path)
Collin Winterdbead562007-03-10 02:23:40 +0000385 test_support.unlink(ABSTFN + "link")
386 safe_rmdir(ABSTFN + "/k")
387 safe_rmdir(ABSTFN)
Brett Cannonb47243a2003-06-16 21:54:50 +0000388
Collin Winter6f187742007-03-16 22:16:08 +0000389 def test_relpath(self):
Collin Winter75c7eb42007-03-23 22:24:39 +0000390 (real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
391 try:
392 curdir = os.path.split(os.getcwd())[-1]
393 self.assertRaises(ValueError, posixpath.relpath, "")
394 self.assertEqual(posixpath.relpath("a"), "a")
395 self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a")
396 self.assertEqual(posixpath.relpath("a/b"), "a/b")
397 self.assertEqual(posixpath.relpath("../a/b"), "../a/b")
398 self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
399 self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
400 self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
Georg Brandl183a0842008-01-06 14:27:15 +0000401 self.assertEqual(posixpath.relpath("a", "a"), ".")
Hirokazu Yamamoto50f7d7e2010-10-18 13:55:29 +0000402 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat')
403 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat')
404 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat')
405 self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..')
406 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat')
407 self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x')
408 self.assertEqual(posixpath.relpath("/", "/"), '.')
409 self.assertEqual(posixpath.relpath("/a", "/a"), '.')
410 self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.')
Collin Winter75c7eb42007-03-23 22:24:39 +0000411 finally:
412 os.getcwd = real_getcwd
Collin Winter6f187742007-03-16 22:16:08 +0000413
Serhiy Storchaka2bd8b222015-02-13 12:02:05 +0200414 @test_support.requires_unicode
415 def test_expandvars_nonascii_word(self):
416 encoding = sys.getfilesystemencoding()
417 # Non-ASCII word characters
418 letters = test_support.u(r'\xe6\u0130\u0141\u03c6\u041a\u05d0\u062a\u0e01')
419 uwnonascii = letters.encode(encoding, 'ignore').decode(encoding)[:3]
420 swnonascii = uwnonascii.encode(encoding)
421 if not swnonascii:
422 self.skip('Needs non-ASCII word characters')
423 with test_support.EnvironmentVarGuard() as env:
424 env.clear()
425 env[swnonascii] = 'baz' + swnonascii
426 self.assertEqual(posixpath.expandvars(u'$%s bar' % uwnonascii),
427 u'baz%s bar' % uwnonascii)
428
Florent Xiclunadc1531c2010-03-06 18:07:18 +0000429
430class PosixCommonTest(test_genericpath.CommonTest):
Florent Xicluna985478d2010-03-06 18:52:52 +0000431 pathmodule = posixpath
Florent Xiclunadc1531c2010-03-06 18:07:18 +0000432 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
433
434
Brett Cannonb47243a2003-06-16 21:54:50 +0000435def test_main():
Florent Xiclunadc1531c2010-03-06 18:07:18 +0000436 test_support.run_unittest(PosixPathTest, PosixCommonTest)
437
Brett Cannonb47243a2003-06-16 21:54:50 +0000438
439if __name__=="__main__":
440 test_main()