11import os
22import shutil
3- import sys
43import tempfile
54
65import pytest
1211import conftest
1312
1413
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 )
1616
1717
1818### test_add_multiple_from_list
@@ -263,15 +263,15 @@ def test_add_filepattern_from_dirname(client, cleanup_pins):
263263 reason = "No point in disabling os.fwalk if it isn't actually supported" )
264264def test_add_filepattern_from_dirname_nofwalk (client , cleanup_pins , monkeypatch ):
265265 monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
266-
266+
267267 res = client .add (FAKE_DIR_PATH , pattern = FAKE_DIR_FNPATTERN1 )
268268 assert conftest .sort_by_key (res ) == conftest .sort_by_key (FAKE_DIR_FNPATTERN1_HASH )
269269
270270
271271@pytest .mark .skipif (not ipfshttpclient .filescanner .HAVE_FWALK ,
272272 reason = "Passing directory as file descriptor requires os.fwalk" )
273273def 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 )
275275 try :
276276 res = client .add (fd , pattern = FAKE_DIR_FNPATTERN1 )
277277 finally :
@@ -288,18 +288,18 @@ def test_add_filepattern_from_dirname_recursive(client, cleanup_pins):
288288 reason = "No point in disabling os.fwalk if it isn't actually supported" )
289289def test_add_filepattern_from_dirname_recursive_nofwalk (client , cleanup_pins , monkeypatch ):
290290 monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
291-
291+
292292 res = client .add (FAKE_DIR_PATH , pattern = FAKE_DIR_FNPATTERN1 , recursive = True )
293293 assert conftest .sort_by_key (res ) == conftest .sort_by_key (FAKE_DIR_FNPATTERN1_RECURSIVE_HASH )
294294
295295
296- @pytest .mark .skipif (sys . platform . startswith ( "win" ) ,
296+ @pytest .mark .skipif (not O_DIRECTORY ,
297297 reason = "Opening directory FDs does not work on Windows" )
298298def test_add_filepattern_from_dirfd_recursive_nofwalk (client , cleanup_pins , monkeypatch ):
299299 monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
300-
300+
301301 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 )
303303 try :
304304 client .add (fd , pattern = FAKE_DIR_FNPATTERN1 , recursive = True )
305305 finally :
@@ -309,7 +309,7 @@ def test_add_filepattern_from_dirfd_recursive_nofwalk(client, cleanup_pins, monk
309309@pytest .mark .skipif (not ipfshttpclient .filescanner .HAVE_FWALK ,
310310 reason = "Passing directory as file descriptor requires os.fwalk" )
311311def 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 )
313313 try :
314314 res = client .add (fd , pattern = FAKE_DIR_FNPATTERN1 , recursive = True )
315315 finally :
@@ -327,7 +327,7 @@ def test_add_filepattern_from_dirname_recursive_binary(client, cleanup_pins):
327327 reason = "No point in disabling os.fwalk if it isn't actually supported" )
328328def test_add_filepattern_from_dirname_recursive_nofwalk_binary (client , cleanup_pins , monkeypatch ):
329329 monkeypatch .setattr (ipfshttpclient .filescanner , "HAVE_FWALK" , False )
330-
330+
331331 res = client .add (os .fsencode (str (FAKE_DIR_PATH )),
332332 pattern = os .fsencode (FAKE_DIR_FNPATTERN1 ), recursive = True )
333333 assert conftest .sort_by_key (res ) == conftest .sort_by_key (FAKE_DIR_FNPATTERN1_RECURSIVE_HASH )
0 commit comments