-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move test files to subfolders and update pytest's conftest.py (#100)
To solve issue #99 * move test files to relevant subfolders * create pytest conftest.py for relevant subfolders * fix redundant fixtures * move non-shared fixture to specific file
- Loading branch information
1 parent
7b21795
commit a058dd9
Showing
27 changed files
with
101 additions
and
93 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
from pathlib import Path | ||
import shutil | ||
import pytest | ||
|
||
from nplinker.metabolomics.metabolomics import load_spectra | ||
from nplinker.metabolomics.metabolomics import make_families | ||
from nplinker.metabolomics.spectrum import Spectrum | ||
from nplinker.strain_collection import StrainCollection | ||
from nplinker.strains import Strain | ||
from nplinker.utils import extract_archive | ||
|
||
from . import DATA_DIR | ||
|
||
|
||
def _unpack(archive: Path): | ||
filepath = DATA_DIR / archive | ||
outdir = DATA_DIR / filepath.stem | ||
extract_archive(filepath, outdir) | ||
return filepath, outdir | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def prepare_data(): | ||
_unpack("ProteoSAFe-METABOLOMICS-SNETS-c22f44b1-download_clustered_spectra.zip") | ||
_unpack("ProteoSAFe-FEATURE-BASED-MOLECULAR-NETWORKING-92036537-download_cytoscape_data.zip") | ||
_unpack( | ||
"ProteoSAFe-METABOLOMICS-SNETS-c22f44b1-download_clustered_spectra.zip" | ||
) | ||
_unpack( | ||
"ProteoSAFe-FEATURE-BASED-MOLECULAR-NETWORKING-92036537-download_cytoscape_data.zip" | ||
) | ||
yield | ||
shutil.rmtree(DATA_DIR / "ProteoSAFe-METABOLOMICS-SNETS-c22f44b1-download_clustered_spectra") | ||
shutil.rmtree(DATA_DIR / "ProteoSAFe-FEATURE-BASED-MOLECULAR-NETWORKING-92036537-download_cytoscape_data") | ||
shutil.rmtree( | ||
DATA_DIR / | ||
"ProteoSAFe-METABOLOMICS-SNETS-c22f44b1-download_clustered_spectra") | ||
shutil.rmtree( | ||
DATA_DIR / | ||
"ProteoSAFe-FEATURE-BASED-MOLECULAR-NETWORKING-92036537-download_cytoscape_data" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def spec_dict() -> dict[int, Spectrum]: | ||
mgf_file = DATA_DIR / "spectra.mgf" | ||
edges_file = DATA_DIR / "edges.pairsinfo" | ||
return load_spectra(mgf_file, edges_file) | ||
|
||
|
||
@pytest.fixture | ||
def collection_from_file() -> StrainCollection: | ||
filename = DATA_DIR / "strain_mappings.csv" | ||
sut = StrainCollection() | ||
sut.add_from_file(filename) | ||
return sut | ||
|
||
|
||
@pytest.fixture | ||
def strain() -> Strain: | ||
item = Strain("peter") | ||
item.aliases = set(["dieter"]) | ||
return item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/test_gnps_spectrum_loader.py → ...metabolomics/test_gnps_spectrum_loader.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import pytest | ||
from nplinker.metabolomics.gnps.gnps_spectrum_loader import GNPSSpectrumLoader | ||
|
||
from . import DATA_DIR | ||
from .. import DATA_DIR | ||
|
||
@pytest.mark.parametrize("file, expected", [ | ||
[DATA_DIR / "ProteoSAFe-METABOLOMICS-SNETS-c22f44b1-download_clustered_spectra/METABOLOMICS-SNETS-c22f44b1-download_clustered_spectra-main.mgf", 435], | ||
[DATA_DIR / "ProteoSAFe-FEATURE-BASED-MOLECULAR-NETWORKING-92036537-download_cytoscape_data/spectra/specs_ms.mgf", 1492] | ||
]) | ||
def test_loads_spectra(file, expected): | ||
actual = GNPSSpectrumLoader(file).spectra() | ||
assert len(actual) == expected | ||
assert len(actual) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from nplinker.parsers.mgf import LoadMGF | ||
|
||
from . import DATA_DIR | ||
from .. import DATA_DIR | ||
|
||
|
||
def test_load_mgf(): | ||
|
Empty file.
File renamed without changes.
Oops, something went wrong.