Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support src=None for db_factory #20

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/ensembl/utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
from pathlib import Path
import re
from typing import Callable, Generator, Optional
from typing import Callable, Generator

import pytest
from pytest import Config, FixtureRequest, Parser
Expand Down Expand Up @@ -125,19 +125,23 @@ def fixture_db_factory(request: FixtureRequest, data_dir: Path) -> Generator[Cal
created: dict[str, UnitTestDB] = {}
server_url = request.config.getoption("server")

def _db_factory(src: StrPath, name: Optional[str] = None) -> UnitTestDB:
def _db_factory(src: StrPath | None, name: str | None = None) -> UnitTestDB:
"""Returns a unit test database.

Args:
src: Directory path where the test database schema and content files are located, if any.
name: Name to give to the new database. See `UnitTestDB` for more information.

"""
src_path = Path(src)
if not src_path.is_absolute():
src_path = data_dir / src_path
db_key = name if name else src_path.name
dump_dir: Path | None = src_path if src_path.exists() else None
if src is not None:
src_path = Path(src)
if not src_path.is_absolute():
src_path = data_dir / src_path
db_key = name if name else src_path.name
dump_dir: Path | None = src_path if src_path.exists() else None
else:
db_key = name if name else "dbkey"
dump_dir = None
return created.setdefault(db_key, UnitTestDB(server_url, dump_dir=dump_dir, name=name))

yield _db_factory
Expand Down
Loading