Skip to content

Commit

Permalink
Narrow scope of exception assertion; document Windows platform guard
Browse files Browse the repository at this point in the history
  • Loading branch information
c0llab0rat0r committed Apr 9, 2021
1 parent 5c858b3 commit 1d9be47
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/functional/test_files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -293,17 +294,20 @@ def test_add_filepattern_from_dirname_recursive_nofwalk(client, cleanup_pins, mo
assert conftest.sort_by_key(res) == conftest.sort_by_key(FAKE_DIR_FNPATTERN1_RECURSIVE_HASH)


@pytest.mark.skipif(not O_DIRECTORY,
@pytest.mark.skipif(sys.platform.startswith("win"),
reason="Opening directory FDs does not work on Windows")
def test_add_filepattern_from_dirfd_recursive_nofwalk(client, cleanup_pins, monkeypatch):
monkeypatch.setattr(ipfshttpclient.filescanner, "HAVE_FWALK", False)

with pytest.raises(NotImplementedError):
fd: int = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY)
try:
assert os.path.isdir(FAKE_DIR_PATH)

# On Windows, this line will fail with PermissionError: [Errno 13] Permission denied
fd: int = os.open(str(FAKE_DIR_PATH), os.O_RDONLY | O_DIRECTORY)
try:
with pytest.raises(NotImplementedError):
client.add(fd, pattern=FAKE_DIR_FNPATTERN1, recursive=True)
finally:
os.close(fd)
finally:
os.close(fd)


@pytest.mark.skipif(not ipfshttpclient.filescanner.HAVE_FWALK,
Expand Down

0 comments on commit 1d9be47

Please sign in to comment.