From de482e831bd7ad64d84708e42ccdd8f358e70579 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Wed, 27 Mar 2024 15:50:00 +0100 Subject: [PATCH] Skip broken datasets in audb.available() (#383) * Skip broken datasets in audb.available() * Add broken dataset as test * Try to test available() with broken dataset * Expand test --- audb/core/api.py | 25 +++++++++++++++---------- tests/conftest.py | 2 ++ tests/test_api.py | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/audb/core/api.py b/audb/core/api.py index c2cb4d7f..ed5daae3 100644 --- a/audb/core/api.py +++ b/audb/core/api.py @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index d8e5a19f..fdecb8db 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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 diff --git a/tests/test_api.py b/tests/test_api.py index 12881a00..58fa252d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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