Skip to content

Commit

Permalink
replace cache folder in test_runsorter in sorters/tests folder with p…
Browse files Browse the repository at this point in the history
…ytest fixture
  • Loading branch information
paulrignanese committed May 29, 2024
1 parent 2a7f265 commit 173c75a
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/spikeinterface/sorters/tests/test_runsorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,36 @@

ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS"))

#
# if hasattr(pytest, "global_test_folder"):
# cache_folder = pytest.global_test_folder / "sorters"
# else:
# cache_folder = Path("cache_folder") / "sorters"
#
# rec_folder = cache_folder / "recording"

if hasattr(pytest, "global_test_folder"):
cache_folder = pytest.global_test_folder / "sorters"
else:
cache_folder = Path("cache_folder") / "sorters"

rec_folder = cache_folder / "recording"


def setup_module():
import pytest
@pytest.fixture(scope='function')
def setup_module(tmp_path):
rec_folder = tmp_path / "recording"
if rec_folder.exists():
shutil.rmtree(rec_folder)
recording, sorting_gt = generate_ground_truth_recording(num_channels=8, durations=[10.0], seed=2205)
recording = recording.save(folder=rec_folder)
yield [tmp_path, rec_folder]


def test_run_sorter_local():
def test_run_sorter_local(setup_module):
# local_path = download_dataset(remote_path="mearec/mearec_test_10s.h5")
# recording, sorting_true = read_mearec(local_path)
tmp_path, rec_folder = setup_module
recording = load_extractor(rec_folder)

sorter_params = {"detect_threshold": 4.9}

sorting = run_sorter(
"tridesclous",
recording,
output_folder=cache_folder / "sorting_tdc_local",
output_folder=tmp_path / "sorting_tdc_local",
remove_existing_folder=True,
delete_output_folder=False,
verbose=True,
Expand All @@ -48,9 +51,10 @@ def test_run_sorter_local():


@pytest.mark.skipif(ON_GITHUB, reason="Docker tests don't run on github: test locally")
def test_run_sorter_docker():
def test_run_sorter_docker(setup_module):
# mearec_filename = download_dataset(remote_path="mearec/mearec_test_10s.h5", unlock=True)
# recording, sorting_true = read_mearec(mearec_filename)
tmp_path, rec_folder = setup_module

recording = load_extractor(rec_folder)

Expand All @@ -60,7 +64,7 @@ def test_run_sorter_docker():

for installation_mode in ("dev", "pypi", "github"):
print(f"\nTest with installation_mode {installation_mode}")
output_folder = cache_folder / f"sorting_tdc_docker_{installation_mode}"
output_folder = tmp_path / f"sorting_tdc_docker_{installation_mode}"

sorting = run_sorter(
"tridesclous",
Expand All @@ -82,9 +86,10 @@ def test_run_sorter_docker():


@pytest.mark.skipif(ON_GITHUB, reason="Singularity tests don't run on github: test it locally")
def test_run_sorter_singularity():
def test_run_sorter_singularity(setup_module):
# mearec_filename = download_dataset(remote_path="mearec/mearec_test_10s.h5", unlock=True)
# recording, sorting_true = read_mearec(mearec_filename)
tmp_path, rec_folder = setup_module

# use an output folder outside of the package. otherwise dev mode will not work
singularity_cache_folder = Path(si.__file__).parents[3] / "sandbox"
Expand Down

0 comments on commit 173c75a

Please sign in to comment.