1
1
import os
2
2
import shutil
3
- import sys
4
3
import tempfile
5
4
6
5
import pytest
12
11
import conftest
13
12
14
13
15
- O_DIRECTORY = getattr (os , "O_DIRECTORY" , 0 ) # type: int
14
+ # Windows does not have os.O_DIRECTORY
15
+ O_DIRECTORY : int = getattr (os , "O_DIRECTORY" , 0 )
16
16
17
17
18
18
### test_add_multiple_from_list
@@ -263,15 +263,15 @@ def test_add_filepattern_from_dirname(client, cleanup_pins):
263
263
reason = "No point in disabling os.fwalk if it isn't actually supported" )
264
264
def test_add_filepattern_from_dirname_nofwalk (client , cleanup_pins , monkeypatch ):
265
265
monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
266
-
266
+
267
267
res = client .add (FAKE_DIR_PATH , pattern = FAKE_DIR_FNPATTERN1 )
268
268
assert conftest .sort_by_key (res ) == conftest .sort_by_key (FAKE_DIR_FNPATTERN1_HASH )
269
269
270
270
271
271
@pytest .mark .skipif (not ipfshttpclient .filescanner .HAVE_FWALK ,
272
272
reason = "Passing directory as file descriptor requires os.fwalk" )
273
273
def test_add_filepattern_from_dirfd (client , cleanup_pins ):
274
- fd = os .open (str (FAKE_DIR_PATH ), os .O_RDONLY | O_DIRECTORY ) # type: int
274
+ fd : int = os .open (str (FAKE_DIR_PATH ), os .O_RDONLY | O_DIRECTORY )
275
275
try :
276
276
res = client .add (fd , pattern = FAKE_DIR_FNPATTERN1 )
277
277
finally :
@@ -288,18 +288,18 @@ def test_add_filepattern_from_dirname_recursive(client, cleanup_pins):
288
288
reason = "No point in disabling os.fwalk if it isn't actually supported" )
289
289
def test_add_filepattern_from_dirname_recursive_nofwalk (client , cleanup_pins , monkeypatch ):
290
290
monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
291
-
291
+
292
292
res = client .add (FAKE_DIR_PATH , pattern = FAKE_DIR_FNPATTERN1 , recursive = True )
293
293
assert conftest .sort_by_key (res ) == conftest .sort_by_key (FAKE_DIR_FNPATTERN1_RECURSIVE_HASH )
294
294
295
295
296
- @pytest .mark .skipif (sys . platform . startswith ( "win" ) ,
296
+ @pytest .mark .skipif (not O_DIRECTORY ,
297
297
reason = "Opening directory FDs does not work on Windows" )
298
298
def test_add_filepattern_from_dirfd_recursive_nofwalk (client , cleanup_pins , monkeypatch ):
299
299
monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
300
-
300
+
301
301
with pytest .raises (NotImplementedError ):
302
- fd = os .open (str (FAKE_DIR_PATH ), os .O_RDONLY | O_DIRECTORY ) # type: int
302
+ fd : int = os .open (str (FAKE_DIR_PATH ), os .O_RDONLY | O_DIRECTORY )
303
303
try :
304
304
client .add (fd , pattern = FAKE_DIR_FNPATTERN1 , recursive = True )
305
305
finally :
@@ -309,7 +309,7 @@ def test_add_filepattern_from_dirfd_recursive_nofwalk(client, cleanup_pins, monk
309
309
@pytest .mark .skipif (not ipfshttpclient .filescanner .HAVE_FWALK ,
310
310
reason = "Passing directory as file descriptor requires os.fwalk" )
311
311
def test_add_filepattern_from_dirfd_recursive (client , cleanup_pins ):
312
- fd = os .open (str (FAKE_DIR_PATH ), os .O_RDONLY | O_DIRECTORY ) # type: int
312
+ fd : int = os .open (str (FAKE_DIR_PATH ), os .O_RDONLY | O_DIRECTORY )
313
313
try :
314
314
res = client .add (fd , pattern = FAKE_DIR_FNPATTERN1 , recursive = True )
315
315
finally :
@@ -327,7 +327,7 @@ def test_add_filepattern_from_dirname_recursive_binary(client, cleanup_pins):
327
327
reason = "No point in disabling os.fwalk if it isn't actually supported" )
328
328
def test_add_filepattern_from_dirname_recursive_nofwalk_binary (client , cleanup_pins , monkeypatch ):
329
329
monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
330
-
330
+
331
331
res = client .add (os .fsencode (str (FAKE_DIR_PATH )),
332
332
pattern = os .fsencode (FAKE_DIR_FNPATTERN1 ), recursive = True )
333
333
assert conftest .sort_by_key (res ) == conftest .sort_by_key (FAKE_DIR_FNPATTERN1_RECURSIVE_HASH )
0 commit comments