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

MAINT: Setup a pytest fixture for reuse across tests #144

Merged
merged 7 commits into from
Oct 26, 2023
32 changes: 32 additions & 0 deletions pylossless/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Pytest fixtures that can be reused across our unit tests."""
# Author: Scott Huberty <[email protected]>
#
# License: MIT

from pathlib import Path
import shutil

import pylossless as ll
from pylossless.tests.test_pipeline import load_openneuro_bids

import pytest


@pytest.fixture(scope="session")
def pipeline_fixture():
"""Return a namedTuple containing MNE eyetracking raw data and events."""
raw, config, bids_root = load_openneuro_bids()
raw.crop(tmin=0, tmax=60) # take 60 seconds for speed
config["find_breaks"] = {}
config["find_breaks"]["min_break_duration"] = 9
config["find_breaks"]["t_start_after_previous"] = 1
config["find_breaks"]["t_stop_before_next"] = 0
config.save("test_config.yaml")
pipeline = ll.LosslessPipeline("test_config.yaml")
not_in_1020 = ["EXG1", "EXG2", "EXG3", "EXG4", "EXG5", "EXG6", "EXG7", "EXG8"]
pipeline.raw = raw.pick("eeg", exclude=not_in_1020).load_data()
pipeline.run_with_raw(pipeline.raw)

Path("test_config.yaml").unlink() # delete config file
shutil.rmtree(bids_root)
return pipeline
4 changes: 3 additions & 1 deletion pylossless/dash/tests/test_topo_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def test_GridTopoPlot():

# chromedriver: https://chromedriver.storage.googleapis.com/
# index.html?path=114.0.5735.90/
@pytest.mark.xfail(reason="an issue with chromedriver on GH CI to be debugged")
@pytest.mark.skip(
reason="an issue with chromedriver causes failure, and test hangs for ~10 minutes"
)
def test_TopoViz(dash_duo):
"""Test TopoViz."""
raw, ica = get_raw_ica()
Expand Down
28 changes: 2 additions & 26 deletions pylossless/tests/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
import shutil
from time import sleep
import pytest

Expand Down Expand Up @@ -61,32 +60,9 @@ def load_openneuro_bids():
return raw, config, bids_root


# @pytest.mark.xfail
@pytest.mark.parametrize(
"dataset, find_breaks", [("openneuro", True), ("openneuro", False)]
)
def test_pipeline_run(dataset, find_breaks):
def test_pipeline_run(pipeline_fixture):
"""Test running the pipeline."""
if dataset == "openneuro":
raw, config, bids_root = load_openneuro_bids()
raw.crop(tmin=0, tmax=60) # take 60 seconds for speed

if find_breaks:
config["find_breaks"] = {}
config["find_breaks"]["min_break_duration"] = 9
config["find_breaks"]["t_start_after_previous"] = 1
config["find_breaks"]["t_stop_before_next"] = 0
config.save("test_config.yaml")
pipeline = ll.LosslessPipeline("test_config.yaml")
not_in_1020 = ["EXG1", "EXG2", "EXG3", "EXG4", "EXG5", "EXG6", "EXG7", "EXG8"]
pipeline.raw = raw.pick("eeg", exclude=not_in_1020).load_data()
pipeline.run_with_raw(pipeline.raw)

if find_breaks:
assert "BAD_break" in raw.annotations.description

Path("test_config.yaml").unlink() # delete config file
shutil.rmtree(bids_root)
assert "BAD_break" in pipeline_fixture.raw.annotations.description


@pytest.mark.parametrize("logging", [True, False])
Expand Down
Loading