Skip to content

Commit

Permalink
Raise error for empty repositories argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Dec 15, 2024
1 parent 4708fd1 commit 328024b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions audb/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def available(
table with database name as index,
and backend, host, repository, version as columns
Raises:
ValueError: if ``repositories`` is an empty when provided
Examples:
>>> df = audb.available(only_latest=True)
>>> df.loc[["air", "emodb"]]
Expand All @@ -63,6 +66,8 @@ def add_database(name: str, version: str, repository: Repository):

if repositories is not None:
repositories = audeer.to_list(repositories)
if not repositories:
raise ValueError("'repositories' argument must not be empty when provided")
else:
repositories = config.REPOSITORIES

Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def test_repositories_single(self, repository_index, preprocess_repository):
# Verify host
assert df.host.iloc[0] == repository.host

@pytest.mark.parametrize("repositories", [[], ()])
def test_repositories_empty(self, repositories):
"""Tests empty repositories argument."""
expected_error_msg = "'repositories' argument must not be empty when provided"
with pytest.raises(ValueError, match=expected_error_msg):
audb.available(repositories=repositories)

def test_broken_database(self, repository_with_broken_database):
"""Test having a database only given as a folder."""
df = audb.available()
Expand Down

0 comments on commit 328024b

Please sign in to comment.