Skip to content

Commit

Permalink
Skip broken datasets in audb.available() (#383)
Browse files Browse the repository at this point in the history
* Skip broken datasets in audb.available()

* Add broken dataset as test

* Try to test available() with broken dataset

* Expand test
  • Loading branch information
hagenw authored Mar 27, 2024
1 parent c488bd1 commit de482e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
25 changes: 15 additions & 10 deletions audb/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,21 @@ def available(
# see https://github.com/audeering/audbackend/issues/132
for p in backend._repo.path:
name = p.name
for version in [str(x).split("/")[-1] for x in p / "db"]:
databases.append(
[
name,
repository.backend,
repository.host,
repository.name,
version,
]
)
try:
for version in [str(x).split("/")[-1] for x in p / "db"]:
databases.append(
[
name,
repository.backend,
repository.host,
repository.name,
version,
]
)
except FileNotFoundError:
# If the `db` folder does not exist,
# we do not include the dataset
pass
else:
for path, version in backend.ls("/"):
if path.endswith(define.HEADER_FILE):
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def private_and_public_repository():
Configure the following repositories:
* data-private: repo on public Artifactory without access
* data-public: repo on public Artifactory with anonymous access
* data-public2: repo on public Artifactory with anonymous access
Note, that the order of the repos is important.
audb will visit the repos in the given order
Expand All @@ -194,6 +195,7 @@ def private_and_public_repository():
audb.config.REPOSITORIES = [
audb.Repository("data-private", host, backend),
audb.Repository("data-public", host, backend),
audb.Repository("data-public2", host, backend),
]

yield repository
Expand Down
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ def test_available(repository):
]
df = audb.available()
assert len(df) == 0


def test_available_broken_dataset(private_and_public_repository):
"""Test for listing datasets, including a broken one.
This uses the public repositories,
from which ``data-public2``
includes ``broken-dataset``,
which has a missing ``db`` folder.
"""
df = audb.available(only_latest=True)
assert len(df) > 0
assert "broken-dataset" not in df

0 comments on commit de482e8

Please sign in to comment.