Skip to content

Commit

Permalink
Fix is_dir under Python 3:
Browse files Browse the repository at this point in the history
It is no longer returning `True` for files with binary content.

Fixes ulope#23.
  • Loading branch information
Michael Howitz committed Jun 30, 2023
1 parent d117527 commit 698d87f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ TODO
Version History
===============

1.3.1 - unreleased
------------------

- Fix ``is_dir`` under Python 3 no longer returning ``True`` for files with binary content. (#23, thanks @icemac)


1.3.0 - 2019-09-16
------------------
- Updated supported Python versions to 2.7, 3.5 - 3.7.
Expand Down
3 changes: 2 additions & 1 deletion pytest_sftpserver/sftp/content_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def list(self, path):
return [n for n in dir(obj) if not n.startswith("__")]

def is_dir(self, path):
return not isinstance(self.get(path), string_types + integer_types)
return not isinstance(
self.get(path), (binary_type,) + string_types + integer_types)

def get_size(self, path):
try:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_content_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self):
f=["testfile5", "testfile6"]
),
d="testfile3",
g=b"testfile7",
o=_TestObj(),
)
# fmt: on
Expand Down Expand Up @@ -107,7 +108,7 @@ def test_remove_obj_fail(content_provider):


def test_list_root(content_provider):
assert set(content_provider.list("/")) == set(["a", "d", "o"])
assert set(content_provider.list("/")) == set(["a", "d", "g", "o"])


def test_list_sub(content_provider):
Expand All @@ -120,6 +121,7 @@ def test_is_dir(content_provider):
assert content_provider.is_dir("/a")
assert content_provider.is_dir("/a/f")
assert content_provider.is_dir("/o")
assert not content_provider.is_dir("/g")
assert not content_provider.is_dir("/d")


Expand Down

0 comments on commit 698d87f

Please sign in to comment.