annotate Lib/test/test_genericpath.py @ 80272:ec00f8570c55

Merge typo fix.
author Ezio Melotti <ezio.melotti@gmail.com>
date Mon, 05 Nov 2012 22:23:16 +0200
parents b3434c1ae503
children de8cf1ece068
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
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
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
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
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
19
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
20 class GenericTest(unittest.TestCase):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
21 # The path module to be tested
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
22 pathmodule = genericpath
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
23 common_attributes = ['commonprefix', 'getsize', 'getatime', 'getctime',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
24 'getmtime', 'exists', 'isdir', 'isfile']
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
25 attributes = []
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
26
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
27 def test_no_argument(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
28 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
29 with self.assertRaises(TypeError):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
30 getattr(self.pathmodule, attr)()
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
31 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
32 .format(self.pathmodule.__name__, attr))
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
33
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
34 def test_commonprefix(self):
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
35 commonprefix = self.pathmodule.commonprefix
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
36 self.assertEqual(
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
37 commonprefix([]),
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
38 ""
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
39 )
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
40 self.assertEqual(
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
41 commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
42 "/home/swen"
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
43 )
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
44 self.assertEqual(
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
45 commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
46 "/home/swen/"
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
47 )
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
48 self.assertEqual(
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
49 commonprefix(["/home/swen/spam", "/home/swen/spam"]),
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
50 "/home/swen/spam"
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
51 )
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
52 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
53 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
54 "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
55 )
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 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
57 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
58 ":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
59 )
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 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
61 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
62 ":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
63 )
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
64
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
65 self.assertEqual(
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
66 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
67 b"/home/swen"
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
68 )
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
69 self.assertEqual(
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
70 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
71 b"/home/swen/"
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
72 )
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
73 self.assertEqual(
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
74 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
75 b"/home/swen/spam"
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
76 )
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
77 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
78 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
79 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
80 )
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 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
82 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
83 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
84 )
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 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
86 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
87 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
88 )
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
89
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
90 testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
91 'aXc', 'abd', 'ab', 'aX', 'abcX']
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
92 for s1 in testlist:
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
93 for s2 in testlist:
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
94 p = commonprefix([s1, s2])
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
95 self.assertTrue(s1.startswith(p))
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
96 self.assertTrue(s2.startswith(p))
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
97 if s1 != s2:
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
98 n = len(p)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
99 self.assertNotEqual(s1[n:n+1], s2[n:n+1])
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
100
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
101 def test_getsize(self):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 42924
diff changeset
102 f = open(support.TESTFN, "wb")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
103 try:
42924
b4b14c4beb82 str/bytes strictness.
Guido van Rossum <guido@python.org>
parents: 42177
diff changeset
104 f.write(b"foo")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
105 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
106 self.assertEqual(self.pathmodule.getsize(support.TESTFN), 3)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
107 finally:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
108 if not f.closed:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
109 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
110 support.unlink(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
111
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
112 def test_time(self):
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 42924
diff changeset
113 f = open(support.TESTFN, "wb")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
114 try:
42924
b4b14c4beb82 str/bytes strictness.
Guido van Rossum <guido@python.org>
parents: 42177
diff changeset
115 f.write(b"foo")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
116 f.close()
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 42924
diff changeset
117 f = open(support.TESTFN, "ab")
42924
b4b14c4beb82 str/bytes strictness.
Guido van Rossum <guido@python.org>
parents: 42177
diff changeset
118 f.write(b"bar")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
119 f.close()
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 42924
diff changeset
120 f = open(support.TESTFN, "rb")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
121 d = f.read()
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
122 f.close()
42177
8d4b69e31581 Make test_genericpath pass.
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
123 self.assertEqual(d, b"foobar")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
124
65728
eb50c48d9cb4 Use assertLessEqual to ease diagnosing of failures
Antoine Pitrou <solipsis@pitrou.net>
parents: 55593
diff changeset
125 self.assertLessEqual(
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
126 self.pathmodule.getctime(support.TESTFN),
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
127 self.pathmodule.getmtime(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
128 )
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
129 finally:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
130 if not f.closed:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
131 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
132 support.unlink(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
133
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
134 def test_exists(self):
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
135 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
136 f = open(support.TESTFN, "wb")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
137 try:
42924
b4b14c4beb82 str/bytes strictness.
Guido van Rossum <guido@python.org>
parents: 42177
diff changeset
138 f.write(b"foo")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
139 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
140 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
141 if not self.pathmodule == genericpath:
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
142 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
143 True)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
144 finally:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
145 if not f.close():
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
146 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
147 support.unlink(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
148
77951
62b9bfbc3356 Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents: 73590
diff changeset
149 @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
150 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
151 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
152 try:
62b9bfbc3356 Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents: 73590
diff changeset
153 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
154 finally:
62b9bfbc3356 Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
Richard Oudkerk <shibturn@gmail.com>
parents: 73590
diff changeset
155 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
156 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
157 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
158
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
159 def test_isdir(self):
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
160 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
161 f = open(support.TESTFN, "wb")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
162 try:
42924
b4b14c4beb82 str/bytes strictness.
Guido van Rossum <guido@python.org>
parents: 42177
diff changeset
163 f.write(b"foo")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
164 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
165 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
166 os.remove(support.TESTFN)
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 42924
diff changeset
167 os.mkdir(support.TESTFN)
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
168 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
169 os.rmdir(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
170 finally:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
171 if not f.close():
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
172 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
173 support.unlink(support.TESTFN)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
174 safe_rmdir(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
175
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
176 def test_isfile(self):
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
177 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
178 f = open(support.TESTFN, "wb")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
179 try:
42924
b4b14c4beb82 str/bytes strictness.
Guido van Rossum <guido@python.org>
parents: 42177
diff changeset
180 f.write(b"foo")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
181 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
182 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
183 os.remove(support.TESTFN)
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 42924
diff changeset
184 os.mkdir(support.TESTFN)
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
185 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
186 os.rmdir(support.TESTFN)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
187 finally:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
188 if not f.close():
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
189 f.close()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
190 support.unlink(support.TESTFN)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
191 safe_rmdir(support.TESTFN)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
192
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
193
63881
7dc37ae175fc Merged manually from 2.7 branch to 3.x trunk.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62490
diff changeset
194 # 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
195 # 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
196
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
197 class CommonTest(GenericTest):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
198 # The path module to be tested
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
199 pathmodule = None
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
200 common_attributes = GenericTest.common_attributes + [
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
201 # Properties
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
202 'curdir', 'pardir', 'extsep', 'sep',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
203 'pathsep', 'defpath', 'altsep', 'devnull',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
204 # Methods
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
205 'normcase', 'splitdrive', 'expandvars', 'normpath', 'abspath',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
206 'join', 'split', 'splitext', 'isabs', 'basename', 'dirname',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
207 'lexists', 'islink', 'ismount', 'expanduser', 'normpath', 'realpath',
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
208 ]
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
209
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
210 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
211 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
212 # 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
213 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
214 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
215 self.assertEqual(p, normcase(p))
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
216
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
217 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
218 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
219
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
220 # 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
221 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
222 self.assertRaises(TypeError, normcase, path)
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
223
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
224 def test_splitdrive(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
225 # splitdrive for non-NT paths
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
226 splitdrive = self.pathmodule.splitdrive
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
227 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
228 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
229 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
230
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
231 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
232 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
233 self.assertEqual(splitdrive(b":foo:bar"), (b"", b":foo:bar"))
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
234
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
235 def test_expandvars(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
236 if self.pathmodule.__name__ == 'macpath':
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
237 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
238 expandvars = self.pathmodule.expandvars
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
239 with support.EnvironmentVarGuard() as env:
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
240 env.clear()
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
241 env["foo"] = "bar"
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
242 env["{foo"] = "baz1"
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
243 env["{foo}"] = "baz2"
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
244 self.assertEqual(expandvars("foo"), "foo")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
245 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
246 self.assertEqual(expandvars("${foo}bar"), "barbar")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
247 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
248 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
249 self.assertEqual(expandvars("$?bar"), "$?bar")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
250 self.assertEqual(expandvars("${foo}bar"), "barbar")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
251 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
252 self.assertEqual(expandvars("${foo"), "${foo")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
253 self.assertEqual(expandvars("${{foo}}"), "baz1}")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
254 self.assertEqual(expandvars("$foo$foo"), "barbar")
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
255 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
256
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 self.assertEqual(expandvars(b"$bar$bar"), b"$bar$bar")
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
269
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
270 def test_abspath(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
271 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
272 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
273 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
274 self.assertIn(b"foo", self.pathmodule.abspath(b"foo"))
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
275
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
276 # 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
277 with warnings.catch_warnings():
5f239b0ba819 Issue #13374: Deprecate os.getcwdb() on Windows
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73576
diff changeset
278 warnings.simplefilter("ignore", DeprecationWarning)
5f239b0ba819 Issue #13374: Deprecate os.getcwdb() on Windows
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73576
diff changeset
279 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
280 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
281
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
282 def test_realpath(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
283 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
284 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
285 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
286 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
287
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
288 def test_normpath_issue5827(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
289 # Make sure normpath preserves unicode
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
290 for path in ('', '.', '/', '\\', '///foo/.//bar//'):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
291 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
292
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
293 def test_abspath_issue3426(self):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
294 # 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
295 # 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
296 abspath = self.pathmodule.abspath
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
297 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
298 self.assertIsInstance(abspath(path), str)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
299
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
300 unicwd = '\xe7w\xf0'
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
301 try:
78374
3edc71ed19e7 Issue #15441: Skip test_nonascii_abspath() of test_genericpath on Windows
Victor Stinner <victor.stinner@gmail.com>
parents: 77951
diff changeset
302 os.fsencode(unicwd)
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
303 except (AttributeError, UnicodeEncodeError):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
304 # FS encoding is probably ASCII
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
305 pass
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
306 else:
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
307 with support.temp_cwd(unicwd):
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
308 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
309 self.assertIsInstance(abspath(path), str)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
310
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
311 @unittest.skipIf(sys.platform == 'darwin',
60833
7d49f021c842 Fix verb tense in skip message.
R. David Murray <rdmurray@bitdance.com>
parents: 60671
diff changeset
312 "Mac OS X denies the creation of a directory with an invalid utf8 name")
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
313 def test_nonascii_abspath(self):
80140
b3434c1ae503 Issue #15441, #15478: Reenable test_nonascii_abspath() on Windows
Victor Stinner <victor.stinner@gmail.com>
parents: 78374
diff changeset
314 if support.TESTFN_UNDECODABLE:
b3434c1ae503 Issue #15441, #15478: Reenable test_nonascii_abspath() on Windows
Victor Stinner <victor.stinner@gmail.com>
parents: 78374
diff changeset
315 name = support.TESTFN_UNDECODABLE
b3434c1ae503 Issue #15441, #15478: Reenable test_nonascii_abspath() on Windows
Victor Stinner <victor.stinner@gmail.com>
parents: 78374
diff changeset
316 else:
b3434c1ae503 Issue #15441, #15478: Reenable test_nonascii_abspath() on Windows
Victor Stinner <victor.stinner@gmail.com>
parents: 78374
diff changeset
317 name = b'a\xffb\xe7w\xf0'
78374
3edc71ed19e7 Issue #15441: Skip test_nonascii_abspath() of test_genericpath on Windows
Victor Stinner <victor.stinner@gmail.com>
parents: 77951
diff changeset
318
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
319 # Test non-ASCII, non-UTF8 bytes in the path.
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
320 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
321 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
322 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
323 self.test_abspath()
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
324
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
325
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
326 def test_main():
59466
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
327 support.run_unittest(GenericTest)
a2f1c15cae6c Merged revisions 78734-78735 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58966
diff changeset
328
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
329
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
330 if __name__=="__main__":
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
diff changeset
331 test_main()