Skip to content

Commit

Permalink
fix use of config for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed May 29, 2024
1 parent 7fc40a3 commit f1a5f54
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

DATA_DIR = Path(__file__).resolve().parent / "data"
GNPS_DATA_DIR = DATA_DIR / "gnps"
CONFIG_FILE_LOCAL_MODE = DATA_DIR / "nplinker_local_mode.toml"
3 changes: 0 additions & 3 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil
import tempfile
from . import DATA_DIR


nplinker_root_dir = os.path.join(tempfile.gettempdir(), "nplinker_unit_test")
Expand All @@ -26,8 +25,6 @@ def pytest_sessionstart(session):
os.mkdir(nplinker_root_dir)
# NPLinker setting `root_dir` must be a path that exists, so setting it to a temporary directory.
os.environ["NPLINKER_ROOT_DIR"] = nplinker_root_dir
# # Specify the config file via environment variable before importing nplinker in any test.
os.environ["NPLINKER_CONFIG_FILE"] = str(DATA_DIR / "nplinker_local_mode.toml")


def pytest_sessionfinish(session):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/scoring/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from nplinker.scoring.linking import LinkFinder
from nplinker.strain import Strain
from nplinker.strain import StrainCollection
from .. import CONFIG_FILE_LOCAL_MODE


@fixture(scope="session")
Expand Down Expand Up @@ -86,7 +87,7 @@ def npl(gcfs, spectra, mfs, strains, tmp_path_factory) -> NPLinker:
The config file `nplinker_demo1.toml` does not affect the tests, just
making sure the NPLinker object can be created succesfully.
"""
npl = NPLinker()
npl = NPLinker(CONFIG_FILE_LOCAL_MODE)
npl._gcfs = gcfs
npl._spectra = spectra
npl._molfams = mfs
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from nplinker.config import config
from nplinker.config import load_config
from . import CONFIG_FILE_LOCAL_MODE


def test_config():
"""Test loading the default config file."""
# The default config file is set in "./conftest.py", which is "data/nplinker_local_mode.toml"
config = load_config(CONFIG_FILE_LOCAL_MODE)

assert config.mode == "local"
assert config.log.level == "DEBUG"
assert config["log.level"] == "DEBUG"
Expand Down

0 comments on commit f1a5f54

Please sign in to comment.