Skip to content

Commit

Permalink
Use audbackend>=2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed May 2, 2024
1 parent d2510ee commit fd1ec14
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
17 changes: 6 additions & 11 deletions audbcards/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _save_pickled(obj, path: str):
pickle.dump(obj, f, protocol=4)

@property
def backend(self) -> audbackend.Backend:
def backend(self) -> audbackend.interface.Base:
r"""Dataset backend object."""
if not hasattr(self, "_backend"): # when loaded from cache
self._backend = self._load_backend()
Expand Down Expand Up @@ -385,16 +385,11 @@ def _cached_properties(self):
)
return props

def _load_backend(self) -> audbackend.Backend:
r"""Load backend containing dataset."""
backend = audbackend.access(
name=self.repository_object.backend,
host=self.repository_object.host,
repository=self.repository,
)
if isinstance(backend, audbackend.Artifactory):
backend._use_legacy_file_structure()
return backend
def _load_backend(self) -> audbackend.interface.Base:
r"""Load backend object containing dataset."""
backend_interface = self.repository_object()
backend_interface.backend.open()
return backend_interface

def _load_dependencies(self) -> audb.Dependencies:
r"""Load dataset dependencies."""
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ classifiers = [
]
requires-python = '>=3.9'
dependencies = [
'audb >=1.6.0',
'audbackend >=1.0.1',
'audb @ git+https://github.com/audeering/audb.git@audbackend-2.0.0',
'audplot >=1.4.6',
'jinja2',
'pandas >=2.1.0',
Expand Down
72 changes: 35 additions & 37 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

import audb
import audbackend
import audeer
import audformat
import audiofile
Expand Down Expand Up @@ -64,17 +63,16 @@ def test_dataset(audb_cache, tmpdir, repository, db, request):
pytest.VERSION,
cache_root=dataset_cache,
)
backend = audbackend.access(
name=repository.backend,
host=repository.host,
repository=repository.name,
)
backend_interface = repository()

# __init__
assert dataset.name == db.name
assert dataset.version == pytest.VERSION
assert dataset.repository_object == repository
assert dataset.backend == backend
with backend_interface.backend:
# Compare only string,
# as backends are not identical
assert str(dataset.backend) == str(backend_interface)
expected_header = audb.info.header(
db.name,
version=pytest.VERSION,
Expand Down Expand Up @@ -144,19 +142,20 @@ def test_dataset(audb_cache, tmpdir, repository, db, request):
expected_license_link = db.license_url
assert dataset.license_link == expected_license_link

# publication_date:
expected_publication_date = backend.date(
backend.join("/", db.name, "db.yaml"),
pytest.VERSION,
)
assert dataset.publication_date == expected_publication_date
with backend_interface.backend:
# publication_date:
expected_publication_date = backend_interface.date(
backend_interface.join("/", db.name, "db.yaml"),
pytest.VERSION,
)
assert dataset.publication_date == expected_publication_date

# publication_owner
expected_publication_owner = backend.owner(
backend.join("/", db.name, "db.yaml"),
pytest.VERSION,
)
assert dataset.publication_owner == expected_publication_owner
# publication_owner
expected_publication_owner = backend_interface.owner(
backend_interface.join("/", db.name, "db.yaml"),
pytest.VERSION,
)
assert dataset.publication_owner == expected_publication_owner

# repository
assert dataset.repository == repository.name
Expand Down Expand Up @@ -393,21 +392,20 @@ def test_dataset_cache_loading(audb_cache, tmpdir, repository, db, request):
version=pytest.VERSION,
cache_root=audb_cache,
)
backend = audbackend.access(
name=repository.backend,
host=repository.host,
repository=repository.name,
)
header = audb.info.header(
db.name,
version=pytest.VERSION,
load_tables=True,
cache_root=audb_cache,
)
assert dataset.backend == backend
assert dataset.deps == deps
# The dataset header is a not fully loaded `audformat.Database` object,
# so we cannot directly use `audformat.Database.__eq__()`
# to compare it.
assert str(dataset.header) == str(header)
assert dataset.repository_object == repository
backend_interface = repository()
with backend_interface.backend:
header = audb.info.header(
db.name,
version=pytest.VERSION,
load_tables=True,
cache_root=audb_cache,
)
# Compare only string representation,
# as objects are not identical
assert str(dataset.backend) == str(backend_interface)
assert dataset.deps == deps
# The dataset header is a not fully loaded `audformat.Database` object,
# so we cannot directly use `audformat.Database.__eq__()`
# to compare it.
assert str(dataset.header) == str(header)
assert dataset.repository_object == repository

0 comments on commit fd1ec14

Please sign in to comment.