Skip to content

Commit

Permalink
Improve code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Apr 25, 2024
1 parent 00b1563 commit 0820aff
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
12 changes: 6 additions & 6 deletions audbcards/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ def name(self) -> str:
@functools.cached_property
def publication_date(self) -> str:
r"""Date dataset was uploaded to repository."""
path = self._backend.join("/", self.name, "db.yaml")
return self._backend.date(path, self._version)
path = self.backend.join("/", self.name, "db.yaml")
return self.backend.date(path, self.version)

@functools.cached_property
def publication_owner(self) -> str:
r"""User who uploaded dataset to repository."""
path = self._backend.join("/", self.name, "db.yaml")
return self._backend.owner(path, self._version)
path = self.backend.join("/", self.name, "db.yaml")
return self.backend.owner(path, self.version)

def properties(self):
"""Get list of properties of the object."""
Expand Down Expand Up @@ -390,8 +390,8 @@ def version(self) -> str:
def _load_backend(self) -> audbackend.Backend:
r"""Load backend containing dataset."""
backend = audbackend.access(
name=self._repository_object.backend,
host=self._repository_object.host,
name=self.repository_object.backend,
host=self.repository_object.host,
repository=self.repository,
)
if isinstance(backend, audbackend.Artifactory):
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
audb >=1.6.5 # for audb.Dependencies.__eq__()
audeer >=1.21.0
pytest
46 changes: 46 additions & 0 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,49 @@ def test_dataset_cache_path():
"emodb-1.2.1.pkl",
)
assert cache_path_calculated == cache_path_expected


@pytest.mark.parametrize(
"db",
[
"medium_db",
],
)
def test_dataset_cache_loading(audb_cache, tmpdir, repository, db, request):
"""Test cached properties after loading from cache.
We no longer store all attributes/properties
in cache as pickle files,
but limit ourselves to the cached properties.
This test ensures,
that other attributes will be re-calculated.
"""
db = request.getfixturevalue(db)
cache_root = audeer.mkdir(tmpdir, "cache")
dataset = audbcards.Dataset(db.name, pytest.VERSION, cache_root=cache_root)
del dataset
dataset = audbcards.Dataset(db.name, pytest.VERSION, cache_root=cache_root)
deps = audb.dependencies(
db.name,
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,
# cache_root=audb_cache,
# )
assert dataset.backend == backend
assert dataset.deps == deps
# Disabled due to potential audformat issue:
# the `files` table cannot be found in cache,
# which is requested when using `load_tables=True`
# in `audb.info.header`.
# assert dataset.header == header
assert dataset.repository_object == repository

0 comments on commit 0820aff

Please sign in to comment.