Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_file returns False for non-existent files #60

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ close the same file handle.
#56 and bpo-41035: ``Path._next`` now honors
subclasses.

#55: ``Path.is_file()`` now returns False for non-existent names.

v3.1.0
======

Expand Down
9 changes: 7 additions & 2 deletions test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def test_iterdir_and_types(self):
(i,) = h.iterdir()
assert i.is_file()

def test_is_file_missing(self):
for alpharep in self.zipfile_alpharep():
root = zipp.Path(alpharep)
assert not root.joinpath('missing.txt').is_file()

def test_iterdir_on_file(self):
for alpharep in self.zipfile_alpharep():
root = zipp.Path(alpharep)
Expand Down Expand Up @@ -175,15 +180,15 @@ def test_read(self):
def test_joinpath(self):
for alpharep in self.zipfile_alpharep():
root = zipp.Path(alpharep)
a = root.joinpath("a")
a = root.joinpath("a.txt")
assert a.is_file()
e = root.joinpath("b").joinpath("d").joinpath("e.txt")
assert e.read_text() == "content of e"

def test_traverse_truediv(self):
for alpharep in self.zipfile_alpharep():
root = zipp.Path(alpharep)
a = root / "a"
a = root / "a.txt"
assert a.is_file()
e = root / "b" / "d" / "e.txt"
assert e.read_text() == "content of e"
Expand Down
2 changes: 1 addition & 1 deletion zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def is_dir(self):
return not self.at or self.at.endswith("/")

def is_file(self):
return not self.is_dir()
return self.exists() and not self.is_dir()

def exists(self):
return self.at in self.root._name_set()
Expand Down