Skip to content

Commit

Permalink
Add a check for calling with an existing member
Browse files Browse the repository at this point in the history
  • Loading branch information
leouieda committed Feb 19, 2024
1 parent 4d576d0 commit fab577f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pooch/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ def __call__(self, fname, action, pooch):
else:
archive_dir = fname.rsplit(os.path.sep, maxsplit=1)[0]
self.extract_dir = os.path.join(archive_dir, self.extract_dir)
members = self.members or self._all_members(fname)
# Get a list of everyone who is supposed to be in the unpacked folder
# so we can check if they are all there or if we need to extract new
# files.
if self.members is None or not self.members:
members = self._all_members(fname)
else:
members = self.members
if (
(action in ("update", "download"))
or (not os.path.exists(self.extract_dir))
Expand Down
31 changes: 27 additions & 4 deletions pooch/tests/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,41 @@ def _unpacking_expected_paths_and_logs(archive, members, path, name):
[(Unzip, ".zip"), (Untar, ".tar.gz")],
)
def test_unpacking_members_then_no_members(processor_class, extension):
"""Test that calling with members then without them works.
"""
Test that calling with valid members then without them works.
https://github.com/fatiando/pooch/issues/364
"""
with TemporaryDirectory() as local_store:
pup = Pooch(path=Path(local_store), base_url=BASEURL, registry=REGISTRY)

# Do a first fetch with an existing member
processor1 = processor_class(members=["store/tiny-data.txt"])
filenames1 = pup.fetch("store" + extension, processor=processor1)
assert len(filenames1) == 1

# Do a second fetch with no members
processor2 = processor_class()
filenames2 = pup.fetch("store" + extension, processor=processor2)
assert len(filenames2) > 1


@pytest.mark.network
@pytest.mark.parametrize(
"processor_class,extension",
[(Unzip, ".zip"), (Untar, ".tar.gz")],
)
def test_unpacking_wrong_members_then_no_members(processor_class, extension):
"""
Test that calling with invalid members then without them works.
https://github.com/fatiando/pooch/issues/364
"""
with TemporaryDirectory() as local_store:
pup = Pooch(path=Path(local_store), base_url=BASEURL, registry=REGISTRY)

# Do a first fetch with incorrect member
processor1 = processor_class(members=["tiny-data.txt"])
processor1 = processor_class(members=["not-a-valid-file.csv"])
filenames1 = pup.fetch("store" + extension, processor=processor1)
assert len(filenames1) == 1
assert len(filenames1) == 0

# Do a second fetch with no members
processor2 = processor_class()
Expand Down

0 comments on commit fab577f

Please sign in to comment.