Skip to content

Commit

Permalink
fix use of config for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed May 29, 2024
1 parent f1a5f54 commit c2e9842
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/nplinker/arranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ def arrange_bigscape(self) -> None:
if self.config.mode == "podp":
for _ in range(3):
try:
validate_bigscape(self.bigscape_dir)
validate_bigscape(self.bigscape_dir, self.config.bigscape.cutoff)
pass_validation = True
break
except FileNotFoundError:
shutil.rmtree(self.bigscape_dir, ignore_errors=True)
self._run_bigscape()

if not pass_validation:
validate_bigscape(self.bigscape_dir)
validate_bigscape(self.bigscape_dir, self.config.bigscape.cutoff)

def _run_bigscape(self) -> None:
"""Run BiG-SCAPE to generate the clustering file.
Expand Down Expand Up @@ -460,7 +460,7 @@ def validate_antismash(antismash_dir: Path) -> None:
raise FileNotFoundError(f"No BGC files found in antiSMASH sub-directory {sub_dir}")


def validate_bigscape(bigscape_dir: Path) -> None:
def validate_bigscape(bigscape_dir: Path, cutoff: str) -> None:
"""Validate the BiG-SCAPE data directory and its contents.
The BiG-SCAPE data directory must exist and contain the clustering file
Expand All @@ -473,14 +473,15 @@ def validate_bigscape(bigscape_dir: Path) -> None:
Args:
bigscape_dir: Path to the BiG-SCAPE data directory.
cutoff: The BiG-SCAPE cutoff value.
Raises:
FileNotFoundError: If the BiG-SCAPE data directory or the clustering file is not found.
"""
if not bigscape_dir.exists():
raise FileNotFoundError(f"BiG-SCAPE data directory not found at {bigscape_dir}")

clustering_file = bigscape_dir / f"mix_clustering_c{self.config.bigscape.cutoff}.tsv"
clustering_file = bigscape_dir / f"mix_clustering_c{cutoff}.tsv"
database_file = bigscape_dir / "data_sqlite.db"
if not clustering_file.exists() and not database_file.exists():
raise FileNotFoundError(f"BiG-SCAPE data not found in {clustering_file} or {database_file}")
2 changes: 0 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def pytest_sessionstart(session):
zip_ref.extractall(temp_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/integration/test_nplinker_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
import pytest
from nplinker.nplinker import NPLinker
from . import DATA_DIR


# Only tests related to data arranging and loading should be put here.
Expand All @@ -23,7 +24,7 @@ def get_file_hash(file_path):

@pytest.fixture(scope="module")
def npl() -> NPLinker:
npl = NPLinker()
npl = NPLinker(DATA_DIR / "nplinker_local_mode.toml")
npl.load_data()
# remove cached score results before running tests
root_dir = Path(npl.root_dir)
Expand Down

0 comments on commit c2e9842

Please sign in to comment.