Add a fixture helper for tests

Add a fixture helper for tests to easily create a valid repository
database with a few dummy entries.
parent 538b11f3
import os
import shutil
import tarfile
import tempfile
from os.path import dirname, join, realpath
from pathlib import Path
RESOURCES = join(dirname(realpath(__file__)), "resources", "repo_db")
# TODO: rely on pytest-pacman instead of re-inventing the wheel, as soon as there is a release
def create_db_file(compression: str = "gz", remove_db: bool = False) -> Path:
(file_number, db_file) = tempfile.mkstemp(suffix=".db")
temp_dir = tempfile.mkdtemp()
repo_dir = shutil.copytree(src=RESOURCES, dst=temp_dir, dirs_exist_ok=True)
with, f"w:{compression}") as db_tar:
for name in ["efivar-37-4", "pacman-5.2.2-1", "elfutils-0.182-1", "libelf-0.182-1"]:
if remove_db:
return Path(db_file)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment