7
7
import sys
8
8
import unittest
9
9
import warnings
10
- from test .support import is_emscripten
11
- from test . support import os_helper
12
- from test . support import warnings_helper
10
+ from test .support import (
11
+ is_apple , is_emscripten , os_helper , warnings_helper
12
+ )
13
13
from test .support .script_helper import assert_python_ok
14
14
from test .support .os_helper import FakePath
15
15
@@ -135,6 +135,9 @@ def test_exists(self):
135
135
self .assertIs (self .pathmodule .exists (filename ), False )
136
136
self .assertIs (self .pathmodule .exists (bfilename ), False )
137
137
138
+ self .assertIs (self .pathmodule .lexists (filename ), False )
139
+ self .assertIs (self .pathmodule .lexists (bfilename ), False )
140
+
138
141
create_file (filename )
139
142
140
143
self .assertIs (self .pathmodule .exists (filename ), True )
@@ -145,14 +148,17 @@ def test_exists(self):
145
148
self .assertIs (self .pathmodule .exists (filename + '\x00 ' ), False )
146
149
self .assertIs (self .pathmodule .exists (bfilename + b'\x00 ' ), False )
147
150
148
- if self .pathmodule is not genericpath :
149
- self .assertIs (self .pathmodule .lexists (filename ), True )
150
- self .assertIs (self .pathmodule .lexists (bfilename ), True )
151
+ self .assertIs (self .pathmodule .lexists (filename ), True )
152
+ self .assertIs (self .pathmodule .lexists (bfilename ), True )
153
+
154
+ self .assertIs (self .pathmodule .lexists (filename + '\udfff ' ), False )
155
+ self .assertIs (self .pathmodule .lexists (bfilename + b'\xff ' ), False )
156
+ self .assertIs (self .pathmodule .lexists (filename + '\x00 ' ), False )
157
+ self .assertIs (self .pathmodule .lexists (bfilename + b'\x00 ' ), False )
151
158
152
- self .assertIs (self .pathmodule .lexists (filename + '\udfff ' ), False )
153
- self .assertIs (self .pathmodule .lexists (bfilename + b'\xff ' ), False )
154
- self .assertIs (self .pathmodule .lexists (filename + '\x00 ' ), False )
155
- self .assertIs (self .pathmodule .lexists (bfilename + b'\x00 ' ), False )
159
+ # Keyword arguments are accepted
160
+ self .assertIs (self .pathmodule .exists (path = filename ), True )
161
+ self .assertIs (self .pathmodule .lexists (path = filename ), True )
156
162
157
163
@unittest .skipUnless (hasattr (os , "pipe" ), "requires os.pipe()" )
158
164
@unittest .skipIf (is_emscripten , "Emscripten pipe fds have no stat" )
@@ -165,6 +171,14 @@ def test_exists_fd(self):
165
171
os .close (w )
166
172
self .assertFalse (self .pathmodule .exists (r ))
167
173
174
+ # TODO: RUSTPYTHON
175
+ @unittest .expectedFailure
176
+ def test_exists_bool (self ):
177
+ for fd in False , True :
178
+ with self .assertWarnsRegex (RuntimeWarning ,
179
+ 'bool is used as a file descriptor' ):
180
+ self .pathmodule .exists (fd )
181
+
168
182
def test_isdir (self ):
169
183
filename = os_helper .TESTFN
170
184
bfilename = os .fsencode (filename )
@@ -483,12 +497,16 @@ def test_abspath_issue3426(self):
483
497
self .assertIsInstance (abspath (path ), str )
484
498
485
499
def test_nonascii_abspath (self ):
486
- if (os_helper .TESTFN_UNDECODABLE
487
- # macOS and Emscripten deny the creation of a directory with an
488
- # invalid UTF-8 name. Windows allows creating a directory with an
489
- # arbitrary bytes name, but fails to enter this directory
490
- # (when the bytes name is used).
491
- and sys .platform not in ('win32' , 'darwin' , 'emscripten' , 'wasi' )):
500
+ if (
501
+ os_helper .TESTFN_UNDECODABLE
502
+ # Apple platforms and Emscripten/WASI deny the creation of a
503
+ # directory with an invalid UTF-8 name. Windows allows creating a
504
+ # directory with an arbitrary bytes name, but fails to enter this
505
+ # directory (when the bytes name is used).
506
+ and sys .platform not in {
507
+ "win32" , "emscripten" , "wasi"
508
+ } and not is_apple
509
+ ):
492
510
name = os_helper .TESTFN_UNDECODABLE
493
511
elif os_helper .TESTFN_NONASCII :
494
512
name = os_helper .TESTFN_NONASCII
0 commit comments