annotate Lib/test/test_posixpath.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 299dc54ad014
children 980b13df6ccd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
1 import unittest
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
2 from test import test_support, test_genericpath
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
3
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
4 import posixpath, os
58808
0cfe836c4a8d Merged revisions 78080 via svnmerge from
Georg Brandl <georg@python.org>
parents: 58270
diff changeset
5 from posixpath import realpath, abspath, dirname, basename
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
6
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
7 # An absolute path to a temporary filename for testing. We can't rely on TESTFN
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
8 # being an absolute path, so we need this.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
9
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
10 ABSTFN = abspath(test_support.TESTFN)
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
11
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
12 def safe_rmdir(dirname):
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
13 try:
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
14 os.rmdir(dirname)
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
15 except OSError:
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
16 pass
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
17
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
18 class PosixPathTest(unittest.TestCase):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
19
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
20 def setUp(self):
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
21 self.tearDown()
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
22
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
23 def tearDown(self):
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
24 for suffix in ["", "1", "2"]:
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
25 test_support.unlink(test_support.TESTFN + suffix)
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
26 safe_rmdir(test_support.TESTFN + suffix)
41133
01355124ce40 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 41097
diff changeset
27
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
28 def test_join(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
29 self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"), "/bar/baz")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
30 self.assertEqual(posixpath.join("/foo", "bar", "baz"), "/foo/bar/baz")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
31 self.assertEqual(posixpath.join("/foo/", "bar/", "baz/"), "/foo/bar/baz/")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
32
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
33 def test_split(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
34 self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar"))
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
35 self.assertEqual(posixpath.split("/"), ("/", ""))
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
36 self.assertEqual(posixpath.split("foo"), ("", "foo"))
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
37 self.assertEqual(posixpath.split("////foo"), ("////", "foo"))
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
38 self.assertEqual(posixpath.split("//foo//bar"), ("//foo", "bar"))
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
39
41057
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
40 def splitextTest(self, path, filename, ext):
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
41 self.assertEqual(posixpath.splitext(path), (filename, ext))
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
42 self.assertEqual(posixpath.splitext("/" + path), ("/" + filename, ext))
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
43 self.assertEqual(posixpath.splitext("abc/" + path), ("abc/" + filename, ext))
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
44 self.assertEqual(posixpath.splitext("abc.def/" + path), ("abc.def/" + filename, ext))
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
45 self.assertEqual(posixpath.splitext("/abc.def/" + path), ("/abc.def/" + filename, ext))
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
46 self.assertEqual(posixpath.splitext(path + "/"), (filename + ext + "/", ""))
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
47
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
48 def test_splitext(self):
41057
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
49 self.splitextTest("foo.bar", "foo", ".bar")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
50 self.splitextTest("foo.boo.bar", "foo.boo", ".bar")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
51 self.splitextTest("foo.boo.biff.bar", "foo.boo.biff", ".bar")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
52 self.splitextTest(".csh.rc", ".csh", ".rc")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
53 self.splitextTest("nodots", "nodots", "")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
54 self.splitextTest(".cshrc", ".cshrc", "")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
55 self.splitextTest("...manydots", "...manydots", "")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
56 self.splitextTest("...manydots.ext", "...manydots", ".ext")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
57 self.splitextTest(".", ".", "")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
58 self.splitextTest("..", "..", "")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
59 self.splitextTest("........", "........", "")
98bbc93bd55b Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
Martin v. Löwis <martin@v.loewis.de>
parents: 40649
diff changeset
60 self.splitextTest("", "", "")
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
61
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
62 def test_isabs(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
63 self.assertIs(posixpath.isabs(""), False)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
64 self.assertIs(posixpath.isabs("/"), True)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
65 self.assertIs(posixpath.isabs("/foo"), True)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
66 self.assertIs(posixpath.isabs("/foo/bar"), True)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
67 self.assertIs(posixpath.isabs("foo/bar"), False)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
68
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
69 def test_basename(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
70 self.assertEqual(posixpath.basename("/foo/bar"), "bar")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
71 self.assertEqual(posixpath.basename("/"), "")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
72 self.assertEqual(posixpath.basename("foo"), "foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
73 self.assertEqual(posixpath.basename("////foo"), "foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
74 self.assertEqual(posixpath.basename("//foo//bar"), "bar")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
75
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
76 def test_dirname(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
77 self.assertEqual(posixpath.dirname("/foo/bar"), "/foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
78 self.assertEqual(posixpath.dirname("/"), "/")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
79 self.assertEqual(posixpath.dirname("foo"), "")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
80 self.assertEqual(posixpath.dirname("////foo"), "////")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
81 self.assertEqual(posixpath.dirname("//foo//bar"), "//foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
82
41133
01355124ce40 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 41097
diff changeset
83 def test_islink(self):
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
84 self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
85 f = open(test_support.TESTFN + "1", "wb")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
86 try:
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
87 f.write("foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
88 f.close()
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
89 self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
90 if hasattr(os, "symlink"):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
91 os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
92 self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
93 os.remove(test_support.TESTFN + "1")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
94 self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
95 self.assertIs(posixpath.exists(test_support.TESTFN + "2"), False)
33332
062177de8685 Patch #941486: add os.path.lexists(). Also fix bug #940578 by using lexists in glob.glob.
Johannes Gijsbers <jlg@dds.nl>
parents: 33204
diff changeset
96 self.assertIs(posixpath.lexists(test_support.TESTFN + "2"), True)
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
97 finally:
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
98 if not f.close():
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
99 f.close()
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
100
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
101 def test_samefile(self):
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
102 f = open(test_support.TESTFN + "1", "wb")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
103 try:
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
104 f.write("foo")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
105 f.close()
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
106 self.assertIs(
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
107 posixpath.samefile(
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
108 test_support.TESTFN + "1",
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
109 test_support.TESTFN + "1"
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
110 ),
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
111 True
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
112 )
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
113 # If we don't have links, assume that os.stat doesn't return resonable
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
114 # inode information and thus, that samefile() doesn't work
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
115 if hasattr(os, "symlink"):
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
116 os.symlink(
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
117 test_support.TESTFN + "1",
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
118 test_support.TESTFN + "2"
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
119 )
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
120 self.assertIs(
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
121 posixpath.samefile(
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
122 test_support.TESTFN + "1",
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
123 test_support.TESTFN + "2"
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
124 ),
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
125 True
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
126 )
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
127 os.remove(test_support.TESTFN + "2")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
128 f = open(test_support.TESTFN + "2", "wb")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
129 f.write("bar")
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
130 f.close()
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
131 self.assertIs(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
132 posixpath.samefile(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
133 test_support.TESTFN + "1",
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
134 test_support.TESTFN + "2"
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
135 ),
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
136 False
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
137 )
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
138 finally:
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
139 if not f.close():
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
140 f.close()
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
141
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
142 def test_samestat(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
143 f = open(test_support.TESTFN + "1", "wb")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
144 try:
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
145 f.write("foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
146 f.close()
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
147 self.assertIs(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
148 posixpath.samestat(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
149 os.stat(test_support.TESTFN + "1"),
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
150 os.stat(test_support.TESTFN + "1")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
151 ),
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
152 True
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
153 )
29668
36a17904a3ed Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 29540
diff changeset
154 # If we don't have links, assume that os.stat() doesn't return resonable
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
155 # inode information and thus, that samefile() doesn't work
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
156 if hasattr(os, "symlink"):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
157 if hasattr(os, "symlink"):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
158 os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
159 self.assertIs(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
160 posixpath.samestat(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
161 os.stat(test_support.TESTFN + "1"),
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
162 os.stat(test_support.TESTFN + "2")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
163 ),
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
164 True
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
165 )
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
166 os.remove(test_support.TESTFN + "2")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
167 f = open(test_support.TESTFN + "2", "wb")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
168 f.write("bar")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
169 f.close()
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
170 self.assertIs(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
171 posixpath.samestat(
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
172 os.stat(test_support.TESTFN + "1"),
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
173 os.stat(test_support.TESTFN + "2")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
174 ),
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
175 False
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
176 )
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
177 finally:
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
178 if not f.close():
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
179 f.close()
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
180
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
181 def test_ismount(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
182 self.assertIs(posixpath.ismount("/"), True)
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
183
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
184 def test_expanduser(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
185 self.assertEqual(posixpath.expanduser("foo"), "foo")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
186 try:
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
187 import pwd
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
188 except ImportError:
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
189 pass
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
190 else:
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58269
diff changeset
191 self.assertIsInstance(posixpath.expanduser("~/"), basestring)
29707
762e2a297ab9 Fix SF #763362, test_posixpath failed
Neal Norwitz <nnorwitz@gmail.com>
parents: 29668
diff changeset
192 # if home directory == root directory, this test makes no sense
762e2a297ab9 Fix SF #763362, test_posixpath failed
Neal Norwitz <nnorwitz@gmail.com>
parents: 29668
diff changeset
193 if posixpath.expanduser("~") != '/':
762e2a297ab9 Fix SF #763362, test_posixpath failed
Neal Norwitz <nnorwitz@gmail.com>
parents: 29668
diff changeset
194 self.assertEqual(
762e2a297ab9 Fix SF #763362, test_posixpath failed
Neal Norwitz <nnorwitz@gmail.com>
parents: 29668
diff changeset
195 posixpath.expanduser("~") + "/",
762e2a297ab9 Fix SF #763362, test_posixpath failed
Neal Norwitz <nnorwitz@gmail.com>
parents: 29668
diff changeset
196 posixpath.expanduser("~/")
762e2a297ab9 Fix SF #763362, test_posixpath failed
Neal Norwitz <nnorwitz@gmail.com>
parents: 29668
diff changeset
197 )
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58269
diff changeset
198 self.assertIsInstance(posixpath.expanduser("~root/"), basestring)
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58269
diff changeset
199 self.assertIsInstance(posixpath.expanduser("~foo/"), basestring)
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
200
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52903
diff changeset
201 with test_support.EnvironmentVarGuard() as env:
53644
85542715a249 Make test.test_support.EnvironmentVarGuard behave like a dictionary.
Walter Dörwald <walter@livinglogic.de>
parents: 53485
diff changeset
202 env['HOME'] = '/'
53485
0688e8b24632 Merged revisions 71984 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52903
diff changeset
203 self.assertEqual(posixpath.expanduser("~"), "/")
76853
299dc54ad014 Closes #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'
Jesus Cea <jcea@jcea.es>
parents: 68256
diff changeset
204 self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
52903
3889d9528601 Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from
Georg Brandl <georg@python.org>
parents: 44522
diff changeset
205
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
206 def test_normpath(self):
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
207 self.assertEqual(posixpath.normpath(""), ".")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
208 self.assertEqual(posixpath.normpath("/"), "/")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
209 self.assertEqual(posixpath.normpath("//"), "//")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
210 self.assertEqual(posixpath.normpath("///"), "/")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
211 self.assertEqual(posixpath.normpath("///foo/.//bar//"), "/foo/bar")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
212 self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), "/foo/baz")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
213 self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar")
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
214
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
215 if hasattr(os, "symlink"):
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
216 def test_realpath_basic(self):
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
217 # Basic operation.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
218 try:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
219 os.symlink(ABSTFN+"1", ABSTFN)
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
220 self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
221 finally:
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
222 test_support.unlink(ABSTFN)
33204
c18aca7e81cb Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33129
diff changeset
223
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
224 def test_realpath_symlink_loops(self):
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
225 # Bug #930024, return the path unchanged if we get into an infinite
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
226 # symlink loop.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
227 try:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
228 old_path = abspath('.')
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
229 os.symlink(ABSTFN, ABSTFN)
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
230 self.assertEqual(realpath(ABSTFN), ABSTFN)
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
231
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
232 os.symlink(ABSTFN+"1", ABSTFN+"2")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
233 os.symlink(ABSTFN+"2", ABSTFN+"1")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
234 self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
235 self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
236
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
237 # Test using relative path as well.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
238 os.chdir(dirname(ABSTFN))
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
239 self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
240 finally:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
241 os.chdir(old_path)
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
242 test_support.unlink(ABSTFN)
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
243 test_support.unlink(ABSTFN+"1")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
244 test_support.unlink(ABSTFN+"2")
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
245
33204
c18aca7e81cb Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33129
diff changeset
246 def test_realpath_resolve_parents(self):
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
247 # We also need to resolve any symlinks in the parents of a relative
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
248 # path passed to realpath. E.g.: current working directory is
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
249 # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
250 # realpath("a"). This should return /usr/share/doc/a/.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
251 try:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
252 old_path = abspath('.')
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
253 os.mkdir(ABSTFN)
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
254 os.mkdir(ABSTFN + "/y")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
255 os.symlink(ABSTFN + "/y", ABSTFN + "/k")
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
256
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
257 os.chdir(ABSTFN + "/k")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
258 self.assertEqual(realpath("a"), ABSTFN + "/y/a")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
259 finally:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
260 os.chdir(old_path)
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
261 test_support.unlink(ABSTFN + "/k")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
262 safe_rmdir(ABSTFN + "/y")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
263 safe_rmdir(ABSTFN)
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
264
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
265 def test_realpath_resolve_before_normalizing(self):
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
266 # Bug #990669: Symbolic links should be resolved before we
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
267 # normalize the path. E.g.: if we have directories 'a', 'k' and 'y'
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
268 # in the following hierarchy:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
269 # a/k/y
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
270 #
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
271 # and a symbolic link 'link-y' pointing to 'y' in directory 'a',
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
272 # then realpath("link-y/..") should return 'k', not 'a'.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
273 try:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
274 old_path = abspath('.')
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
275 os.mkdir(ABSTFN)
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
276 os.mkdir(ABSTFN + "/k")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
277 os.mkdir(ABSTFN + "/k/y")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
278 os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
279
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
280 # Absolute path.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
281 self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
282 # Relative path.
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
283 os.chdir(dirname(ABSTFN))
58965
3a7132f65623 Remove e assertIs definitions and use correct assert* methods.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58963
diff changeset
284 self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
3a7132f65623 Remove e assertIs definitions and use correct assert* methods.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58963
diff changeset
285 ABSTFN + "/k")
33129
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
286 finally:
ae9b47a8d648 bug #990669: os.path.realpath() will resolve symlinks before normalizing the
Johannes Gijsbers <jlg@dds.nl>
parents: 29707
diff changeset
287 os.chdir(old_path)
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
288 test_support.unlink(ABSTFN + "/link-y")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
289 safe_rmdir(ABSTFN + "/k/y")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
290 safe_rmdir(ABSTFN + "/k")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
291 safe_rmdir(ABSTFN)
35040
3b41bd878918 Tools/scripts/reindent.py is your friend
Anthony Baxter <anthonybaxter@gmail.com>
parents: 35007
diff changeset
292
35007
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
293 def test_realpath_resolve_first(self):
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
294 # Bug #1213894: The first component of the path, if not absolute,
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
295 # must be resolved too.
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
296
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
297 try:
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
298 old_path = abspath('.')
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
299 os.mkdir(ABSTFN)
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
300 os.mkdir(ABSTFN + "/k")
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
301 os.symlink(ABSTFN, ABSTFN + "link")
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
302 os.chdir(dirname(ABSTFN))
35040
3b41bd878918 Tools/scripts/reindent.py is your friend
Anthony Baxter <anthonybaxter@gmail.com>
parents: 35007
diff changeset
303
35007
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
304 base = basename(ABSTFN)
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
305 self.assertEqual(realpath(base + "link"), ABSTFN)
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
306 self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
307 finally:
de76b343d9c8 Backport bug #1213894: os.path.realpath didn't resolve symlinks that were the first
Georg Brandl <georg@python.org>
parents: 33332
diff changeset
308 os.chdir(old_path)
41097
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
309 test_support.unlink(ABSTFN + "link")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
310 safe_rmdir(ABSTFN + "/k")
be0d49134e4f * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
Collin Winter <collinw@gmail.com>
parents: 41057
diff changeset
311 safe_rmdir(ABSTFN)
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
312
41218
f3d4274d063d Patch 1339796: add a relpath() function to os.path.
Collin Winter <collinw@gmail.com>
parents: 41133
diff changeset
313 def test_relpath(self):
41293
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
314 (real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
315 try:
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
316 curdir = os.path.split(os.getcwd())[-1]
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
317 self.assertRaises(ValueError, posixpath.relpath, "")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
318 self.assertEqual(posixpath.relpath("a"), "a")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
319 self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
320 self.assertEqual(posixpath.relpath("a/b"), "a/b")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
321 self.assertEqual(posixpath.relpath("../a/b"), "../a/b")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
322 self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
323 self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
324 self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
44522
4321a5abd6ce #1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Georg Brandl <georg@python.org>
parents: 41701
diff changeset
325 self.assertEqual(posixpath.relpath("a", "a"), ".")
65524
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
326 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
327 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
328 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
329 self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
330 self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
331 self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
332 self.assertEqual(posixpath.relpath("/", "/"), '.')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
333 self.assertEqual(posixpath.relpath("/a", "/a"), '.')
2f7e01694926 Issue #5117: Fixed root directory related issue on posixpath.relpath() and
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 59409
diff changeset
334 self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.')
41293
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
335 finally:
1c3e0d2c36dc Make test_relpath() pass on Windows.
Collin Winter <collinw@gmail.com>
parents: 41218
diff changeset
336 os.getcwd = real_getcwd
41218
f3d4274d063d Patch 1339796: add a relpath() function to os.path.
Collin Winter <collinw@gmail.com>
parents: 41133
diff changeset
337
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
338
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
339 class PosixCommonTest(test_genericpath.CommonTest):
59409
a07f70fc82a1 Minor tweaking of previous r78734, and add a NEWS entry.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59408
diff changeset
340 pathmodule = posixpath
59408
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
341 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
342
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
343
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
344 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
345 test_support.run_unittest(PosixPathTest, PosixCommonTest)
ebdc2aa730c0 Create test_genericpath.CommonTest and reuse it to test other path modules.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58971
diff changeset
346
29502
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
347
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
348 if __name__=="__main__":
71c06bc5a73e Complete rewrite of tests by Walter Dorwald as unittest tests.
Brett Cannon <bcannon@gmail.com>
parents: 26627
diff changeset
349 test_main()