Skip to content

Commit

Permalink
Merge pull request #60 from jaraco/bugfix/55-isfile-missing
Browse files Browse the repository at this point in the history
is_file returns False for non-existent files
  • Loading branch information
jaraco authored Sep 22, 2020
2 parents 20ef7dd + e495001 commit da7a4aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit da7a4aa

Please sign in to comment.