Skip to content

Commit

Permalink
Add test for load_to()
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed May 28, 2024
1 parent 44df511 commit fdd2727
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_attachments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os

import audeer
import audformat

import audb


def test_loading_multiple_attachments(tmpdir, repository):
r"""Test loading of databases containing multiple attachments.
As described in https://github.com/audeering/audb/issues/313,
``audb.load_to()`` might struggle to load all attachments.
"""
db_name = "db"
db_version = "1.0.0"
db_root = audeer.mkdir(tmpdir, db_name)
db = audformat.Database(db_name)
# Include four different folders as attachment
folders = [
os.path.join("a", "a"),
os.path.join("a", "b"),
os.path.join("b", "a"),
os.path.join("c", "a"),
]
files = [
os.path.join("a", "a", "file-a-a-1"),
os.path.join("a", "a", "file-a-a-2"),
os.path.join("a", "b", "file-a-b-1"),
os.path.join("a", "b", "file-a-b-2"),
os.path.join("b", "a", "file-b-a-1"),
os.path.join("b", "a", "file-b-a-2"),
os.path.join("c", "a", "file-c-a-1"),
os.path.join("c", "a", "file-c-a-2"),
]
for folder in folders:
audeer.mkdir(db_root, folder)
for file in files:
audeer.touch(db_root, file)
db.attachments["a-a"] = audformat.Attachment("a/a/")
db.attachments["a-b"] = audformat.Attachment("a/b/")
db.attachments["b-a"] = audformat.Attachment("b/a/")
db.attachments["c-a"] = audformat.Attachment("c/a/")
db.save(db_root)

audb.publish(db_root, db_version, repository)

build_dir = audeer.mkdir(tmpdir, "build")
audb.load_to(build_dir, db_name, version=db_version, verbose=False)

for file in files:
assert os.path.exists(audeer.path(build_dir, file))

0 comments on commit fdd2727

Please sign in to comment.