Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_genericpath.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 3a7cd8efc19f |
| children |
| rev | line source |
|---|---|
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
1 """ |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
2 Tests common to genericpath, macpath, ntpath and posixpath |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
3 """ |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
4 |
|
73576
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
5 import genericpath |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
6 import os |
|
60671
0f37afb8a9f2
Issue #8422, test_genericpath: skip the creation of a directory with an invalid
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59470
diff
changeset
|
7 import sys |
|
73576
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
8 import unittest |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
9 import warnings |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
10 from test import support |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
11 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
12 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
13 def safe_rmdir(dirname): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
14 try: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
15 os.rmdir(dirname) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
16 except OSError: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
17 pass |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
18 |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
19 |
|
81342
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
20 class GenericTest: |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
21 common_attributes = ['commonprefix', 'getsize', 'getatime', 'getctime', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
22 'getmtime', 'exists', 'isdir', 'isfile'] |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
23 attributes = [] |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
24 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
25 def test_no_argument(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
26 for attr in self.common_attributes + self.attributes: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
27 with self.assertRaises(TypeError): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
28 getattr(self.pathmodule, attr)() |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
29 raise self.fail("{}.{}() did not raise a TypeError" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
30 .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
|
31 |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
32 def test_commonprefix(self): |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
33 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
|
34 self.assertEqual( |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
35 commonprefix([]), |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
36 "" |
|
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 self.assertEqual( |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
39 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
|
40 "/home/swen" |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
41 ) |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
42 self.assertEqual( |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
43 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
|
44 "/home/swen/" |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
45 ) |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
46 self.assertEqual( |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
47 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
|
48 "/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
|
49 ) |
|
59469
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
50 self.assertEqual( |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
51 commonprefix(["home:swenson:spam", "home:swen:spam"]), |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
52 "home:swen" |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
53 ) |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
54 self.assertEqual( |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
55 commonprefix([":home:swen:spam", ":home:swen:eggs"]), |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
56 ":home:swen:" |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
57 ) |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
58 self.assertEqual( |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
59 commonprefix([":home:swen:spam", ":home:swen:spam"]), |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
60 ":home:swen:spam" |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
61 ) |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
62 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
63 self.assertEqual( |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
64 commonprefix([b"/home/swenson/spam", b"/home/swen/spam"]), |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
65 b"/home/swen" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
66 ) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
67 self.assertEqual( |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
68 commonprefix([b"/home/swen/spam", b"/home/swen/eggs"]), |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
69 b"/home/swen/" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
70 ) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
71 self.assertEqual( |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
72 commonprefix([b"/home/swen/spam", b"/home/swen/spam"]), |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
73 b"/home/swen/spam" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
74 ) |
|
59469
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
75 self.assertEqual( |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
76 commonprefix([b"home:swenson:spam", b"home:swen:spam"]), |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
77 b"home:swen" |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
78 ) |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
79 self.assertEqual( |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
80 commonprefix([b":home:swen:spam", b":home:swen:eggs"]), |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
81 b":home:swen:" |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
82 ) |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
83 self.assertEqual( |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
84 commonprefix([b":home:swen:spam", b":home:swen:spam"]), |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
85 b":home:swen:spam" |
|
cdfdefec99ab
Merge other tests from test_*path.py into test_genericpath.CommonTest, and do some cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59466
diff
changeset
|
86 ) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
87 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
88 testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
89 'aXc', 'abd', 'ab', 'aX', 'abcX'] |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
90 for s1 in testlist: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
91 for s2 in testlist: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
92 p = commonprefix([s1, s2]) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
93 self.assertTrue(s1.startswith(p)) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
94 self.assertTrue(s2.startswith(p)) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
95 if s1 != s2: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
96 n = len(p) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
97 self.assertNotEqual(s1[n:n+1], s2[n:n+1]) |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
98 |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
99 def test_getsize(self): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
100 f = open(support.TESTFN, "wb") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
101 try: |
|
42924
b4b14c4beb82
str/bytes strictness.
Guido van Rossum <guido@python.org>
parents:
42177
diff
changeset
|
102 f.write(b"foo") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
103 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
104 self.assertEqual(self.pathmodule.getsize(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
|
105 finally: |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
106 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
|
107 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
108 support.unlink(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
|
109 |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
110 def test_time(self): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
111 f = open(support.TESTFN, "wb") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
112 try: |
|
42924
b4b14c4beb82
str/bytes strictness.
Guido van Rossum <guido@python.org>
parents:
42177
diff
changeset
|
113 f.write(b"foo") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
114 f.close() |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
115 f = open(support.TESTFN, "ab") |
|
42924
b4b14c4beb82
str/bytes strictness.
Guido van Rossum <guido@python.org>
parents:
42177
diff
changeset
|
116 f.write(b"bar") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
117 f.close() |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
118 f = open(support.TESTFN, "rb") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
119 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
|
120 f.close() |
|
42177
8d4b69e31581
Make test_genericpath pass.
Guido van Rossum <guido@python.org>
parents:
39689
diff
changeset
|
121 self.assertEqual(d, b"foobar") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
122 |
|
65728
eb50c48d9cb4
Use assertLessEqual to ease diagnosing of failures
Antoine Pitrou <solipsis@pitrou.net>
parents:
55593
diff
changeset
|
123 self.assertLessEqual( |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
124 self.pathmodule.getctime(support.TESTFN), |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
125 self.pathmodule.getmtime(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
|
126 ) |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
127 finally: |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
128 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
|
129 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
130 support.unlink(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
|
131 |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
132 def test_exists(self): |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
133 self.assertIs(self.pathmodule.exists(support.TESTFN), False) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
134 f = open(support.TESTFN, "wb") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
135 try: |
|
42924
b4b14c4beb82
str/bytes strictness.
Guido van Rossum <guido@python.org>
parents:
42177
diff
changeset
|
136 f.write(b"foo") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
137 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
138 self.assertIs(self.pathmodule.exists(support.TESTFN), True) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
139 if not self.pathmodule == genericpath: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
140 self.assertIs(self.pathmodule.lexists(support.TESTFN), |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
141 True) |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
142 finally: |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
143 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
|
144 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
145 support.unlink(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
|
146 |
|
77951
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
147 @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
148 def test_exists_fd(self): |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
149 r, w = os.pipe() |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
150 try: |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
151 self.assertTrue(self.pathmodule.exists(r)) |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
152 finally: |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
153 os.close(r) |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
154 os.close(w) |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
155 self.assertFalse(self.pathmodule.exists(r)) |
|
62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents:
73590
diff
changeset
|
156 |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
157 def test_isdir(self): |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
158 self.assertIs(self.pathmodule.isdir(support.TESTFN), False) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
159 f = open(support.TESTFN, "wb") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
160 try: |
|
42924
b4b14c4beb82
str/bytes strictness.
Guido van Rossum <guido@python.org>
parents:
42177
diff
changeset
|
161 f.write(b"foo") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
162 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
163 self.assertIs(self.pathmodule.isdir(support.TESTFN), False) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
164 os.remove(support.TESTFN) |
|
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
165 os.mkdir(support.TESTFN) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
166 self.assertIs(self.pathmodule.isdir(support.TESTFN), True) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
167 os.rmdir(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
|
168 finally: |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
169 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
|
170 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
171 support.unlink(support.TESTFN) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
172 safe_rmdir(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
|
173 |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
174 def test_isfile(self): |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
175 self.assertIs(self.pathmodule.isfile(support.TESTFN), False) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
176 f = open(support.TESTFN, "wb") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
177 try: |
|
42924
b4b14c4beb82
str/bytes strictness.
Guido van Rossum <guido@python.org>
parents:
42177
diff
changeset
|
178 f.write(b"foo") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
179 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
180 self.assertIs(self.pathmodule.isfile(support.TESTFN), True) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
181 os.remove(support.TESTFN) |
|
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
182 os.mkdir(support.TESTFN) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
183 self.assertIs(self.pathmodule.isfile(support.TESTFN), False) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42924
diff
changeset
|
184 os.rmdir(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
|
185 finally: |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
186 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
|
187 f.close() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
188 support.unlink(support.TESTFN) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
189 safe_rmdir(support.TESTFN) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
190 |
|
81062
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
191 @staticmethod |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
192 def _create_file(filename): |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
193 with open(filename, 'wb') as f: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
194 f.write(b'foo') |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
195 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
196 def test_samefile(self): |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
197 try: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
198 test_fn = support.TESTFN + "1" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
199 self._create_file(test_fn) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
200 self.assertTrue(self.pathmodule.samefile(test_fn, test_fn)) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
201 self.assertRaises(TypeError, self.pathmodule.samefile) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
202 finally: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
203 os.remove(test_fn) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
204 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
205 @support.skip_unless_symlink |
|
81064
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
206 def test_samefile_on_symlink(self): |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
207 self._test_samefile_on_link_func(os.symlink) |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
208 |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
209 def test_samefile_on_link(self): |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
210 self._test_samefile_on_link_func(os.link) |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
211 |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
212 def _test_samefile_on_link_func(self, func): |
|
81062
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
213 try: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
214 test_fn1 = support.TESTFN + "1" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
215 test_fn2 = support.TESTFN + "2" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
216 self._create_file(test_fn1) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
217 |
|
81064
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
218 func(test_fn1, test_fn2) |
|
81062
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
219 self.assertTrue(self.pathmodule.samefile(test_fn1, test_fn2)) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
220 os.remove(test_fn2) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
221 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
222 self._create_file(test_fn2) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
223 self.assertFalse(self.pathmodule.samefile(test_fn1, test_fn2)) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
224 finally: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
225 os.remove(test_fn1) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
226 os.remove(test_fn2) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
227 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
228 def test_samestat(self): |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
229 try: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
230 test_fn = support.TESTFN + "1" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
231 self._create_file(test_fn) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
232 test_fns = [test_fn]*2 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
233 stats = map(os.stat, test_fns) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
234 self.assertTrue(self.pathmodule.samestat(*stats)) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
235 finally: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
236 os.remove(test_fn) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
237 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
238 @support.skip_unless_symlink |
|
81064
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
239 def test_samestat_on_symlink(self): |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
240 self._test_samestat_on_link_func(os.symlink) |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
241 |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
242 def test_samestat_on_link(self): |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
243 self._test_samestat_on_link_func(os.link) |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
244 |
|
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
245 def _test_samestat_on_link_func(self, func): |
|
81062
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
246 try: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
247 test_fn1 = support.TESTFN + "1" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
248 test_fn2 = support.TESTFN + "2" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
249 self._create_file(test_fn1) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
250 test_fns = (test_fn1, test_fn2) |
|
81064
9e980454b85e
Add tests for Issue #10646.
Brian Curtin <brian@python.org>
parents:
81062
diff
changeset
|
251 func(*test_fns) |
|
81062
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
252 stats = map(os.stat, test_fns) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
253 self.assertTrue(self.pathmodule.samestat(*stats)) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
254 os.remove(test_fn2) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
255 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
256 self._create_file(test_fn2) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
257 stats = map(os.stat, test_fns) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
258 self.assertFalse(self.pathmodule.samestat(*stats)) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
259 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
260 self.assertRaises(TypeError, self.pathmodule.samestat) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
261 finally: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
262 os.remove(test_fn1) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
263 os.remove(test_fn2) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
264 |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
265 def test_sameopenfile(self): |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
266 fname = support.TESTFN + "1" |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
267 with open(fname, "wb") as a, open(fname, "wb") as b: |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
268 self.assertTrue(self.pathmodule.sameopenfile( |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
269 a.fileno(), b.fileno())) |
|
189b21f9bc0c
Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.
Brian Curtin <brian@python.org>
parents:
80337
diff
changeset
|
270 |
|
81342
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
271 class TestGenericTest(GenericTest, unittest.TestCase): |
|
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
272 # Issue 16852: GenericTest can't inherit from unittest.TestCase |
|
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
273 # for test discovery purposes; CommonTest inherits from GenericTest |
|
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
274 # and is only meant to be inherited by others. |
|
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
275 pathmodule = genericpath |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
276 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
277 |
|
63881
7dc37ae175fc
Merged manually from 2.7 branch to 3.x trunk.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
62490
diff
changeset
|
278 # Following TestCase is not supposed to be run from test_genericpath. |
|
7dc37ae175fc
Merged manually from 2.7 branch to 3.x trunk.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
62490
diff
changeset
|
279 # It is inherited by other test modules (macpath, ntpath, posixpath). |
|
7dc37ae175fc
Merged manually from 2.7 branch to 3.x trunk.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
62490
diff
changeset
|
280 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
281 class CommonTest(GenericTest): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
282 common_attributes = GenericTest.common_attributes + [ |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
283 # Properties |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
284 'curdir', 'pardir', 'extsep', 'sep', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
285 'pathsep', 'defpath', 'altsep', 'devnull', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
286 # Methods |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
287 'normcase', 'splitdrive', 'expandvars', 'normpath', 'abspath', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
288 'join', 'split', 'splitext', 'isabs', 'basename', 'dirname', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
289 'lexists', 'islink', 'ismount', 'expanduser', 'normpath', 'realpath', |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
290 ] |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
291 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
292 def test_normcase(self): |
|
62490
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
293 normcase = self.pathmodule.normcase |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
294 # check that normcase() is idempotent |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
295 for p in ["FoO/./BaR", b"FoO/./BaR"]: |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
296 p = normcase(p) |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
297 self.assertEqual(p, normcase(p)) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
298 |
|
62490
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
299 self.assertEqual(normcase(''), '') |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
300 self.assertEqual(normcase(b''), b'') |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
301 |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
302 # check that normcase raises a TypeError for invalid types |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
303 for path in (None, True, 0, 2.5, [], bytearray(b''), {'o','o'}): |
|
4e099e5004a1
#9018: os.path.normcase() now raises a TypeError if the argument is not str or bytes.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60833
diff
changeset
|
304 self.assertRaises(TypeError, normcase, path) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
305 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
306 def test_splitdrive(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
307 # splitdrive for non-NT paths |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
308 splitdrive = self.pathmodule.splitdrive |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
309 self.assertEqual(splitdrive("/foo/bar"), ("", "/foo/bar")) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
310 self.assertEqual(splitdrive("foo:bar"), ("", "foo:bar")) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
311 self.assertEqual(splitdrive(":foo:bar"), ("", ":foo:bar")) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
312 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
313 self.assertEqual(splitdrive(b"/foo/bar"), (b"", b"/foo/bar")) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
314 self.assertEqual(splitdrive(b"foo:bar"), (b"", b"foo:bar")) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
315 self.assertEqual(splitdrive(b":foo:bar"), (b"", b":foo:bar")) |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
316 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
317 def test_expandvars(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
318 if self.pathmodule.__name__ == 'macpath': |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
319 self.skipTest('macpath.expandvars is a stub') |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
320 expandvars = self.pathmodule.expandvars |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
321 with support.EnvironmentVarGuard() as env: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
322 env.clear() |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
323 env["foo"] = "bar" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
324 env["{foo"] = "baz1" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
325 env["{foo}"] = "baz2" |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
326 self.assertEqual(expandvars("foo"), "foo") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
327 self.assertEqual(expandvars("$foo bar"), "bar bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
328 self.assertEqual(expandvars("${foo}bar"), "barbar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
329 self.assertEqual(expandvars("$[foo]bar"), "$[foo]bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
330 self.assertEqual(expandvars("$bar bar"), "$bar bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
331 self.assertEqual(expandvars("$?bar"), "$?bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
332 self.assertEqual(expandvars("${foo}bar"), "barbar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
333 self.assertEqual(expandvars("$foo}bar"), "bar}bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
334 self.assertEqual(expandvars("${foo"), "${foo") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
335 self.assertEqual(expandvars("${{foo}}"), "baz1}") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
336 self.assertEqual(expandvars("$foo$foo"), "barbar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
337 self.assertEqual(expandvars("$bar$bar"), "$bar$bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
338 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
339 self.assertEqual(expandvars(b"foo"), b"foo") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
340 self.assertEqual(expandvars(b"$foo bar"), b"bar bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
341 self.assertEqual(expandvars(b"${foo}bar"), b"barbar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
342 self.assertEqual(expandvars(b"$[foo]bar"), b"$[foo]bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
343 self.assertEqual(expandvars(b"$bar bar"), b"$bar bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
344 self.assertEqual(expandvars(b"$?bar"), b"$?bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
345 self.assertEqual(expandvars(b"${foo}bar"), b"barbar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
346 self.assertEqual(expandvars(b"$foo}bar"), b"bar}bar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
347 self.assertEqual(expandvars(b"${foo"), b"${foo") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
348 self.assertEqual(expandvars(b"${{foo}}"), b"baz1}") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
349 self.assertEqual(expandvars(b"$foo$foo"), b"barbar") |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
350 self.assertEqual(expandvars(b"$bar$bar"), b"$bar$bar") |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
351 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
352 def test_abspath(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
353 self.assertIn("foo", self.pathmodule.abspath("foo")) |
|
73576
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
354 with warnings.catch_warnings(): |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
355 warnings.simplefilter("ignore", DeprecationWarning) |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
356 self.assertIn(b"foo", self.pathmodule.abspath(b"foo")) |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
357 |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
358 # Abspath returns bytes when the arg is bytes |
|
73590
5f239b0ba819
Issue #13374: Deprecate os.getcwdb() on Windows
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73576
diff
changeset
|
359 with warnings.catch_warnings(): |
|
5f239b0ba819
Issue #13374: Deprecate os.getcwdb() on Windows
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73576
diff
changeset
|
360 warnings.simplefilter("ignore", DeprecationWarning) |
|
5f239b0ba819
Issue #13374: Deprecate os.getcwdb() on Windows
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73576
diff
changeset
|
361 for path in (b'', b'foo', b'f\xf2\xf2', b'/foo', b'C:\\'): |
|
5f239b0ba819
Issue #13374: Deprecate os.getcwdb() on Windows
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73576
diff
changeset
|
362 self.assertIsInstance(self.pathmodule.abspath(path), bytes) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
363 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
364 def test_realpath(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
365 self.assertIn("foo", self.pathmodule.realpath("foo")) |
|
73576
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
366 with warnings.catch_warnings(): |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
367 warnings.simplefilter("ignore", DeprecationWarning) |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
368 self.assertIn(b"foo", self.pathmodule.realpath(b"foo")) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
369 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
370 def test_normpath_issue5827(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
371 # Make sure normpath preserves unicode |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
372 for path in ('', '.', '/', '\\', '///foo/.//bar//'): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
373 self.assertIsInstance(self.pathmodule.normpath(path), str) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
374 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
375 def test_abspath_issue3426(self): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
376 # Check that abspath returns unicode when the arg is unicode |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
377 # with both ASCII and non-ASCII cwds. |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
378 abspath = self.pathmodule.abspath |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
379 for path in ('', 'fuu', 'f\xf9\xf9', '/fuu', 'U:\\'): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
380 self.assertIsInstance(abspath(path), str) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
381 |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
382 unicwd = '\xe7w\xf0' |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
383 try: |
|
78374
3edc71ed19e7
Issue #15441: Skip test_nonascii_abspath() of test_genericpath on Windows
Victor Stinner <victor.stinner@gmail.com>
parents:
77951
diff
changeset
|
384 os.fsencode(unicwd) |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
385 except (AttributeError, UnicodeEncodeError): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
386 # FS encoding is probably ASCII |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
387 pass |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
388 else: |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
389 with support.temp_cwd(unicwd): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
390 for path in ('', 'fuu', 'f\xf9\xf9', '/fuu', 'U:\\'): |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
391 self.assertIsInstance(abspath(path), str) |
|
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
392 |
|
60671
0f37afb8a9f2
Issue #8422, test_genericpath: skip the creation of a directory with an invalid
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59470
diff
changeset
|
393 def test_nonascii_abspath(self): |
|
81260
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
394 if (support.TESTFN_UNDECODABLE |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
395 # Mac OS X denies the creation of a directory with an invalid |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
396 # UTF-8 name. Windows allows to create a directory with an |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
397 # arbitrary bytes name, but fails to enter this directory |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
398 # (when the bytes name is used). |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
399 and sys.platform not in ('win32', 'darwin')): |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
400 name = support.TESTFN_UNDECODABLE |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
401 elif support.TESTFN_NONASCII: |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
402 name = support.TESTFN_NONASCII |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
403 else: |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
404 self.skipTest("need support.TESTFN_NONASCII") |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
68257
diff
changeset
|
405 |
|
73576
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
406 with warnings.catch_warnings(): |
|
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
407 warnings.simplefilter("ignore", DeprecationWarning) |
|
78374
3edc71ed19e7
Issue #15441: Skip test_nonascii_abspath() of test_genericpath on Windows
Victor Stinner <victor.stinner@gmail.com>
parents:
77951
diff
changeset
|
408 with support.temp_cwd(name): |
|
73576
d42811b93357
Issue #13374: The Windows bytes API has been deprecated in the os module. Use
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68257
diff
changeset
|
409 self.test_abspath() |
|
59466
a2f1c15cae6c
Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58966
diff
changeset
|
410 |
|
39689
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
411 |
|
d0ed7dbaad56
- Move functions common to all path modules into genericpath.py and have the
Jack Diederich <jackdied@gmail.com>
parents:
diff
changeset
|
412 if __name__=="__main__": |
|
81342
6f71e6aa9041
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
81261
diff
changeset
|
413 unittest.main() |
