From 41462ce08672289845f4a5e06d2d8cdb96e7dba0 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Wed, 29 May 2024 16:12:59 +0100 Subject: [PATCH 01/81] remove the setting of cache folder as global test_core_tools in core/test folder --- src/spikeinterface/core/tests/test_core_tools.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_core_tools.py b/src/spikeinterface/core/tests/test_core_tools.py index c37f356900..ab847226bf 100644 --- a/src/spikeinterface/core/tests/test_core_tools.py +++ b/src/spikeinterface/core/tests/test_core_tools.py @@ -14,12 +14,6 @@ ) -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" - - def test_path_utils_functions(): if platform.system() != "Windows": # posix path From bddfd92c90a970f266aaa20966041dbe4cb3697f Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Wed, 29 May 2024 16:15:24 +0100 Subject: [PATCH 02/81] remove the setting of cache folder as global common_benchmark_testing in sortingcomponents/benchmark/tests folder --- .../benchmark/tests/common_benchmark_testing.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/common_benchmark_testing.py b/src/spikeinterface/sortingcomponents/benchmark/tests/common_benchmark_testing.py index 313f19537e..1e9f8abae9 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/common_benchmark_testing.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/common_benchmark_testing.py @@ -21,12 +21,6 @@ ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sortingcomponents_benchmark" -else: - cache_folder = Path("cache_folder") / "sortingcomponents_benchmark" - - def make_dataset(): recording, gt_sorting = generate_ground_truth_recording( durations=[60.0], From 7d99d6c4e52ec02d5620976edf9635b04e779b7e Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Wed, 29 May 2024 16:16:46 +0100 Subject: [PATCH 03/81] remove the setting of global cache folder as global test_average_across_direction in preprocessing/tests folder --- .../preprocessing/tests/test_average_across_direction.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_average_across_direction.py b/src/spikeinterface/preprocessing/tests/test_average_across_direction.py index 9543a669bc..dc3edc3b1d 100644 --- a/src/spikeinterface/preprocessing/tests/test_average_across_direction.py +++ b/src/spikeinterface/preprocessing/tests/test_average_across_direction.py @@ -8,13 +8,6 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - def test_average_across_direction(): # gradient recording with 100 samples and 10 channels From b23af98d32ace0f34b44220e1e779769687617eb Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Wed, 29 May 2024 16:31:40 +0100 Subject: [PATCH 04/81] replace cache_folder creation and global setting with pytest fixtures tmp_path for test_filter_gaussian in preprocessing/tests folder --- .../tests/test_filter_gaussian.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py b/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py index 7a53e1f069..b2b1b3876d 100644 --- a/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py +++ b/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py @@ -11,19 +11,19 @@ from spikeinterface.core import NumpyRecording -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" / "gaussian_bandpass_filter" -else: - cache_folder = Path("cache_folder") / "preprocessing" / "gaussian_bandpass_filter" +# if hasattr(pytest, "global_test_folder"): +# cache_folder = pytest.global_test_folder / "preprocessing" / "gaussian_bandpass_filter" +# else: +# cache_folder = Path("cache_folder") / "preprocessing" / "gaussian_bandpass_filter" +# +# set_global_tmp_folder(cache_folder) +# cache_folder.mkdir(parents=True, exist_ok=True) -set_global_tmp_folder(cache_folder) -cache_folder.mkdir(parents=True, exist_ok=True) - -def test_filter_gaussian(): +def test_filter_gaussian(tmp_path): recording = generate_recording(num_channels=3) recording.annotate(is_filtered=True) - recording = recording.save(folder=cache_folder / "recording") + recording = recording.save(folder=tmp_path / "recording") rec_filtered = gaussian_filter(recording) @@ -37,8 +37,8 @@ def test_filter_gaussian(): saved_loaded = load_extractor(rec_filtered.to_dict()) check_recordings_equal(rec_filtered, saved_loaded, return_scaled=False) - saved_1job = rec_filtered.save(folder=cache_folder / "1job") - saved_2job = rec_filtered.save(folder=cache_folder / "2job", n_jobs=2, chunk_duration="1s") + saved_1job = rec_filtered.save(folder=tmp_path / "1job") + saved_2job = rec_filtered.save(folder=tmp_path / "2job", n_jobs=2, chunk_duration="1s") for seg_idx in range(rec_filtered.get_num_segments()): original_trace = rec_filtered.get_traces(seg_idx) From cbca727c48462da610724dc784998fd0b509b334 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Wed, 29 May 2024 16:46:26 +0100 Subject: [PATCH 05/81] in progress --- .../tests/test_motion_estimation.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py b/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py index 36f623ebf8..0db8efe5b6 100644 --- a/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py +++ b/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py @@ -28,10 +28,10 @@ plt.ion() plt.show() - -def setup_module(): +@pytest.fixture(scope="module") +def setup_module(tmp_path_factory): recording, sorting = make_dataset() - + cache_folder = tmp_path_factory.mktemp('cache_folder') cache_folder.mkdir(parents=True, exist_ok=True) # detect and localize @@ -50,13 +50,17 @@ def setup_module(): progress_bar=True, pipeline_nodes=pipeline_nodes, ) - np.save(cache_folder / "dataset_peaks.npy", peaks) - np.save(cache_folder / "dataset_peak_locations.npy", peak_locations) + peaks_path = cache_folder / "dataset_peaks.npy" + np.save(peaks_path, peaks) + peak_location_path = cache_folder / "dataset_peak_locations.npy" + np.save(peak_location_path, peak_locations) -def test_estimate_motion(): - recording, sorting = make_dataset() + return recording, sorting, peaks_path, peak_location_path +def test_estimate_motion(setup_module): + # recording, sorting = make_dataset() + recording, sorting, peaks_path, peak_location_path = setup_module peaks = np.load(cache_folder / "dataset_peaks.npy") peak_locations = np.load(cache_folder / "dataset_peak_locations.npy") @@ -234,6 +238,6 @@ def test_estimate_motion(): # assert np.testing.assert_almost_equal(motion0, motion1) -if __name__ == "__main__": - setup_module() - test_estimate_motion() +# if __name__ == "__main__": +# setup_module() +# test_estimate_motion() From 8a63d0617e770838252175786f73a6e5b83d572c Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 09:45:25 +0100 Subject: [PATCH 06/81] replace cache folder with pytest fixture for test_motion_extimation in sortingcomponents/test/ folder --- .../tests/test_motion_estimation.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py b/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py index 0db8efe5b6..62d0d65ecd 100644 --- a/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py +++ b/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py @@ -1,5 +1,5 @@ import pytest -from pathlib import Path + import shutil import numpy as np @@ -7,7 +7,6 @@ from spikeinterface.sortingcomponents.peak_detection import detect_peaks from spikeinterface.sortingcomponents.motion_estimation import estimate_motion - from spikeinterface.sortingcomponents.motion_interpolation import InterpolateMotionRecording from spikeinterface.core.node_pipeline import ExtractDenseWaveforms @@ -15,10 +14,6 @@ from spikeinterface.sortingcomponents.tests.common import make_dataset -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sortingcomponents" -else: - cache_folder = Path("cache_folder") / "sortingcomponents" DEBUG = False @@ -56,11 +51,11 @@ def setup_module(tmp_path_factory): peak_location_path = cache_folder / "dataset_peak_locations.npy" np.save(peak_location_path, peak_locations) - return recording, sorting, peaks_path, peak_location_path + return recording, sorting, cache_folder def test_estimate_motion(setup_module): # recording, sorting = make_dataset() - recording, sorting, peaks_path, peak_location_path = setup_module + recording, sorting, cache_folder = setup_module peaks = np.load(cache_folder / "dataset_peaks.npy") peak_locations = np.load(cache_folder / "dataset_peak_locations.npy") @@ -238,6 +233,6 @@ def test_estimate_motion(setup_module): # assert np.testing.assert_almost_equal(motion0, motion1) -# if __name__ == "__main__": -# setup_module() -# test_estimate_motion() +if __name__ == "__main__": + setup_module() + test_estimate_motion() From 0e4760848e14fdd27e39432c105b31f9ecfb9eed Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 09:47:23 +0100 Subject: [PATCH 07/81] remove of useless cache folder for test_motion_interpolation in sortingcomponents/tests --- .../tests/test_motion_interpolation.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/tests/test_motion_interpolation.py b/src/spikeinterface/sortingcomponents/tests/test_motion_interpolation.py index cc3434b782..de22ee010d 100644 --- a/src/spikeinterface/sortingcomponents/tests/test_motion_interpolation.py +++ b/src/spikeinterface/sortingcomponents/tests/test_motion_interpolation.py @@ -1,9 +1,5 @@ -import pytest -from pathlib import Path import numpy as np -from spikeinterface import download_dataset - from spikeinterface.sortingcomponents.motion_interpolation import ( correct_motion_on_peaks, interpolate_motion_on_traces, @@ -13,12 +9,6 @@ from spikeinterface.sortingcomponents.tests.common import make_dataset -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sortingcomponents" -else: - cache_folder = Path("cache_folder") / "sortingcomponents" - - def make_fake_motion(rec): # make a fake motion vector duration = rec.get_total_duration() From d3dcfc8ab2253257ed60987c657a25946ff27c89 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 10:08:38 +0100 Subject: [PATCH 08/81] rename test_NumpyRecording by setup_NumpyRecording as no tests were done, replace cache_folder with pytest fixture for test_numpy_extractors in core/tests --- .../core/tests/test_numpy_extractors.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/spikeinterface/core/tests/test_numpy_extractors.py b/src/spikeinterface/core/tests/test_numpy_extractors.py index c694026918..22de2ecffc 100644 --- a/src/spikeinterface/core/tests/test_numpy_extractors.py +++ b/src/spikeinterface/core/tests/test_numpy_extractors.py @@ -1,6 +1,3 @@ -import shutil -from pathlib import Path - import pytest import numpy as np @@ -19,13 +16,9 @@ from spikeinterface.core.basesorting import minimum_spike_dtype -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" - -def test_NumpyRecording(): +@pytest.fixture(scope="module") +def setup_NumpyRecording(tmp_path_factory): sampling_frequency = 30000 timeseries_list = [] for seg_index in range(3): @@ -36,9 +29,9 @@ def test_NumpyRecording(): # print(rec) times1 = rec.get_times(1) - + cache_folder = tmp_path_factory.mktemp('cache_folder') rec.save(folder=cache_folder / "test_NumpyRecording") - + return cache_folder def test_SharedMemoryRecording(): rec0 = generate_recording(num_channels=2, durations=[4.0, 3.0]) @@ -57,7 +50,7 @@ def test_SharedMemoryRecording(): del rec -def test_NumpySorting(): +def test_NumpySorting(setup_NumpyRecording): sampling_frequency = 30000 # empty @@ -82,6 +75,9 @@ def test_NumpySorting(): # from other extracrtor num_seg = 2 + + cache_folder = setup_NumpyRecording + file_path = cache_folder / "test_NpzSortingExtractor.npz" create_sorting_npz(num_seg, file_path) other_sorting = NpzSortingExtractor(file_path) From f2b80987c5c43d69c28bca9e8a7dcc36ae1fe71b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 10:56:16 +0100 Subject: [PATCH 09/81] remove useless setting of cache_folder as global variable --- .../tests/test_directional_derivative.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_directional_derivative.py b/src/spikeinterface/preprocessing/tests/test_directional_derivative.py index d863ea9c59..5f887ae35c 100644 --- a/src/spikeinterface/preprocessing/tests/test_directional_derivative.py +++ b/src/spikeinterface/preprocessing/tests/test_directional_derivative.py @@ -1,20 +1,9 @@ -import pytest -from pathlib import Path - -from spikeinterface import set_global_tmp_folder from spikeinterface.core import NumpyRecording from spikeinterface.preprocessing import DirectionalDerivativeRecording, directional_derivative import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - def test_directional_derivative(): # gradient recording with 100 samples and 10 channels From cfd8eeb5553d61b4c96ab08de220974a05538a95 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:02:50 +0100 Subject: [PATCH 10/81] replace cache_folder (study_folder) with pytext fixture for test_groundtruthstudy in comparison/tests/ folder --- .../comparison/tests/test_groundtruthstudy.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/comparison/tests/test_groundtruthstudy.py b/src/spikeinterface/comparison/tests/test_groundtruthstudy.py index b7df085fab..880e8286b5 100644 --- a/src/spikeinterface/comparison/tests/test_groundtruthstudy.py +++ b/src/spikeinterface/comparison/tests/test_groundtruthstudy.py @@ -7,19 +7,13 @@ from spikeinterface.comparison import GroundTruthStudy -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "comparison" -else: - cache_folder = Path("cache_folder") / "comparison" - cache_folder.mkdir(exist_ok=True, parents=True) - -study_folder = cache_folder / "test_groundtruthstudy/" - - -def setup_module(): +@pytest.fixture(scope='module') +def setup_module(tmp_path_factory): + study_folder = tmp_path_factory.mktemp('study_folder') if study_folder.is_dir(): shutil.rmtree(study_folder) create_a_study(study_folder) + return study_folder def simple_preprocess(rec): @@ -74,7 +68,8 @@ def create_a_study(study_folder): # print(study) -def test_GroundTruthStudy(): +def test_GroundTruthStudy(setup_module): + study_folder = setup_module study = GroundTruthStudy(study_folder) print(study) From 00da3a270fba5c0bb5e2693e8a707d291273d510 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:15:26 +0100 Subject: [PATCH 11/81] replace cache_folder with pytext fixture in new cache_folder_creation function for test_node_pipeline.py in core/tests/ folder --- .../core/tests/test_node_pipeline.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/spikeinterface/core/tests/test_node_pipeline.py b/src/spikeinterface/core/tests/test_node_pipeline.py index 76ba5d041b..7e3abc17c1 100644 --- a/src/spikeinterface/core/tests/test_node_pipeline.py +++ b/src/spikeinterface/core/tests/test_node_pipeline.py @@ -18,12 +18,6 @@ ) -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" - - class AmplitudeExtractionNode(PipelineNode): def __init__(self, recording, parents=None, return_output=True, param0=5.5): PipelineNode.__init__(self, recording, parents=parents, return_output=return_output) @@ -68,7 +62,14 @@ def compute(self, traces, peaks, waveforms): return rms_by_channels -def test_run_node_pipeline(): +@pytest.fixture(scope='module') +def cache_folder_creation(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder + + +def test_run_node_pipeline(cache_folder_creation): + cache_folder = cache_folder_creation recording, sorting = generate_ground_truth_recording(num_channels=10, num_units=10, durations=[10.0]) # job_kwargs = dict(chunk_duration="0.5s", n_jobs=2, progress_bar=False) From 2ee63cb367b64af8ecd49a35bbcc750dcf43e76b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:20:30 +0100 Subject: [PATCH 12/81] replace cache_folder with pytext fixture and add new cache_folder_creation function for test_npyfoldersnippets.py in core/tests/ folder --- .../core/tests/test_npyfoldersnippets.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_npyfoldersnippets.py b/src/spikeinterface/core/tests/test_npyfoldersnippets.py index 12edef9d15..2df5fc937e 100644 --- a/src/spikeinterface/core/tests/test_npyfoldersnippets.py +++ b/src/spikeinterface/core/tests/test_npyfoldersnippets.py @@ -6,14 +6,15 @@ from spikeinterface.core import load_extractor from spikeinterface.core import generate_snippets +@pytest.fixture(scope="module") +def cache_folder_creation(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +def test_NpyFolderSnippets(cache_folder_creation): -def test_NpyFolderSnippets(): + cache_folder = cache_folder_creation snippets, _ = generate_snippets(num_channels=10, durations=[2.0, 1.0]) folder = cache_folder / "npy_folder_1" From cd8d5ebcaded01bf490ff13edab9a8a650527a6e Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:23:19 +0100 Subject: [PATCH 13/81] replace cache_folder with pytext fixture and add new cache_folder_creation function for test_motion.py in preprocessing/tests/ folder --- .../preprocessing/tests/test_motion.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_motion.py b/src/spikeinterface/preprocessing/tests/test_motion.py index 7cea531bb4..95976613d5 100644 --- a/src/spikeinterface/preprocessing/tests/test_motion.py +++ b/src/spikeinterface/preprocessing/tests/test_motion.py @@ -1,6 +1,4 @@ import pytest -from pathlib import Path - import shutil @@ -10,15 +8,13 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -print(cache_folder.absolute()) - +@pytest.fixture(scope='module') +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder -def test_estimate_and_correct_motion(): +def test_estimate_and_correct_motion(create_cache_folder): + cache_folder = create_cache_folder rec, sorting = toy_example(num_segments=1, duration=30.0, num_units=10, num_channels=12) print(rec) @@ -34,4 +30,4 @@ def test_estimate_and_correct_motion(): if __name__ == "__main__": print(correct_motion.__doc__) - # test_estimate_and_correct_motion() + #test_estimate_and_correct_motion() From e3c700e90956b5b914d8c54fa291e75f4f2d0311 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:25:04 +0100 Subject: [PATCH 14/81] remove useless setting of cache folder as global variable --- .../preprocessing/tests/test_zero_padding.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_zero_padding.py b/src/spikeinterface/preprocessing/tests/test_zero_padding.py index 954f5ed7e8..092007d379 100644 --- a/src/spikeinterface/preprocessing/tests/test_zero_padding.py +++ b/src/spikeinterface/preprocessing/tests/test_zero_padding.py @@ -9,13 +9,6 @@ from spikeinterface.preprocessing import zero_channel_pad, bandpass_filter, phase_shift from spikeinterface.preprocessing.zero_channel_pad import TracePaddedRecording -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - def test_zero_padding_channel(): num_original_channels = 4 From 150c28450bb2ce4b0e0c7e116972a131269bc5e1 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:25:55 +0100 Subject: [PATCH 15/81] remove useless cache folder creation (was commented) --- .../qualitymetrics/tests/test_metrics_functions.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/spikeinterface/qualitymetrics/tests/test_metrics_functions.py b/src/spikeinterface/qualitymetrics/tests/test_metrics_functions.py index 79fbab8893..346ea0b8d3 100644 --- a/src/spikeinterface/qualitymetrics/tests/test_metrics_functions.py +++ b/src/spikeinterface/qualitymetrics/tests/test_metrics_functions.py @@ -41,11 +41,6 @@ from spikeinterface.core.basesorting import minimum_spike_dtype -# if hasattr(pytest, "global_test_folder"): -# cache_folder = pytest.global_test_folder / "qualitymetrics" -# else: -# cache_folder = Path("cache_folder") / "qualitymetrics" - job_kwargs = dict(n_jobs=2, progress_bar=True, chunk_duration="1s") From d15532333f8f64800d497cc258eb9aac3cc64250 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:26:45 +0100 Subject: [PATCH 16/81] remove useless cache folder creation (was commented) --- .../preprocessing/tests/test_filter_gaussian.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py b/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py index b2b1b3876d..d5cc6b91f8 100644 --- a/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py +++ b/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py @@ -11,14 +11,6 @@ from spikeinterface.core import NumpyRecording -# if hasattr(pytest, "global_test_folder"): -# cache_folder = pytest.global_test_folder / "preprocessing" / "gaussian_bandpass_filter" -# else: -# cache_folder = Path("cache_folder") / "preprocessing" / "gaussian_bandpass_filter" -# -# set_global_tmp_folder(cache_folder) -# cache_folder.mkdir(parents=True, exist_ok=True) - def test_filter_gaussian(tmp_path): recording = generate_recording(num_channels=3) From 63193dc3d75a0738ccca7f7ab67df10c4e02ede7 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:30:39 +0100 Subject: [PATCH 17/81] replace setting of global cache folder by pytest fixture with new create_cache_folder function for test_silence.py in preprocessing/tests/ --- .../preprocessing/tests/test_silence.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_silence.py b/src/spikeinterface/preprocessing/tests/test_silence.py index a362f4dfbd..1b6cf8fc27 100644 --- a/src/spikeinterface/preprocessing/tests/test_silence.py +++ b/src/spikeinterface/preprocessing/tests/test_silence.py @@ -1,8 +1,5 @@ import pytest -from pathlib import Path -import shutil -from spikeinterface import set_global_tmp_folder from spikeinterface.core import generate_recording from spikeinterface.preprocessing import silence_periods @@ -13,15 +10,16 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" +@pytest.fixture(scope='module') +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder -set_global_tmp_folder(cache_folder) +def test_silence(create_cache_folder): + + cache_folder = create_cache_folder -def test_silence(): rec = generate_recording() rec0 = silence_periods(rec, list_periods=[[[0, 1000], [5000, 6000]], []], mode="zeros") From 1aaac62ae8e75a669732df5ed4e6d5db8a87180c Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:36:17 +0100 Subject: [PATCH 18/81] replace setting of cache folder by pytest fixture with new create_cache_folder function for test_binaryrecordingextractor.py in core/tests/ --- .../core/tests/test_binaryrecordingextractor.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_binaryrecordingextractor.py b/src/spikeinterface/core/tests/test_binaryrecordingextractor.py index fb4c3ee3c4..41a7949d08 100644 --- a/src/spikeinterface/core/tests/test_binaryrecordingextractor.py +++ b/src/spikeinterface/core/tests/test_binaryrecordingextractor.py @@ -1,17 +1,18 @@ import pytest import numpy as np -from pathlib import Path from spikeinterface.core import BinaryRecordingExtractor from spikeinterface.core.numpyextractors import NumpyRecording -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope='module') +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder -def test_BinaryRecordingExtractor(): + +def test_BinaryRecordingExtractor(create_cache_folder): + cache_folder = create_cache_folder num_seg = 2 num_channels = 3 num_samples = 30 From 2d150a451fca659d9441d73f12b1ce80cf621b15 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:40:18 +0100 Subject: [PATCH 19/81] replace setting of global cache_folder by pytest fixture with new create_cache_folder function for test_whiten.py in preprocessing/tests/ --- .../preprocessing/tests/test_whiten.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_whiten.py b/src/spikeinterface/preprocessing/tests/test_whiten.py index 40674a08f4..36eabe1f5e 100644 --- a/src/spikeinterface/preprocessing/tests/test_whiten.py +++ b/src/spikeinterface/preprocessing/tests/test_whiten.py @@ -1,21 +1,16 @@ import pytest import numpy as np -from pathlib import Path -from spikeinterface import set_global_tmp_folder from spikeinterface.core import generate_recording from spikeinterface.preprocessing import whiten, scale, compute_whitening_matrix +@pytest.fixture(scope='module') +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - - -def test_whiten(): +def test_whiten(create_cache_folder): + cache_folder = create_cache_folder rec = generate_recording(num_channels=4) print(rec.get_channel_locations()) From 43651b6128fd8ee6c95ee6882a9f211a5f3db198 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 11:42:42 +0100 Subject: [PATCH 20/81] replace setting of cache_folder by pytest fixture with new create_cache_folder function for test_unitsaggregationsorting.py in core/tests/ --- .../core/tests/test_unitsaggregationsorting.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_unitsaggregationsorting.py b/src/spikeinterface/core/tests/test_unitsaggregationsorting.py index 814e75af3d..1cd873097a 100644 --- a/src/spikeinterface/core/tests/test_unitsaggregationsorting.py +++ b/src/spikeinterface/core/tests/test_unitsaggregationsorting.py @@ -1,6 +1,5 @@ import pytest import numpy as np -from pathlib import Path from spikeinterface.core import aggregate_units @@ -8,13 +7,15 @@ from spikeinterface.core import create_sorting_npz -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope='module') +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp('cache_folder') + return cache_folder -def test_unitsaggregationsorting(): +def test_unitsaggregationsorting(create_cache_folder): + cache_folder = create_cache_folder + num_seg = 2 file_path = cache_folder / "test_BaseSorting.npz" From 7be7c667896822fe074fc3e5af0958c78a1f20cc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 10:56:13 +0000 Subject: [PATCH 21/81] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../comparison/tests/test_groundtruthstudy.py | 4 ++-- .../core/tests/test_binaryrecordingextractor.py | 4 ++-- src/spikeinterface/core/tests/test_core_tools.py | 1 + src/spikeinterface/core/tests/test_node_pipeline.py | 4 ++-- src/spikeinterface/core/tests/test_npyfoldersnippets.py | 3 ++- src/spikeinterface/core/tests/test_numpy_extractors.py | 3 ++- .../core/tests/test_unitsaggregationsorting.py | 4 ++-- .../preprocessing/tests/test_filter_gaussian.py | 1 - src/spikeinterface/preprocessing/tests/test_motion.py | 6 ++++-- src/spikeinterface/preprocessing/tests/test_silence.py | 4 ++-- src/spikeinterface/preprocessing/tests/test_whiten.py | 7 +++++-- .../sortingcomponents/tests/test_motion_estimation.py | 4 +++- 12 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/spikeinterface/comparison/tests/test_groundtruthstudy.py b/src/spikeinterface/comparison/tests/test_groundtruthstudy.py index 880e8286b5..a92d6e9f77 100644 --- a/src/spikeinterface/comparison/tests/test_groundtruthstudy.py +++ b/src/spikeinterface/comparison/tests/test_groundtruthstudy.py @@ -7,9 +7,9 @@ from spikeinterface.comparison import GroundTruthStudy -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def setup_module(tmp_path_factory): - study_folder = tmp_path_factory.mktemp('study_folder') + study_folder = tmp_path_factory.mktemp("study_folder") if study_folder.is_dir(): shutil.rmtree(study_folder) create_a_study(study_folder) diff --git a/src/spikeinterface/core/tests/test_binaryrecordingextractor.py b/src/spikeinterface/core/tests/test_binaryrecordingextractor.py index 41a7949d08..a49c210bfe 100644 --- a/src/spikeinterface/core/tests/test_binaryrecordingextractor.py +++ b/src/spikeinterface/core/tests/test_binaryrecordingextractor.py @@ -5,9 +5,9 @@ from spikeinterface.core.numpyextractors import NumpyRecording -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder diff --git a/src/spikeinterface/core/tests/test_core_tools.py b/src/spikeinterface/core/tests/test_core_tools.py index 83101e1478..8e00dcb779 100644 --- a/src/spikeinterface/core/tests/test_core_tools.py +++ b/src/spikeinterface/core/tests/test_core_tools.py @@ -14,6 +14,7 @@ add_suffix, ) + def test_add_suffix(): # first case - no dot provided before extension file_path = "testpath" diff --git a/src/spikeinterface/core/tests/test_node_pipeline.py b/src/spikeinterface/core/tests/test_node_pipeline.py index 7e3abc17c1..03acc9fed1 100644 --- a/src/spikeinterface/core/tests/test_node_pipeline.py +++ b/src/spikeinterface/core/tests/test_node_pipeline.py @@ -62,9 +62,9 @@ def compute(self, traces, peaks, waveforms): return rms_by_channels -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def cache_folder_creation(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder diff --git a/src/spikeinterface/core/tests/test_npyfoldersnippets.py b/src/spikeinterface/core/tests/test_npyfoldersnippets.py index 2df5fc937e..c0d7f303bf 100644 --- a/src/spikeinterface/core/tests/test_npyfoldersnippets.py +++ b/src/spikeinterface/core/tests/test_npyfoldersnippets.py @@ -6,9 +6,10 @@ from spikeinterface.core import load_extractor from spikeinterface.core import generate_snippets + @pytest.fixture(scope="module") def cache_folder_creation(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder diff --git a/src/spikeinterface/core/tests/test_numpy_extractors.py b/src/spikeinterface/core/tests/test_numpy_extractors.py index 22de2ecffc..fecafb8989 100644 --- a/src/spikeinterface/core/tests/test_numpy_extractors.py +++ b/src/spikeinterface/core/tests/test_numpy_extractors.py @@ -29,10 +29,11 @@ def setup_NumpyRecording(tmp_path_factory): # print(rec) times1 = rec.get_times(1) - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") rec.save(folder=cache_folder / "test_NumpyRecording") return cache_folder + def test_SharedMemoryRecording(): rec0 = generate_recording(num_channels=2, durations=[4.0, 3.0]) # print(rec0) diff --git a/src/spikeinterface/core/tests/test_unitsaggregationsorting.py b/src/spikeinterface/core/tests/test_unitsaggregationsorting.py index 1cd873097a..622e33a1eb 100644 --- a/src/spikeinterface/core/tests/test_unitsaggregationsorting.py +++ b/src/spikeinterface/core/tests/test_unitsaggregationsorting.py @@ -7,9 +7,9 @@ from spikeinterface.core import create_sorting_npz -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder diff --git a/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py b/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py index d5cc6b91f8..ad0ac5f59c 100644 --- a/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py +++ b/src/spikeinterface/preprocessing/tests/test_filter_gaussian.py @@ -11,7 +11,6 @@ from spikeinterface.core import NumpyRecording - def test_filter_gaussian(tmp_path): recording = generate_recording(num_channels=3) recording.annotate(is_filtered=True) diff --git a/src/spikeinterface/preprocessing/tests/test_motion.py b/src/spikeinterface/preprocessing/tests/test_motion.py index c316ce8543..577aaaa23a 100644 --- a/src/spikeinterface/preprocessing/tests/test_motion.py +++ b/src/spikeinterface/preprocessing/tests/test_motion.py @@ -11,11 +11,13 @@ import numpy as np -@pytest.fixture(scope='module') + +@pytest.fixture(scope="module") def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder + def test_estimate_and_correct_motion(create_cache_folder): cache_folder = create_cache_folder rec = generate_recording(durations=[30.0], num_channels=12) diff --git a/src/spikeinterface/preprocessing/tests/test_silence.py b/src/spikeinterface/preprocessing/tests/test_silence.py index 1b6cf8fc27..62952f2790 100644 --- a/src/spikeinterface/preprocessing/tests/test_silence.py +++ b/src/spikeinterface/preprocessing/tests/test_silence.py @@ -10,9 +10,9 @@ import numpy as np -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder diff --git a/src/spikeinterface/preprocessing/tests/test_whiten.py b/src/spikeinterface/preprocessing/tests/test_whiten.py index 36eabe1f5e..6c2e3d44a2 100644 --- a/src/spikeinterface/preprocessing/tests/test_whiten.py +++ b/src/spikeinterface/preprocessing/tests/test_whiten.py @@ -4,11 +4,14 @@ from spikeinterface.core import generate_recording from spikeinterface.preprocessing import whiten, scale, compute_whitening_matrix -@pytest.fixture(scope='module') + + +@pytest.fixture(scope="module") def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder + def test_whiten(create_cache_folder): cache_folder = create_cache_folder rec = generate_recording(num_channels=4) diff --git a/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py b/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py index 62d0d65ecd..597eee7a99 100644 --- a/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py +++ b/src/spikeinterface/sortingcomponents/tests/test_motion_estimation.py @@ -23,10 +23,11 @@ plt.ion() plt.show() + @pytest.fixture(scope="module") def setup_module(tmp_path_factory): recording, sorting = make_dataset() - cache_folder = tmp_path_factory.mktemp('cache_folder') + cache_folder = tmp_path_factory.mktemp("cache_folder") cache_folder.mkdir(parents=True, exist_ok=True) # detect and localize @@ -53,6 +54,7 @@ def setup_module(tmp_path_factory): return recording, sorting, cache_folder + def test_estimate_motion(setup_module): # recording, sorting = make_dataset() recording, sorting, cache_folder = setup_module From 0b5fc4ab2116848d2a38f70889c7c4e01a50fd1a Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:10:02 +0100 Subject: [PATCH 22/81] replace setting of cache_folder by pytest fixture with new create_cache_folder function for test_time_handling.py in core/tests/ --- .../tests/test_benchmark_motion_estimation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py index 7f24c07d3d..82c36c569f 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py @@ -9,15 +9,20 @@ from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import ( make_drifting_dataset, - cache_folder, ) from spikeinterface.sortingcomponents.benchmark.benchmark_motion_estimation import MotionEstimationStudy -@pytest.mark.skip() -def test_benchmark_motion_estimaton(): +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + +@pytest.mark.skip() +def test_benchmark_motion_estimaton(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="1s") data = make_drifting_dataset() From 1e458745a644070e1c760396f22d166e619809f2 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:10:46 +0100 Subject: [PATCH 23/81] replace setting of cache_folder by pytest fixture with new create_cache_folder function for test_time_handling.py in core/tests/ --- src/spikeinterface/core/tests/test_time_handling.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_time_handling.py b/src/spikeinterface/core/tests/test_time_handling.py index 8bb8778c76..0783230d1e 100644 --- a/src/spikeinterface/core/tests/test_time_handling.py +++ b/src/spikeinterface/core/tests/test_time_handling.py @@ -1,17 +1,17 @@ import pytest -from pathlib import Path import numpy as np from spikeinterface.core import generate_recording, generate_sorting -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_time_handling(): +def test_time_handling(create_cache_folder): + cache_folder = create_cache_folder durations = [[10], [10, 5]] # test multi-segment From 9597b5006121da10981d6450328c1b193253d71d Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:12:39 +0100 Subject: [PATCH 24/81] replace setting of cache_folder by pytest fixture with new create_cache_folder function for test_basesorting.py in core/tests/ --- src/spikeinterface/core/tests/test_basesorting.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_basesorting.py b/src/spikeinterface/core/tests/test_basesorting.py index 331c65b46a..c3ab2cf298 100644 --- a/src/spikeinterface/core/tests/test_basesorting.py +++ b/src/spikeinterface/core/tests/test_basesorting.py @@ -25,13 +25,15 @@ from spikeinterface.core.testing import check_sorted_arrays_equal, check_sortings_equal from spikeinterface.core.generate import generate_sorting -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_BaseSorting(): + +def test_BaseSorting(create_cache_folder): + cache_folder = create_cache_folder num_seg = 2 file_path = cache_folder / "test_BaseSorting.npz" file_path.parent.mkdir(exist_ok=True) From 8457afdd66924886a7e1934e2331ce980cd6b308 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:14:16 +0100 Subject: [PATCH 25/81] remove useless setting of cache_folder as global variable for test_clip.py in preprocessing/tests/ --- src/spikeinterface/preprocessing/tests/test_clip.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_clip.py b/src/spikeinterface/preprocessing/tests/test_clip.py index 990730cc36..724ba2c963 100644 --- a/src/spikeinterface/preprocessing/tests/test_clip.py +++ b/src/spikeinterface/preprocessing/tests/test_clip.py @@ -1,8 +1,3 @@ -import pytest -from pathlib import Path -import shutil - -from spikeinterface import set_global_tmp_folder from spikeinterface.core import generate_recording from spikeinterface.preprocessing import clip, blank_staturation @@ -10,14 +5,6 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - - def test_clip(): rec = generate_recording() From 391c2d6b083c6cf0d3b82f0628a3eefd29151fdc Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:22:46 +0100 Subject: [PATCH 26/81] replace cache folder import by pytest fixture with new cache_folder_creation for test_benchmark_peak_localization.py in sortingcomponents/benchmark/tests/ folder, even if here the tests are skipped --- .../tests/test_benchmark_peak_localization.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py index fb3ecc61aa..7e77e1e8ec 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py @@ -5,14 +5,21 @@ import matplotlib.pyplot as plt -from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset, cache_folder +from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset from spikeinterface.sortingcomponents.benchmark.benchmark_peak_localization import PeakLocalizationStudy from spikeinterface.sortingcomponents.benchmark.benchmark_peak_localization import UnitLocalizationStudy +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + + @pytest.mark.skip() -def test_benchmark_peak_localization(): +def test_benchmark_peak_localization(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="100ms") # recording, gt_sorting = make_dataset() @@ -55,7 +62,8 @@ def test_benchmark_peak_localization(): @pytest.mark.skip() -def test_benchmark_unit_localization(): +def test_benchmark_unit_localization(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="100ms") recording, gt_sorting = make_dataset() From d9f22a0b073c18b206d505c4d6fbd2012686bef3 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:25:10 +0100 Subject: [PATCH 27/81] replace cache_folder creation by pytest fixture with new cache_folder_creation for test_sorting_folder.py in core/tests/ folder --- .../core/tests/test_sorting_folder.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/spikeinterface/core/tests/test_sorting_folder.py b/src/spikeinterface/core/tests/test_sorting_folder.py index 359e3ee7fc..4ed4d0899e 100644 --- a/src/spikeinterface/core/tests/test_sorting_folder.py +++ b/src/spikeinterface/core/tests/test_sorting_folder.py @@ -1,6 +1,4 @@ import pytest - -from pathlib import Path import shutil import numpy as np @@ -9,13 +7,15 @@ from spikeinterface.core import generate_sorting from spikeinterface.core.testing import check_sorted_arrays_equal, check_sortings_equal -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" + +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_NumpyFolderSorting(): +def test_NumpyFolderSorting(create_cache_folder): + cache_folder = create_cache_folder sorting = generate_sorting(seed=42) folder = cache_folder / "numpy_sorting_1" @@ -33,7 +33,8 @@ def test_NumpyFolderSorting(): ) -def test_NpzFolderSorting(): +def test_NpzFolderSorting(create_cache_folder): + cache_folder = create_cache_folder sorting = generate_sorting(seed=42) folder = cache_folder / "npz_folder_sorting_1" From 200d4e6fc24abbebc2082215dfc89ec2254113d9 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:26:30 +0100 Subject: [PATCH 28/81] replace cache_folder by pytest fixture with new cache_folder_creation for test_globals.py in core/tests/ folder --- src/spikeinterface/core/tests/test_globals.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_globals.py b/src/spikeinterface/core/tests/test_globals.py index a45bb6f49c..21060f2ad3 100644 --- a/src/spikeinterface/core/tests/test_globals.py +++ b/src/spikeinterface/core/tests/test_globals.py @@ -13,13 +13,15 @@ ) from spikeinterface.core.job_tools import fix_job_kwargs -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_global_dataset_folder(): + +def test_global_dataset_folder(create_cache_folder): + cache_folder = create_cache_folder dataset_folder = get_global_dataset_folder() assert dataset_folder.is_dir() new_dataset_folder = cache_folder / "dataset_folder" @@ -28,7 +30,8 @@ def test_global_dataset_folder(): assert new_dataset_folder.is_dir() -def test_global_tmp_folder(): +def test_global_tmp_folder(create_cache_folder): + cache_folder = create_cache_folder tmp_folder = get_global_tmp_folder() assert tmp_folder.is_dir() new_tmp_folder = cache_folder / "tmp_folder" From 395319705e9d1985433d1eb461f12c07d2d5d456 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:32:43 +0100 Subject: [PATCH 29/81] replace cache_folder by pytest fixture with new cache_folder_creation for test_benchmark_motion_interpolation.py in sortingcomponents/benchmark/tests/ folder (even thought it is skipped) --- .../tests/test_benchmark_motion_interpolation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py index 06a3fa9140..18fbf42896 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py @@ -12,7 +12,6 @@ from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import ( make_drifting_dataset, - cache_folder, ) from spikeinterface.sortingcomponents.benchmark.benchmark_motion_interpolation import MotionInterpolationStudy @@ -22,9 +21,15 @@ ) -@pytest.mark.skip() -def test_benchmark_motion_interpolation(): +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + +@pytest.mark.skip() +def test_benchmark_motion_interpolation(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="1s") data = make_drifting_dataset() From 84561ccf7d644920f1a5e354bc0ac3aac5736a46 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:34:55 +0100 Subject: [PATCH 30/81] remove useless cache_folder for test_widgets.py in widgets/tests/ folder --- src/spikeinterface/widgets/tests/test_widgets.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/spikeinterface/widgets/tests/test_widgets.py b/src/spikeinterface/widgets/tests/test_widgets.py index 5366fb864f..44bbae1750 100644 --- a/src/spikeinterface/widgets/tests/test_widgets.py +++ b/src/spikeinterface/widgets/tests/test_widgets.py @@ -1,7 +1,6 @@ import unittest import pytest import os -from pathlib import Path if __name__ != "__main__": import matplotlib @@ -23,12 +22,6 @@ from spikeinterface.preprocessing import scale -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "widgets" -else: - cache_folder = Path("cache_folder") / "widgets" - - ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) KACHERY_CLOUD_SET = bool(os.getenv("KACHERY_CLOUD_CLIENT_ID")) and bool(os.getenv("KACHERY_CLOUD_PRIVATE_KEY")) From 22fc4140a0f3a367aa996080b03e771600579969 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:36:35 +0100 Subject: [PATCH 31/81] replace cache folder with pytest fixture by new create_cache_folder in test_baserecodring.py in core/tests/ folder --- src/spikeinterface/core/tests/test_baserecording.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_baserecording.py b/src/spikeinterface/core/tests/test_baserecording.py index 48dd11d996..00a9bcc529 100644 --- a/src/spikeinterface/core/tests/test_baserecording.py +++ b/src/spikeinterface/core/tests/test_baserecording.py @@ -18,14 +18,15 @@ from spikeinterface.core import generate_recording -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" - cache_folder.mkdir(exist_ok=True, parents=True) +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_BaseRecording(): + +def test_BaseRecording(create_cache_folder): + cache_folder = create_cache_folder num_seg = 2 num_chan = 3 num_samples = 30 From 75bfc37e91018c4fbf74b926b21dfd943abac9ec Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:38:38 +0100 Subject: [PATCH 32/81] replace cache folder with pytest fixture by new create_cache_folder in test_npysnippetextractor.py in core/tests/ folder --- .../core/tests/test_npysnippetsextractor.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_npysnippetsextractor.py b/src/spikeinterface/core/tests/test_npysnippetsextractor.py index 8a44f657fc..b4ca6b234a 100644 --- a/src/spikeinterface/core/tests/test_npysnippetsextractor.py +++ b/src/spikeinterface/core/tests/test_npysnippetsextractor.py @@ -4,13 +4,15 @@ from spikeinterface.core import NpySnippetsExtractor from spikeinterface.core import generate_snippets -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_NpySnippetsExtractor(): + +def test_NpySnippetsExtractor(create_cache_folder): + cache_folder = create_cache_folder segment_durations = [2, 5] sampling_frequency = 30000 file_path = [cache_folder / f"test_NpySnippetsExtractor_{i}.npy" for i in range(len(segment_durations))] From ca8d7b0cbc541b8d4d5144ab51ade843e4755d3b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:49:23 +0100 Subject: [PATCH 33/81] replace useless cache_folder in test_align_snippets.py in preprocessing/tests/ folder --- .../preprocessing/tests/test_align_snippets.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_align_snippets.py b/src/spikeinterface/preprocessing/tests/test_align_snippets.py index 488c9adeb9..104c911278 100644 --- a/src/spikeinterface/preprocessing/tests/test_align_snippets.py +++ b/src/spikeinterface/preprocessing/tests/test_align_snippets.py @@ -3,19 +3,12 @@ but check only for BaseRecording general methods. """ -from pathlib import Path import pytest import numpy as np from spikeinterface.core import generate_snippets from spikeinterface.preprocessing.align_snippets import AlignSnippets -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" - cache_folder.mkdir(exist_ok=True, parents=True) - def test_AlignSnippets(): duration = [4, 3] From 9d6e7d67a842f56546723bd4ad3e6825a3efb5df Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:53:39 +0100 Subject: [PATCH 34/81] replace cache_folder with pytest fixture by new create_cache_folder for test_benchmark_peak_detection.py in sortingcomponents/benchmark/tests/ folder (even thgough it is skipped) --- .../benchmark/tests/test_benchmark_peak_detection.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py index fd09575193..0de600223a 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py @@ -9,14 +9,21 @@ import numpy as np -from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset, cache_folder +from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset from spikeinterface.sortingcomponents.benchmark.benchmark_peak_detection import PeakDetectionStudy from spikeinterface.core.sortinganalyzer import create_sorting_analyzer from spikeinterface.core.template_tools import get_template_extremum_channel +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + + @pytest.mark.skip() -def test_benchmark_peak_detection(): +def test_benchmark_peak_detection(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="100ms") # recording, gt_sorting = make_dataset() From 510267b1d56ac982a12b1fa519c0dea782d41779 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 12:54:43 +0100 Subject: [PATCH 35/81] replace cache_folder with pytest fixture by new create_cache_folder for test_binaryfolder.py in core/tests/ folder --- src/spikeinterface/core/tests/test_binaryfolder.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_binaryfolder.py b/src/spikeinterface/core/tests/test_binaryfolder.py index 4d38d1bc04..58cbf37003 100644 --- a/src/spikeinterface/core/tests/test_binaryfolder.py +++ b/src/spikeinterface/core/tests/test_binaryfolder.py @@ -9,13 +9,14 @@ from spikeinterface.core import generate_recording -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_BinaryFolderRecording(): +def test_BinaryFolderRecording(create_cache_folder): + cache_folder = create_cache_folder rec = generate_recording(num_channels=10, durations=[2.0, 2.0]) folder = cache_folder / "binary_folder_1" From 2fb265c2e5977589bd2adb91880608c37d2c0499 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:30:07 +0100 Subject: [PATCH 36/81] replace cache_folder with pytest fixture by new create_cache_folder for test_deepinterpolation.py in preprocessing/deepinterpolation/tests/ folder --- .../tests/test_deepinterpolation.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index 43b35dfef9..dbcb88ed26 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -20,10 +20,10 @@ HAVE_DEEPINTERPOLATION = False -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "deepinterpolation" -else: - cache_folder = Path("cache_folder") / "deepinterpolation" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder def recording_and_shape(): @@ -67,7 +67,8 @@ def test_deepinterpolation_generator_borders(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") -def test_deepinterpolation_training(recording_and_shape_fixture): +def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_folder): + cache_folder = create_cache_folder recording, desired_shape = recording_and_shape_fixture model_folder = Path(cache_folder) / "training" @@ -93,7 +94,8 @@ def test_deepinterpolation_training(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): +def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_cache_folder): + cache_folder = create_cache_folder recording, desired_shape = recording_and_shape_fixture existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" @@ -121,7 +123,8 @@ def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference(recording_and_shape_fixture): +def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_folder): + cache_folder = create_cache_folder recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" @@ -147,7 +150,8 @@ def test_deepinterpolation_inference(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture): +def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_cache_folder): + cache_folder = create_cache_folder recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" From b1a79d418dd8fdfe5fa324598b824c86e32d7897 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:39:21 +0100 Subject: [PATCH 37/81] replace cache_folder with pytest fixture by new create_cache_folder for test_analyzer_extension_core.py in core/tests/ folder --- .../tests/test_analyzer_extension_core.py | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/spikeinterface/core/tests/test_analyzer_extension_core.py b/src/spikeinterface/core/tests/test_analyzer_extension_core.py index 8991c959ad..fefe03c236 100644 --- a/src/spikeinterface/core/tests/test_analyzer_extension_core.py +++ b/src/spikeinterface/core/tests/test_analyzer_extension_core.py @@ -1,5 +1,4 @@ import pytest -from pathlib import Path import shutil @@ -11,13 +10,14 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def get_sorting_analyzer(format="memory", sparse=True): + +def get_sorting_analyzer(cache_folder, format="memory", sparse=True): recording, sorting = generate_ground_truth_recording( durations=[30.0], sampling_frequency=16000.0, @@ -53,7 +53,7 @@ def get_sorting_analyzer(format="memory", sparse=True): return sorting_analyzer -def _check_result_extension(sorting_analyzer, extension_name): +def _check_result_extension(sorting_analyzer, extension_name, cache_folder): # select unit_ids to several format for format in ("memory", "binary_folder", "zarr"): # for format in ("memory", ): @@ -83,39 +83,42 @@ def _check_result_extension(sorting_analyzer, extension_name): False, ], ) -def test_ComputeRandomSpikes(format, sparse): - sorting_analyzer = get_sorting_analyzer(format=format, sparse=sparse) +def test_ComputeRandomSpikes(format, sparse, create_cache_folder): + cache_folder = create_cache_folder + sorting_analyzer = get_sorting_analyzer(cache_folder, format=format, sparse=sparse) ext = sorting_analyzer.compute("random_spikes", max_spikes_per_unit=10, seed=2205) indices = ext.data["random_spikes_indices"] assert indices.size == 10 * sorting_analyzer.sorting.unit_ids.size - _check_result_extension(sorting_analyzer, "random_spikes") + _check_result_extension(sorting_analyzer, "random_spikes", cache_folder) sorting_analyzer.delete_extension("random_spikes") ext = sorting_analyzer.compute("random_spikes", method="all") indices = ext.data["random_spikes_indices"] assert indices.size == len(sorting_analyzer.sorting.to_spike_vector()) - _check_result_extension(sorting_analyzer, "random_spikes") + _check_result_extension(sorting_analyzer, "random_spikes", cache_folder) @pytest.mark.parametrize("format", ["memory", "binary_folder", "zarr"]) @pytest.mark.parametrize("sparse", [True, False]) -def test_ComputeWaveforms(format, sparse): - sorting_analyzer = get_sorting_analyzer(format=format, sparse=sparse) +def test_ComputeWaveforms(format, sparse, create_cache_folder): + cache_folder = create_cache_folder + sorting_analyzer = get_sorting_analyzer(cache_folder, format=format, sparse=sparse) job_kwargs = dict(n_jobs=2, chunk_duration="1s", progress_bar=True) sorting_analyzer.compute("random_spikes", max_spikes_per_unit=50, seed=2205) ext = sorting_analyzer.compute("waveforms", **job_kwargs) wfs = ext.data["waveforms"] - _check_result_extension(sorting_analyzer, "waveforms") + _check_result_extension(sorting_analyzer, "waveforms", cache_folder) @pytest.mark.parametrize("format", ["memory", "binary_folder", "zarr"]) @pytest.mark.parametrize("sparse", [True, False]) -def test_ComputeTemplates(format, sparse): - sorting_analyzer = get_sorting_analyzer(format=format, sparse=sparse) +def test_ComputeTemplates(format, sparse, create_cache_folder): + cache_folder = create_cache_folder + sorting_analyzer = get_sorting_analyzer(cache_folder, format=format, sparse=sparse) sorting_analyzer.compute("random_spikes", max_spikes_per_unit=50, seed=2205) @@ -187,13 +190,14 @@ def test_ComputeTemplates(format, sparse): # ax.legend() # plt.show() - _check_result_extension(sorting_analyzer, "templates") + _check_result_extension(sorting_analyzer, "templates", cache_folder) @pytest.mark.parametrize("format", ["memory", "binary_folder", "zarr"]) @pytest.mark.parametrize("sparse", [True, False]) -def test_ComputeNoiseLevels(format, sparse): - sorting_analyzer = get_sorting_analyzer(format=format, sparse=sparse) +def test_ComputeNoiseLevels(format, sparse, create_cache_folder): + cache_folder = create_cache_folder + sorting_analyzer = get_sorting_analyzer(cache_folder, format=format, sparse=sparse) sorting_analyzer.compute("noise_levels") print(sorting_analyzer) @@ -212,8 +216,9 @@ def test_get_children_dependencies(): assert rs_children.index("waveforms") < rs_children.index("templates") -def test_delete_on_recompute(): - sorting_analyzer = get_sorting_analyzer(format="memory", sparse=False) +def test_delete_on_recompute(create_cache_folder): + cache_folder = create_cache_folder + sorting_analyzer = get_sorting_analyzer(cache_folder, format="memory", sparse=False) sorting_analyzer.compute("random_spikes") sorting_analyzer.compute("waveforms") sorting_analyzer.compute("templates") @@ -224,8 +229,9 @@ def test_delete_on_recompute(): assert sorting_analyzer.get_extension("waveforms") is None -def test_compute_several(): - sorting_analyzer = get_sorting_analyzer(format="memory", sparse=False) +def test_compute_several(create_cache_folder): + cache_folder = create_cache_folder + sorting_analyzer = get_sorting_analyzer(cache_folder, format="memory", sparse=False) # should raise an error since waveforms depends on random_spikes, which isn't calculated with pytest.raises(AssertionError): From e54b58cf4350c4b7123e7622ab1749bdfef103c2 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:40:42 +0100 Subject: [PATCH 38/81] replace cache_folder with pytest fixture by new create_cache_folder for test_channelslicerecording.py in core/tests/ folder --- .../core/tests/test_channelslicerecording.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_channelslicerecording.py b/src/spikeinterface/core/tests/test_channelslicerecording.py index e2e4dfdb2c..f5738781fc 100644 --- a/src/spikeinterface/core/tests/test_channelslicerecording.py +++ b/src/spikeinterface/core/tests/test_channelslicerecording.py @@ -10,11 +10,14 @@ from spikeinterface.core.generate import generate_recording -def test_ChannelSliceRecording(): - if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" - else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + + +def test_ChannelSliceRecording(create_cache_folder): + cache_folder = create_cache_folder num_seg = 2 num_chan = 3 From 632815aea8cd4a5ccd766d8b5b013594ac06da91 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:42:15 +0100 Subject: [PATCH 39/81] remove useless cache_folder with pytest fixture for test_quality_metric_calculator.py in qualitymetrics/tests/ folder --- .../qualitymetrics/tests/test_quality_metric_calculator.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/spikeinterface/qualitymetrics/tests/test_quality_metric_calculator.py b/src/spikeinterface/qualitymetrics/tests/test_quality_metric_calculator.py index f26e80068f..0950524ebe 100644 --- a/src/spikeinterface/qualitymetrics/tests/test_quality_metric_calculator.py +++ b/src/spikeinterface/qualitymetrics/tests/test_quality_metric_calculator.py @@ -20,12 +20,6 @@ ) -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "qualitymetrics" -else: - cache_folder = Path("cache_folder") / "qualitymetrics" - - job_kwargs = dict(n_jobs=2, progress_bar=True, chunk_duration="1s") From caa6cec427517fede14c88cd6003c56b3471b044 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:44:14 +0100 Subject: [PATCH 40/81] replace cache_folder by pytest fixture with new create_cache_folder for test_basesnippets.py in core/tests folder --- src/spikeinterface/core/tests/test_basesnippets.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/tests/test_basesnippets.py b/src/spikeinterface/core/tests/test_basesnippets.py index cb57b3861e..595973afce 100644 --- a/src/spikeinterface/core/tests/test_basesnippets.py +++ b/src/spikeinterface/core/tests/test_basesnippets.py @@ -14,14 +14,15 @@ from spikeinterface.core.npysnippetsextractor import NpySnippetsExtractor from spikeinterface.core.base import BaseExtractor -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" - cache_folder.mkdir(exist_ok=True, parents=True) +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_BaseSnippets(): + +def test_BaseSnippets(create_cache_folder): + cache_folder = create_cache_folder duration = [4, 3] num_channels = 3 nbefore = 20 From c9966d8947fa48911f388cad6f3f31626dcae02b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:52:21 +0100 Subject: [PATCH 41/81] replace cache_folder by pytest fixture in setup_module for test_container_tools.py in sorters/tests folder --- .../sorters/tests/test_container_tools.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/spikeinterface/sorters/tests/test_container_tools.py b/src/spikeinterface/sorters/tests/test_container_tools.py index 16d1e0a4a4..3ae03abff1 100644 --- a/src/spikeinterface/sorters/tests/test_container_tools.py +++ b/src/spikeinterface/sorters/tests/test_container_tools.py @@ -11,13 +11,10 @@ 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" - -def setup_module(): +@pytest.fixture(scope="module") +def setup_module(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") test_dirs = [cache_folder / "mono", cache_folder / "multi"] for test_dir in test_dirs: if test_dir.exists(): @@ -27,9 +24,11 @@ def setup_module(): rec2, _ = generate_ground_truth_recording(durations=[10, 10, 10]) rec2 = rec2.save(folder=cache_folder / "multi") + return cache_folder -def test_find_recording_folders(): +def test_find_recording_folders(setup_module): + cache_folder = setup_module rec1 = si.load_extractor(cache_folder / "mono") rec2 = si.load_extractor(cache_folder / "multi" / "binary.json", base_folder=cache_folder / "multi") From 53a7dc68f759d5ae3987e29ee2ff47c2232f4c84 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:55:21 +0100 Subject: [PATCH 42/81] replace cache_folder by pytest fixture in setup_module for test_hybrid.py in comparison/tests folder --- .../comparison/tests/test_hybrid.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/spikeinterface/comparison/tests/test_hybrid.py b/src/spikeinterface/comparison/tests/test_hybrid.py index 8c392f7687..ce409ca778 100644 --- a/src/spikeinterface/comparison/tests/test_hybrid.py +++ b/src/spikeinterface/comparison/tests/test_hybrid.py @@ -11,13 +11,9 @@ from spikeinterface.preprocessing import bandpass_filter -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "comparison" / "hybrid" -else: - cache_folder = Path("cache_folder") / "comparison" / "hybrid" - - -def setup_module(): +@pytest.fixture(scope="module") +def setup_module(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") if cache_folder.is_dir(): shutil.rmtree(cache_folder) cache_folder.mkdir(parents=True, exist_ok=True) @@ -31,9 +27,11 @@ def setup_module(): wvf_extractor = extract_waveforms( recording, sorting, folder=cache_folder / "wvf_extractor", ms_before=10.0, ms_after=10.0 ) + return cache_folder -def test_hybrid_units_recording(): +def test_hybrid_units_recording(setup_module): + cache_folder = setup_module wvf_extractor = load_waveforms(cache_folder / "wvf_extractor") print(wvf_extractor) print(wvf_extractor.sorting_analyzer) @@ -63,7 +61,8 @@ def test_hybrid_units_recording(): check_recordings_equal(hybrid_units_recording, saved_2job, return_scaled=False) -def test_hybrid_spikes_recording(): +def test_hybrid_spikes_recording(setup_module): + cache_folder = setup_module wvf_extractor = load_waveforms(cache_folder / "wvf_extractor") recording = wvf_extractor.recording sorting = wvf_extractor.sorting From 5df78c86d1441770177b8185122c65c73d512b2a Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 13:58:15 +0100 Subject: [PATCH 43/81] replace cache_folder import from common.py by pytest fixture with new create_cache_folder for test_report.py in exporters/tests folder --- src/spikeinterface/exporters/tests/common.py | 5 ----- src/spikeinterface/exporters/tests/test_report.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/spikeinterface/exporters/tests/common.py b/src/spikeinterface/exporters/tests/common.py index a6fc2abf99..78a9c82860 100644 --- a/src/spikeinterface/exporters/tests/common.py +++ b/src/spikeinterface/exporters/tests/common.py @@ -5,11 +5,6 @@ from spikeinterface.core import generate_ground_truth_recording, create_sorting_analyzer, compute_sparsity -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "exporters" -else: - cache_folder = Path("cache_folder") / "exporters" - def make_sorting_analyzer(sparse=True, with_group=False): recording, sorting = generate_ground_truth_recording( diff --git a/src/spikeinterface/exporters/tests/test_report.py b/src/spikeinterface/exporters/tests/test_report.py index cd000bc077..92383a1458 100644 --- a/src/spikeinterface/exporters/tests/test_report.py +++ b/src/spikeinterface/exporters/tests/test_report.py @@ -1,4 +1,3 @@ -from pathlib import Path import shutil import pytest @@ -6,13 +5,19 @@ from spikeinterface.exporters import export_report from spikeinterface.exporters.tests.common import ( - cache_folder, make_sorting_analyzer, sorting_analyzer_sparse_for_export, ) -def test_export_report(sorting_analyzer_sparse_for_export): +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + + +def test_export_report(sorting_analyzer_sparse_for_export, create_cache_folder): + cache_folder = create_cache_folder report_folder = cache_folder / "report" if report_folder.exists(): shutil.rmtree(report_folder) From 94ac62ccd08b8828cd0b39555a85106e84d75158 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:31:41 +0100 Subject: [PATCH 44/81] replace cache_folder import from common.py by pytest fixture with new create_cache_folder for test_export_to_phy.py in exporters/tests folder --- .../exporters/tests/test_export_to_phy.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/exporters/tests/test_export_to_phy.py b/src/spikeinterface/exporters/tests/test_export_to_phy.py index 18ba15b975..ddd467be4e 100644 --- a/src/spikeinterface/exporters/tests/test_export_to_phy.py +++ b/src/spikeinterface/exporters/tests/test_export_to_phy.py @@ -1,6 +1,5 @@ import pytest import shutil -from pathlib import Path import numpy as np @@ -11,7 +10,6 @@ from spikeinterface.exporters import export_to_phy from spikeinterface.exporters.tests.common import ( - cache_folder, make_sorting_analyzer, sorting_analyzer_sparse_for_export, sorting_analyzer_with_group_for_export, @@ -19,7 +17,14 @@ ) -def test_export_to_phy_dense(sorting_analyzer_dense_for_export): +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + + +def test_export_to_phy_dense(sorting_analyzer_dense_for_export, create_cache_folder): + cache_folder = create_cache_folder output_folder1 = cache_folder / "phy_output_dense" for f in (output_folder1,): if f.is_dir(): @@ -38,7 +43,8 @@ def test_export_to_phy_dense(sorting_analyzer_dense_for_export): ) -def test_export_to_phy_sparse(sorting_analyzer_sparse_for_export): +def test_export_to_phy_sparse(sorting_analyzer_sparse_for_export, create_cache_folder): + cache_folder = create_cache_folder output_folder1 = cache_folder / "phy_output_1" output_folder2 = cache_folder / "phy_output_2" for f in (output_folder1, output_folder2): @@ -70,7 +76,8 @@ def test_export_to_phy_sparse(sorting_analyzer_sparse_for_export): ) -def test_export_to_phy_by_property(sorting_analyzer_with_group_for_export): +def test_export_to_phy_by_property(sorting_analyzer_with_group_for_export, create_cache_folder): + cache_folder = create_cache_folder output_folder = cache_folder / "phy_output_property" for f in (output_folder,): From 7c6dd89f0057d4d7288559f86742486ea244636d Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:39:54 +0100 Subject: [PATCH 45/81] replace cache_folder import from common_benchmark_testing.py by pytest fixture with new create_cache_folder for test_benchmark_clustering.py in sortingcomponents/benchmark/tests folder --- .../benchmark/tests/test_benchmark_clustering.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py index d9d07370cb..228d79aa54 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py @@ -1,20 +1,25 @@ import pytest import pandas as pd -from pathlib import Path import matplotlib.pyplot as plt import numpy as np import shutil -from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset, cache_folder +from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset from spikeinterface.sortingcomponents.benchmark.benchmark_clustering import ClusteringStudy from spikeinterface.core.sortinganalyzer import create_sorting_analyzer from spikeinterface.core.template_tools import get_template_extremum_channel -@pytest.mark.skip() -def test_benchmark_clustering(): +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + +@pytest.mark.skip() +def test_benchmark_clustering(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="1s") recording, gt_sorting, gt_analyzer = make_dataset() From c57904c62e4f42a70b0724c7bbe3a7e57499a863 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:45:21 +0100 Subject: [PATCH 46/81] replace cache_folder import from common_benchmark_testing.py by pytest fixture with new create_cache_folder for test_benchmark_peak_selection.py and test_benchmark_matching.py sortingcomponents/benchmark/tests folder --- .../benchmark/tests/test_benchmark_matching.py | 12 ++++++++---- .../benchmark/tests/test_benchmark_peak_selection.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py index 1aae51c9ef..614c7857b4 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py @@ -4,7 +4,6 @@ import spikeinterface.full as si import pandas as pd -from pathlib import Path import matplotlib.pyplot as plt from spikeinterface.core import ( @@ -14,15 +13,20 @@ from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import ( make_dataset, - cache_folder, compute_gt_templates, ) from spikeinterface.sortingcomponents.benchmark.benchmark_matching import MatchingStudy -@pytest.mark.skip() -def test_benchmark_matching(): +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + +@pytest.mark.skip() +def test_benchmark_matching(create_cache_folder): + cache_folder = create_cache_folder job_kwargs = dict(n_jobs=0.8, chunk_duration="100ms") recording, gt_sorting, gt_analyzer = make_dataset() diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py index f90a0c56d6..bd70d280b7 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py @@ -5,11 +5,18 @@ from pathlib import Path import matplotlib.pyplot as plt -from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset, cache_folder +from spikeinterface.sortingcomponents.benchmark.tests.common_benchmark_testing import make_dataset + + +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder @pytest.mark.skip() -def test_benchmark_peak_selection(): +def test_benchmark_peak_selection(create_cache_folder): + cache_folder = create_cache_folder pass From df8b4847faa19f610f269fbc2499cfa0dcae3c4a Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:45:57 +0100 Subject: [PATCH 47/81] remove useless cache_folder for test_align_sorting.py in postprocessing/tests/ folder --- .../postprocessing/tests/test_align_sorting.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/spikeinterface/postprocessing/tests/test_align_sorting.py b/src/spikeinterface/postprocessing/tests/test_align_sorting.py index e5c70ae4b2..a02e224984 100644 --- a/src/spikeinterface/postprocessing/tests/test_align_sorting.py +++ b/src/spikeinterface/postprocessing/tests/test_align_sorting.py @@ -1,6 +1,5 @@ import pytest import shutil -from pathlib import Path import pytest @@ -11,11 +10,6 @@ from spikeinterface.postprocessing import align_sorting -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "postprocessing" -else: - cache_folder = Path("cache_folder") / "postprocessing" - def test_align_sorting(): sorting = generate_sorting(durations=[10.0], seed=0) From 8f95f63bfc5b55396813cd4e7e70e57a9114562b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:49:41 +0100 Subject: [PATCH 48/81] replace cache_folder by pytest fixture with new create_cache_folder for test_drift_tools.py in generation/tests/ folder --- .../generation/tests/test_drift_tools.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/generation/tests/test_drift_tools.py b/src/spikeinterface/generation/tests/test_drift_tools.py index e64e64ffda..b0262b3806 100644 --- a/src/spikeinterface/generation/tests/test_drift_tools.py +++ b/src/spikeinterface/generation/tests/test_drift_tools.py @@ -1,6 +1,5 @@ import pytest import numpy as np -from pathlib import Path import shutil from spikeinterface.generation import ( @@ -16,10 +15,10 @@ from probeinterface import generate_multi_columns_probe -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "generation" -else: - cache_folder = Path("cache_folder") / "generation" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder def make_some_templates(): @@ -121,7 +120,8 @@ def test_DriftingTemplates(): ) -def test_InjectDriftingTemplatesRecording(): +def test_InjectDriftingTemplatesRecording(create_cache_folder): + cache_folder = create_cache_folder templates = make_some_templates() probe = templates.probe From 0f91fc235e71d888759c3cf896d55f45f152bf62 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:51:30 +0100 Subject: [PATCH 49/81] replace cache_folder by pytest fixture with new create_cache_folder for test_mdaextractors.py in extractors/tests/ folder --- .../extractors/tests/test_mdaextractors.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/extractors/tests/test_mdaextractors.py b/src/spikeinterface/extractors/tests/test_mdaextractors.py index 6440e575d5..5a17a87c9d 100644 --- a/src/spikeinterface/extractors/tests/test_mdaextractors.py +++ b/src/spikeinterface/extractors/tests/test_mdaextractors.py @@ -4,13 +4,15 @@ from spikeinterface.core import generate_ground_truth_recording from spikeinterface.extractors import MdaRecordingExtractor, MdaSortingExtractor -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "extractors" -else: - cache_folder = Path("cache_folder") / "extractors" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_mda_extractors(): + +def test_mda_extractors(create_cache_folder): + cache_folder = create_cache_folder rec, sort = generate_ground_truth_recording(durations=[10.0], num_units=10) MdaRecordingExtractor.write_recording(rec, cache_folder / "mdatest") From 9b0bb09c7ec4a30cd098dd89808ce8a31d798869 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:53:59 +0100 Subject: [PATCH 50/81] replace cache_folder by pytest fixture with new create_cache_folder for test_shybridextractors.py in extractors/tests/ folder (event hought it is skipped) --- .../extractors/tests/test_shybridextractors.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/extractors/tests/test_shybridextractors.py b/src/spikeinterface/extractors/tests/test_shybridextractors.py index a0164fd119..a091986dee 100644 --- a/src/spikeinterface/extractors/tests/test_shybridextractors.py +++ b/src/spikeinterface/extractors/tests/test_shybridextractors.py @@ -1,17 +1,19 @@ import pytest -from pathlib import Path + from spikeinterface.core import generate_ground_truth_recording from spikeinterface.core.testing import check_recordings_equal, check_sortings_equal from spikeinterface.extractors import SHYBRIDRecordingExtractor, SHYBRIDSortingExtractor -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "extractors" -else: - cache_folder = Path("cache_folder") / "extractors" + +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder @pytest.mark.skipif(True, reason="SHYBRID only tested locally") -def test_shybrid_extractors(): +def test_shybrid_extractors(create_cache_folder): + cache_folder = create_cache_folder rec, sort = generate_ground_truth_recording(durations=[10.0], num_units=10) SHYBRIDSortingExtractor.write_sorting(sort, cache_folder / "shybridtest") From 2f39eaae94b14de1ee3c1319ad6542950d20cd73 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:56:34 +0100 Subject: [PATCH 51/81] removed useless cache_folder_creation and global setting for common.py, test_auto_merge.py and test_sortingview_curation.py in curation/tests/ folder --- src/spikeinterface/curation/tests/common.py | 7 ------- src/spikeinterface/curation/tests/test_auto_merge.py | 6 ------ .../curation/tests/test_sortingview_curation.py | 8 -------- 3 files changed, 21 deletions(-) diff --git a/src/spikeinterface/curation/tests/common.py b/src/spikeinterface/curation/tests/common.py index 5a288a35c8..9cd20f4bfc 100644 --- a/src/spikeinterface/curation/tests/common.py +++ b/src/spikeinterface/curation/tests/common.py @@ -1,17 +1,10 @@ from __future__ import annotations import pytest -from pathlib import Path from spikeinterface.core import generate_ground_truth_recording, create_sorting_analyzer from spikeinterface.qualitymetrics import compute_quality_metrics -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "curation" -else: - cache_folder = Path("cache_folder") / "curation" - - job_kwargs = dict(n_jobs=-1) diff --git a/src/spikeinterface/curation/tests/test_auto_merge.py b/src/spikeinterface/curation/tests/test_auto_merge.py index bbf861dac9..93c302f1f6 100644 --- a/src/spikeinterface/curation/tests/test_auto_merge.py +++ b/src/spikeinterface/curation/tests/test_auto_merge.py @@ -12,12 +12,6 @@ from spikeinterface.curation.tests.common import make_sorting_analyzer, sorting_analyzer_for_curation -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "curation" -else: - cache_folder = Path("cache_folder") / "curation" - - def test_get_auto_merge_list(sorting_analyzer_for_curation): sorting = sorting_analyzer_for_curation.sorting diff --git a/src/spikeinterface/curation/tests/test_sortingview_curation.py b/src/spikeinterface/curation/tests/test_sortingview_curation.py index 5ac82aab86..d524a599de 100644 --- a/src/spikeinterface/curation/tests/test_sortingview_curation.py +++ b/src/spikeinterface/curation/tests/test_sortingview_curation.py @@ -16,19 +16,11 @@ ) from spikeinterface.curation import apply_sortingview_curation -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "curation" -else: - cache_folder = Path("cache_folder") / "curation" - parent_folder = Path(__file__).parent ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) KACHERY_CLOUD_SET = bool(os.getenv("KACHERY_CLOUD_CLIENT_ID")) and bool(os.getenv("KACHERY_CLOUD_PRIVATE_KEY")) -set_global_tmp_folder(cache_folder) - - # this needs to be run only once: if we want to regenerate we need to start with sorting result # TODO : regenerate the # def generate_sortingview_curation_dataset(): From 84effa8bf73593e3b443058ef8a9cc847254d832 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:58:15 +0100 Subject: [PATCH 52/81] removed useless cache_folder_creation setting for common.py, test_noise_levels_propagation.py in core/tests/ folder --- .../core/tests/test_noise_levels_propagation.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/spikeinterface/core/tests/test_noise_levels_propagation.py b/src/spikeinterface/core/tests/test_noise_levels_propagation.py index 6f1b46bd33..421f709d06 100644 --- a/src/spikeinterface/core/tests/test_noise_levels_propagation.py +++ b/src/spikeinterface/core/tests/test_noise_levels_propagation.py @@ -7,13 +7,6 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - def test_skip_noise_levels_propagation(): rec = generate_recording(durations=[5.0], num_channels=4) From 83d1a1e8ec93cf917acd1f333dfa999213ff8e46 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 14:59:55 +0100 Subject: [PATCH 53/81] replaced cache_folder by pytest fixture with new create_cache_folder for test_NpzSortingExtractor.py in core/tests/ folder --- .../core/tests/test_npzsortingextractor.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_npzsortingextractor.py b/src/spikeinterface/core/tests/test_npzsortingextractor.py index a9c34d97df..6540a2cd42 100644 --- a/src/spikeinterface/core/tests/test_npzsortingextractor.py +++ b/src/spikeinterface/core/tests/test_npzsortingextractor.py @@ -4,13 +4,15 @@ from spikeinterface.core import NpzSortingExtractor from spikeinterface.core import create_sorting_npz -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def test_NpzSortingExtractor(): + +def test_NpzSortingExtractor(create_cache_folder): + cache_folder = create_cache_folder num_seg = 2 file_path = cache_folder / "test_NpzSortingExtractor.npz" From 32ff6bce677abc859f1ef67f336610ff26e3309f Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 15:02:13 +0100 Subject: [PATCH 54/81] replaced cache_folder by pytest fixture with new create_cache_folder for test_waveform_tools.py in core/tests/ folder --- src/spikeinterface/core/tests/test_waveform_tools.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_waveform_tools.py b/src/spikeinterface/core/tests/test_waveform_tools.py index 25396841cc..757c08c5c7 100644 --- a/src/spikeinterface/core/tests/test_waveform_tools.py +++ b/src/spikeinterface/core/tests/test_waveform_tools.py @@ -15,10 +15,10 @@ ) -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder def _check_all_wf_equal(list_wfs_arrays): @@ -41,7 +41,8 @@ def get_dataset(): return recording, sorting -def test_waveform_tools(): +def test_waveform_tools(create_cache_folder): + cache_folder = create_cache_folder # durations = [30, 40] # sampling_frequency = 30000.0 From 496062c1ed8aa670ceb2017b3f15f4e2676563b0 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 15:03:09 +0100 Subject: [PATCH 55/81] replaced cache_folder by pytest fixture with new create_cache_folder for test_waveforms_extractor_backwards_compatibility.py in core/tests/ folder --- ...est_waveforms_extractor_backwards_compatibility.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py b/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py index 9688dc7825..8d7bc341e1 100644 --- a/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py +++ b/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py @@ -16,10 +16,10 @@ from spikeinterface.core import extract_waveforms as old_extract_waveforms -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "core" -else: - cache_folder = Path("cache_folder") / "core" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder def get_dataset(): @@ -45,7 +45,8 @@ def get_dataset(): return recording, sorting -def test_extract_waveforms(): +def test_extract_waveforms(create_cache_folder): + cache_folder = create_cache_folder recording, sorting = get_dataset() folder = cache_folder / "old_waveforms_extractor" From 184b4da205c46ee87877384848a076faa5207e93 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 15:40:57 +0100 Subject: [PATCH 56/81] remove useless import (copypaste mistake) --- src/spikeinterface/preprocessing/tests/test_motion.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_motion.py b/src/spikeinterface/preprocessing/tests/test_motion.py index 577aaaa23a..b994bcc18f 100644 --- a/src/spikeinterface/preprocessing/tests/test_motion.py +++ b/src/spikeinterface/preprocessing/tests/test_motion.py @@ -7,8 +7,6 @@ from spikeinterface.preprocessing import correct_motion, load_motion_info -from spikeinterface.extractors import toy_example - import numpy as np From 9e7c92884443456f09ba3f59b30dcc7be7f0e9a7 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Thu, 30 May 2024 16:23:22 +0100 Subject: [PATCH 57/81] Revert "replace cache_folder with pytest fixture by new create_cache_folder for test_deepinterpolation.py in preprocessing/deepinterpolation/tests/ folder" This reverts commit 2fb265c2e5977589bd2adb91880608c37d2c0499. --- .../tests/test_deepinterpolation.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index dbcb88ed26..43b35dfef9 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -20,10 +20,10 @@ HAVE_DEEPINTERPOLATION = False -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder +if hasattr(pytest, "global_test_folder"): + cache_folder = pytest.global_test_folder / "deepinterpolation" +else: + cache_folder = Path("cache_folder") / "deepinterpolation" def recording_and_shape(): @@ -67,8 +67,7 @@ def test_deepinterpolation_generator_borders(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") -def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_folder): - cache_folder = create_cache_folder +def test_deepinterpolation_training(recording_and_shape_fixture): recording, desired_shape = recording_and_shape_fixture model_folder = Path(cache_folder) / "training" @@ -94,8 +93,7 @@ def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_fo @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_cache_folder): - cache_folder = create_cache_folder +def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): recording, desired_shape = recording_and_shape_fixture existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" @@ -123,8 +121,7 @@ def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, creat @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_folder): - cache_folder = create_cache_folder +def test_deepinterpolation_inference(recording_and_shape_fixture): recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" @@ -150,8 +147,7 @@ def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_f @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_cache_folder): - cache_folder = create_cache_folder +def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture): recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" From f02d45b46d7274ec247d9d32fc7606f3a3a7805e Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:05:06 +0100 Subject: [PATCH 58/81] replace cache_folder by pytest fixture in common_extension_tests.py with new create_cache_folder method, and modify test_template_similarity.py to have the test function as method of the class which is inheriting the pytest fixture from AnalyzerExtensionCommonTestSuite class in common_extension_tests.py --- .../tests/common_extension_tests.py | 51 +++++++++---------- .../tests/test_template_similarity.py | 35 ++++++------- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/spikeinterface/postprocessing/tests/common_extension_tests.py b/src/spikeinterface/postprocessing/tests/common_extension_tests.py index bf462a9466..c7ebbbcf7e 100644 --- a/src/spikeinterface/postprocessing/tests/common_extension_tests.py +++ b/src/spikeinterface/postprocessing/tests/common_extension_tests.py @@ -5,21 +5,12 @@ import pandas as pd import shutil import platform -from pathlib import Path from spikeinterface.core import generate_ground_truth_recording from spikeinterface.core import create_sorting_analyzer from spikeinterface.core import estimate_sparsity -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "postprocessing" -else: - cache_folder = Path("cache_folder") / "postprocessing" - -cache_folder.mkdir(exist_ok=True, parents=True) - - def get_dataset(): recording, sorting = generate_ground_truth_recording( durations=[15.0, 5.0], @@ -43,24 +34,7 @@ def get_dataset(): return recording, sorting -def get_sorting_analyzer(recording, sorting, format="memory", sparsity=None, name=""): - sparse = sparsity is not None - if format == "memory": - folder = None - elif format == "binary_folder": - folder = cache_folder / f"test_{name}_sparse{sparse}_{format}" - elif format == "zarr": - folder = cache_folder / f"test_{name}_sparse{sparse}_{format}.zarr" - if folder and folder.exists(): - shutil.rmtree(folder) - - sorting_analyzer = create_sorting_analyzer( - sorting, recording, format=format, folder=folder, sparse=False, sparsity=sparsity - ) - - return sorting_analyzer - - +@pytest.mark.usefixtures("create_cache_folder") class AnalyzerExtensionCommonTestSuite: """ Common tests with class approach to compute extension on several cases (3 format x 2 sparsity) @@ -85,10 +59,31 @@ def setUpClass(cls): def extension_name(self): return self.extension_class.extension_name + @pytest.fixture(autouse=True) + def create_cache_folder(self, tmp_path_factory): + self.cache_folder = tmp_path_factory.mktemp("cache_folder") + + def get_sorting_analyzer(self, recording, sorting, format="memory", sparsity=None, name=""): + sparse = sparsity is not None + if format == "memory": + folder = None + elif format == "binary_folder": + folder = self.cache_folder / f"test_{name}_sparse{sparse}_{format}" + elif format == "zarr": + folder = self.cache_folder / f"test_{name}_sparse{sparse}_{format}.zarr" + if folder and folder.exists(): + shutil.rmtree(folder) + + sorting_analyzer = create_sorting_analyzer( + sorting, recording, format=format, folder=folder, sparse=False, sparsity=sparsity + ) + + return sorting_analyzer + def _prepare_sorting_analyzer(self, format, sparse): # prepare a SortingAnalyzer object with depencies already computed sparsity_ = self.sparsity if sparse else None - sorting_analyzer = get_sorting_analyzer( + sorting_analyzer = self.get_sorting_analyzer( self.recording, self.sorting, format=format, sparsity=sparsity_, name=self.extension_class.extension_name ) sorting_analyzer.compute("random_spikes", max_spikes_per_unit=50, seed=2205) diff --git a/src/spikeinterface/postprocessing/tests/test_template_similarity.py b/src/spikeinterface/postprocessing/tests/test_template_similarity.py index 534c909592..1693530454 100644 --- a/src/spikeinterface/postprocessing/tests/test_template_similarity.py +++ b/src/spikeinterface/postprocessing/tests/test_template_similarity.py @@ -2,7 +2,6 @@ from spikeinterface.postprocessing.tests.common_extension_tests import ( AnalyzerExtensionCommonTestSuite, - get_sorting_analyzer, get_dataset, ) @@ -15,30 +14,28 @@ class SimilarityExtensionTest(AnalyzerExtensionCommonTestSuite, unittest.TestCas dict(method="cosine_similarity"), ] + def test_check_equal_template_with_distribution_overlap(self): + recording, sorting = get_dataset() -def test_check_equal_template_with_distribution_overlap(): + sorting_analyzer = self.get_sorting_analyzer(recording=recording, sorting=sorting, sparsity=None) + sorting_analyzer.compute("random_spikes") + sorting_analyzer.compute("waveforms") + sorting_analyzer.compute("templates") - recording, sorting = get_dataset() + wf_ext = sorting_analyzer.get_extension("waveforms") - sorting_analyzer = get_sorting_analyzer(recording, sorting, sparsity=None) - sorting_analyzer.compute("random_spikes") - sorting_analyzer.compute("waveforms") - sorting_analyzer.compute("templates") - - wf_ext = sorting_analyzer.get_extension("waveforms") - - for unit_id0 in sorting_analyzer.unit_ids: - waveforms0 = wf_ext.get_waveforms_one_unit(unit_id0) - for unit_id1 in sorting_analyzer.unit_ids: - if unit_id0 == unit_id1: - continue - waveforms1 = wf_ext.get_waveforms_one_unit(unit_id1) - check_equal_template_with_distribution_overlap(waveforms0, waveforms1) + for unit_id0 in sorting_analyzer.unit_ids: + waveforms0 = wf_ext.get_waveforms_one_unit(unit_id0) + for unit_id1 in sorting_analyzer.unit_ids: + if unit_id0 == unit_id1: + continue + waveforms1 = wf_ext.get_waveforms_one_unit(unit_id1) + check_equal_template_with_distribution_overlap(waveforms0, waveforms1) if __name__ == "__main__": - # test = SimilarityExtensionTest() + test = SimilarityExtensionTest() # test.setUpClass() # test.test_extension() - test_check_equal_template_with_distribution_overlap() + # test_check_equal_template_with_distribution_overlap() From 4c751467ce3cd5867e39faeef7d3db5d68e38d8a Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:24:30 +0100 Subject: [PATCH 59/81] removal of a decorator use in debugging that I forgot about --- .../postprocessing/tests/common_extension_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/spikeinterface/postprocessing/tests/common_extension_tests.py b/src/spikeinterface/postprocessing/tests/common_extension_tests.py index c7ebbbcf7e..67c571eb06 100644 --- a/src/spikeinterface/postprocessing/tests/common_extension_tests.py +++ b/src/spikeinterface/postprocessing/tests/common_extension_tests.py @@ -34,7 +34,6 @@ def get_dataset(): return recording, sorting -@pytest.mark.usefixtures("create_cache_folder") class AnalyzerExtensionCommonTestSuite: """ Common tests with class approach to compute extension on several cases (3 format x 2 sparsity) From 30706d45b186d50dd408f0700b13b7ec4808c6e0 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:29:23 +0100 Subject: [PATCH 60/81] replace cache_folder by pytest fixture with new create_cache_folder method for SorterCommonTestSuite and SnippetsSorterCommonTestSuite in common_tests.py --- .../sorters/tests/common_tests.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/sorters/tests/common_tests.py b/src/spikeinterface/sorters/tests/common_tests.py index 5339918f11..0bcd38c433 100644 --- a/src/spikeinterface/sorters/tests/common_tests.py +++ b/src/spikeinterface/sorters/tests/common_tests.py @@ -1,18 +1,12 @@ from __future__ import annotations import pytest -from pathlib import Path import shutil from spikeinterface import generate_ground_truth_recording from spikeinterface.sorters import run_sorter from spikeinterface.core.snippets_tools import snippets_from_sorting -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" - class SorterCommonTestSuite: """ @@ -23,12 +17,16 @@ class SorterCommonTestSuite: SorterClass = None + @pytest.fixture(autouse=True) + def create_cache_folder(self, tmp_path_factory): + self.cache_folder = tmp_path_factory.mktemp("cache_folder") + def setUp(self): recording, sorting_gt = generate_ground_truth_recording(num_channels=4, durations=[60], seed=0) - rec_folder = cache_folder / "rec" + rec_folder = self.cache_folder / "rec" if rec_folder.is_dir(): shutil.rmtree(rec_folder) - self.recording = recording.save(folder=cache_folder / "rec", verbose=False, format="binary") + self.recording = recording.save(folder=self.cache_folder / "rec", verbose=False, format="binary") print(self.recording) def test_with_run(self): @@ -39,7 +37,7 @@ def test_with_run(self): sorter_name = self.SorterClass.sorter_name - output_folder = cache_folder / sorter_name + output_folder = self.cache_folder / sorter_name sorter_params = self.SorterClass.default_params() @@ -77,11 +75,15 @@ class SnippetsSorterCommonTestSuite: * run once """ + @pytest.fixture(autouse=True) + def create_cache_folder(self, tmp_path_factory): + self.cache_folder = tmp_path_factory.mktemp("cache_folder") + SorterClass = None def setUp(self): recording, sorting_gt = generate_ground_truth_recording(num_channels=4, durations=[60], seed=0) - snippets_folder = cache_folder / "snippets" + snippets_folder = self.cache_folder / "snippets" if snippets_folder.is_dir(): shutil.rmtree(snippets_folder) @@ -98,7 +100,7 @@ def test_with_run(self): sorter_name = self.SorterClass.sorter_name - output_folder = cache_folder / sorter_name + output_folder = self.cache_folder / sorter_name sorter_params = self.SorterClass.default_params() From c4cd1c2eb73488f218477f4ab67f16265a6373cc Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:41:07 +0100 Subject: [PATCH 61/81] replace cache_folder by pytest fixture with new create_cache_folder for test_multisortingcomparison.py in comparison/test folder --- .../tests/test_multisortingcomparison.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/spikeinterface/comparison/tests/test_multisortingcomparison.py b/src/spikeinterface/comparison/tests/test_multisortingcomparison.py index f39b8cd890..9ea8ba3e80 100644 --- a/src/spikeinterface/comparison/tests/test_multisortingcomparison.py +++ b/src/spikeinterface/comparison/tests/test_multisortingcomparison.py @@ -1,6 +1,4 @@ import shutil -import pytest -from pathlib import Path import pytest import numpy as np @@ -9,18 +7,14 @@ from spikeinterface.extractors import NumpySorting from spikeinterface.comparison import compare_multiple_sorters, MultiSortingComparison -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "comparison" -else: - cache_folder = Path("cache_folder") / "comparison" - - -multicomparison_folder = cache_folder / "saved_multisorting_comparison" - -def setup_module(): +@pytest.fixture(scope="module") +def setup_module(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + multicomparison_folder = cache_folder / "saved_multisorting_comparison" if multicomparison_folder.is_dir(): shutil.rmtree(multicomparison_folder) + return multicomparison_folder def make_sorting(times1, labels1, times2, labels2, times3, labels3): @@ -34,7 +28,8 @@ def make_sorting(times1, labels1, times2, labels2, times3, labels3): return sorting1, sorting2, sorting3 -def test_compare_multiple_sorters(): +def test_compare_multiple_sorters(setup_module): + multicomparison_folder = setup_module # simple match sorting1, sorting2, sorting3 = make_sorting( [100, 200, 300, 400, 500, 600, 700, 800, 900], From 84f757f7b3ffff3c516d4f6f024dc9eef0be77d2 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:42:39 +0100 Subject: [PATCH 62/81] remove commented cache_folder for test_templatecomparison.py in comarison/tests folder --- .../comparison/tests/test_templatecomparison.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/spikeinterface/comparison/tests/test_templatecomparison.py b/src/spikeinterface/comparison/tests/test_templatecomparison.py index f4b3a14f0d..871bdeaed3 100644 --- a/src/spikeinterface/comparison/tests/test_templatecomparison.py +++ b/src/spikeinterface/comparison/tests/test_templatecomparison.py @@ -1,21 +1,11 @@ import shutil import pytest -from pathlib import Path import numpy as np from spikeinterface.core import create_sorting_analyzer, generate_ground_truth_recording from spikeinterface.comparison import compare_templates, compare_multiple_templates -# if hasattr(pytest, "global_test_folder"): -# cache_folder = pytest.global_test_folder / "comparison" -# else: -# cache_folder = Path("cache_folder") / "comparison" - - -# test_dir = cache_folder / "temp_comp_test" - - # def setup_module(): # if test_dir.is_dir(): # shutil.rmtree(test_dir) From e0247ad1632e0b91cb3d4685b8504320c23bc951 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:48:23 +0100 Subject: [PATCH 63/81] remove import of cache_folder from common_extension_tests, as it is inherited from AnalyzerExtensionCommonTestSuite now, for test_principal_component.py in postprocessing/tests/ folder --- .../postprocessing/tests/test_principal_component.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/postprocessing/tests/test_principal_component.py b/src/spikeinterface/postprocessing/tests/test_principal_component.py index d94d7ea586..f9b847ec22 100644 --- a/src/spikeinterface/postprocessing/tests/test_principal_component.py +++ b/src/spikeinterface/postprocessing/tests/test_principal_component.py @@ -5,7 +5,7 @@ import numpy as np from spikeinterface.postprocessing import ComputePrincipalComponents, compute_principal_components -from spikeinterface.postprocessing.tests.common_extension_tests import AnalyzerExtensionCommonTestSuite, cache_folder +from spikeinterface.postprocessing.tests.common_extension_tests import AnalyzerExtensionCommonTestSuite DEBUG = False @@ -100,12 +100,12 @@ def test_compute_for_all_spikes(self): sorting_analyzer.compute("principal_components", mode="by_channel_local", n_components=n_components) ext = sorting_analyzer.get_extension("principal_components") - pc_file1 = cache_folder / "all_pc1.npy" + pc_file1 = self.cache_folder / "all_pc1.npy" ext.run_for_all_spikes(pc_file1, chunk_size=10000, n_jobs=1) all_pc1 = np.load(pc_file1) assert all_pc1.shape[0] == num_spikes - pc_file2 = cache_folder / "all_pc2.npy" + pc_file2 = self.cache_folder / "all_pc2.npy" ext.run_for_all_spikes(pc_file2, chunk_size=10000, n_jobs=2) all_pc2 = np.load(pc_file2) From 06a4e476e51e7e16aeda2afd2cfb72828d55bd5d Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:50:09 +0100 Subject: [PATCH 64/81] remove useless global setting of cache_folder for test_de .py in preprocessing/tests/ folder --- .../preprocessing/tests/test_depth_order.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_depth_order.py b/src/spikeinterface/preprocessing/tests/test_depth_order.py index bc959b8ddb..b0dbc2a8da 100644 --- a/src/spikeinterface/preprocessing/tests/test_depth_order.py +++ b/src/spikeinterface/preprocessing/tests/test_depth_order.py @@ -1,20 +1,11 @@ import pytest -from pathlib import Path -from spikeinterface import set_global_tmp_folder from spikeinterface.core import NumpyRecording from spikeinterface.preprocessing import DepthOrderRecording, depth_order import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - def test_depth_order(): # gradient recording with 100 samples and 10 channels From 17ea159d77b09b07b3c2e99583e189fc3d6e79d4 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:51:18 +0100 Subject: [PATCH 65/81] remove useless global setting of cache_folder for test_filter.py in preprocessing/tests/ folder --- src/spikeinterface/preprocessing/tests/test_filter.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_filter.py b/src/spikeinterface/preprocessing/tests/test_filter.py index 95e5a097ff..7e9ff74b83 100644 --- a/src/spikeinterface/preprocessing/tests/test_filter.py +++ b/src/spikeinterface/preprocessing/tests/test_filter.py @@ -1,5 +1,4 @@ import pytest -from pathlib import Path import shutil import numpy as np @@ -10,13 +9,6 @@ from spikeinterface.preprocessing import filter, bandpass_filter, notch_filter from scipy.signal import iirfilter -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - def test_filter(): rec = generate_recording() From 294d331b7a7a8d46804872ce1208bac6d4ec805b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:52:13 +0100 Subject: [PATCH 66/81] remove useless global setting of cache_folder for test_normalize_scale.py in preprocessing/tests/ folder --- .../preprocessing/tests/test_normalize_scale.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_normalize_scale.py b/src/spikeinterface/preprocessing/tests/test_normalize_scale.py index 69e45425c1..576b570832 100644 --- a/src/spikeinterface/preprocessing/tests/test_normalize_scale.py +++ b/src/spikeinterface/preprocessing/tests/test_normalize_scale.py @@ -9,14 +9,6 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - - def test_normalize_by_quantile(): rec = generate_recording() From b97b4c95c59fd5768db0c8193c252c32c43e6ca8 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:52:48 +0100 Subject: [PATCH 67/81] remove useless global setting of cache_folder for test_rectify.py in preprocessing/tests/ folder --- src/spikeinterface/preprocessing/tests/test_rectify.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_rectify.py b/src/spikeinterface/preprocessing/tests/test_rectify.py index cca41ebf7d..b8bb31015e 100644 --- a/src/spikeinterface/preprocessing/tests/test_rectify.py +++ b/src/spikeinterface/preprocessing/tests/test_rectify.py @@ -9,14 +9,6 @@ import numpy as np -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - -set_global_tmp_folder(cache_folder) - - def test_rectify(): rec = generate_recording() From 5a00dae8de6ad797e6f51208baa8e16d9fe03f81 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:53:19 +0100 Subject: [PATCH 68/81] remove commented global setting of cache_folder for test_remove_artifacts.py in preprocessing/tests/ folder --- .../preprocessing/tests/test_remove_artifacts.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_remove_artifacts.py b/src/spikeinterface/preprocessing/tests/test_remove_artifacts.py index b8a6e83f67..3461bf9b1b 100644 --- a/src/spikeinterface/preprocessing/tests/test_remove_artifacts.py +++ b/src/spikeinterface/preprocessing/tests/test_remove_artifacts.py @@ -1,18 +1,10 @@ import pytest -from pathlib import Path + import numpy as np -from spikeinterface import set_global_tmp_folder from spikeinterface.core import generate_recording from spikeinterface.preprocessing import remove_artifacts -# if hasattr(pytest, "global_test_folder"): -# cache_folder = pytest.global_test_folder / "preprocessing" -# else: -# cache_folder = Path("cache_folder") / "preprocessing" - -# set_global_tmp_folder(cache_folder) - def test_remove_artifacts(): # one segment only From ab40479f4d37af7c3904838a0938f195de9fca27 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 10:54:14 +0100 Subject: [PATCH 69/81] remove useless cache_folder for test_resample.py in preprocessing/tests/ folder --- src/spikeinterface/preprocessing/tests/test_resample.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/spikeinterface/preprocessing/tests/test_resample.py b/src/spikeinterface/preprocessing/tests/test_resample.py index d17617487f..d8975b980c 100644 --- a/src/spikeinterface/preprocessing/tests/test_resample.py +++ b/src/spikeinterface/preprocessing/tests/test_resample.py @@ -1,7 +1,6 @@ import pytest -from pathlib import Path -from spikeinterface import NumpyRecording, set_global_tmp_folder +from spikeinterface import NumpyRecording from spikeinterface.core import generate_recording from spikeinterface.preprocessing import resample @@ -9,11 +8,6 @@ import numpy as np from scipy.fft import fft, fftfreq -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "preprocessing" -else: - cache_folder = Path("cache_folder") / "preprocessing" - DEBUG = False # DEBUG = True From 78b1290a5d8573a64e208b52d115eeed31eff668 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 11:19:34 +0100 Subject: [PATCH 70/81] replace depreciated output_folder by folder in runsorter, and replace cache_folder by pytest fixture for test_docker_containers.py in sorters/external/tests (fails possibly because of docker not working on my machine) --- .../external/tests/test_docker_containers.py | 62 +++++++++++-------- src/spikeinterface/sorters/runsorter.py | 14 ++--- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/spikeinterface/sorters/external/tests/test_docker_containers.py b/src/spikeinterface/sorters/external/tests/test_docker_containers.py index 9bf17549bf..e8a4a527f1 100644 --- a/src/spikeinterface/sorters/external/tests/test_docker_containers.py +++ b/src/spikeinterface/sorters/external/tests/test_docker_containers.py @@ -2,17 +2,18 @@ import shutil import pytest -from pathlib import Path from spikeinterface import generate_ground_truth_recording from spikeinterface.core.core_tools import is_editable_mode import spikeinterface.extractors as se import spikeinterface.sorters as ss -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" + +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + + return cache_folder ON_GITHUB = os.getenv("CI") @@ -40,66 +41,77 @@ def run_kwargs(): return generate_run_kwargs() -def test_spykingcircus(run_kwargs): - sorting = ss.run_sorter("spykingcircus", output_folder=cache_folder / "spykingcircus", **run_kwargs) +def test_spykingcircus(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + print(cache_folder) + sorting = ss.run_sorter("spykingcircus", folder=cache_folder / "spykingcircus", **run_kwargs) print("resulting sorting") print(sorting) -def test_mountainsort4(run_kwargs): - sorting = ss.run_sorter("mountainsort4", output_folder=cache_folder / "mountainsort4", **run_kwargs) +def test_mountainsort4(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter("mountainsort4", folder=cache_folder / "mountainsort4", **run_kwargs) print("resulting sorting") print(sorting) -def test_mountainsort5(run_kwargs): - sorting = ss.run_sorter("mountainsort5", output_folder=cache_folder / "mountainsort5", **run_kwargs) +def test_mountainsort5(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter("mountainsort5", folder=cache_folder / "mountainsort5", **run_kwargs) print("resulting sorting") print(sorting) -def test_tridesclous(run_kwargs): - sorting = ss.run_sorter("tridesclous", output_folder=cache_folder / "tridesclous", **run_kwargs) +def test_tridesclous(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter("tridesclous", folder=cache_folder / "tridesclous", **run_kwargs) print("resulting sorting") print(sorting) -def test_ironclust(run_kwargs): - sorting = ss.run_sorter("ironclust", output_folder=cache_folder / "ironclust", fGpu=False, **run_kwargs) +def test_ironclust(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter("ironclust", folder=cache_folder / "ironclust", fGpu=False, **run_kwargs) print("resulting sorting") print(sorting) -def test_waveclus(run_kwargs): - sorting = ss.run_sorter(sorter_name="waveclus", output_folder=cache_folder / "waveclus", **run_kwargs) +def test_waveclus(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter(sorter_name="waveclus", folder=cache_folder / "waveclus", **run_kwargs) print("resulting sorting") print(sorting) -def test_hdsort(run_kwargs): - sorting = ss.run_sorter(sorter_name="hdsort", output_folder=cache_folder / "hdsort", **run_kwargs) +def test_hdsort(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter(sorter_name="hdsort", folder=cache_folder / "hdsort", **run_kwargs) print("resulting sorting") print(sorting) -def test_kilosort1(run_kwargs): - sorting = ss.run_sorter(sorter_name="kilosort", output_folder=cache_folder / "kilosort", useGPU=False, **run_kwargs) +def test_kilosort1(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter(sorter_name="kilosort", folder=cache_folder / "kilosort", useGPU=False, **run_kwargs) print("resulting sorting") print(sorting) -def test_combinato(run_kwargs): +def test_combinato(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder rec = run_kwargs["recording"] channels = rec.get_channel_ids()[0:1] rec_one_channel = rec.channel_slice(channels) run_kwargs["recording"] = rec_one_channel - sorting = ss.run_sorter(sorter_name="combinato", output_folder=cache_folder / "combinato", **run_kwargs) + sorting = ss.run_sorter(sorter_name="combinato", folder=cache_folder / "combinato", **run_kwargs) print(sorting) @pytest.mark.skip("Klusta is not supported anymore for Python>=3.8") -def test_klusta(run_kwargs): - sorting = ss.run_sorter("klusta", output_folder=cache_folder / "klusta", **run_kwargs) +def test_klusta(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder + sorting = ss.run_sorter("klusta", folder=cache_folder / "klusta", **run_kwargs) print(sorting) diff --git a/src/spikeinterface/sorters/runsorter.py b/src/spikeinterface/sorters/runsorter.py index b50ddb0a79..d75735c090 100644 --- a/src/spikeinterface/sorters/runsorter.py +++ b/src/spikeinterface/sorters/runsorter.py @@ -344,7 +344,7 @@ def run_sorter_container( # common code for docker and singularity if folder is None: - output_folder = sorter_name + "_output" + folder = sorter_name + "_output" if container_image is None: if sorter_name in SORTER_DOCKER_MAP: @@ -380,11 +380,11 @@ def run_sorter_container( json.dumps(check_json(sorter_params), indent=4), encoding="utf8" ) - in_container_sorting_folder = output_folder / "in_container_sorting" + in_container_sorting_folder = folder / "in_container_sorting" # if in Windows, skip C: parent_folder_unix = path_to_unix(parent_folder) - output_folder_unix = path_to_unix(output_folder) + folder_unix = path_to_unix(folder) recording_input_folders_unix = [path_to_unix(rf) for rf in recording_input_folders] in_container_sorting_folder_unix = path_to_unix(in_container_sorting_folder) @@ -410,9 +410,9 @@ def run_sorter_container( sorter_params = json.load(f) # run in container - output_folder = '{output_folder_unix}' + folder = '{folder_unix}' sorting = run_sorter_local( - '{sorter_name}', recording, output_folder=output_folder, + '{sorter_name}', recording, folder=folder, remove_existing_folder={remove_existing_folder}, delete_output_folder=False, verbose={verbose}, raise_error={raise_error}, with_output=True, **sorter_params ) @@ -584,9 +584,9 @@ def run_sorter_container( if platform.system() != "Windows": uid = os.getuid() # this do not work with singularity: - # cmd = f'chown {uid}:{uid} -R "{output_folder}"' + # cmd = f'chown {uid}:{uid} -R "{folder}"' # this approach is better - cmd = ["chown", f"{uid}:{uid}", "-R", f"{output_folder}"] + cmd = ["chown", f"{uid}:{uid}", "-R", f"{folder}"] res_output = container_client.run_command(cmd) else: # not needed for Windows From 52beb89aaed4646c0feed9a1085bd98f95c39a35 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 11:49:27 +0100 Subject: [PATCH 71/81] replace import of cache_folder from SorterCommonTestSuite as it is now inherited as self.cache_folder in Kilosort4SorterCommonTestSuite for test_kilosort4.py in sorters/external/tests folder --- .../sorters/external/tests/test_kilosort4.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/spikeinterface/sorters/external/tests/test_kilosort4.py b/src/spikeinterface/sorters/external/tests/test_kilosort4.py index 62a1476407..dbaf3ffc5e 100644 --- a/src/spikeinterface/sorters/external/tests/test_kilosort4.py +++ b/src/spikeinterface/sorters/external/tests/test_kilosort4.py @@ -6,11 +6,6 @@ from spikeinterface.sorters import Kilosort4Sorter, run_sorter from spikeinterface.sorters.tests.common_tests import SorterCommonTestSuite -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" - # This run several tests @pytest.mark.skipif(not Kilosort4Sorter.is_installed(), reason="kilosort4 not installed") @@ -19,11 +14,11 @@ class Kilosort4SorterCommonTestSuite(SorterCommonTestSuite, unittest.TestCase): # 4 channels is to few for KS4 def setUp(self): - if (cache_folder / "rec").is_dir(): - recording = load_extractor(cache_folder / "rec") + if (self.cache_folder / "rec").is_dir(): + recording = load_extractor(self.cache_folder / "rec") else: recording, _ = generate_ground_truth_recording(num_channels=32, durations=[60], seed=0) - recording = recording.save(folder=cache_folder / "rec", verbose=False, format="binary") + recording = recording.save(folder=self.cache_folder / "rec", verbose=False, format="binary") self.recording = recording print(self.recording) @@ -32,7 +27,7 @@ def test_with_run_skip_correction(self): sorter_name = self.SorterClass.sorter_name - output_folder = cache_folder / sorter_name + output_folder = self.cache_folder / sorter_name sorter_params = self.SorterClass.default_params() sorter_params["do_correction"] = False @@ -66,7 +61,7 @@ def test_with_run_skip_preprocessing(self): sorter_name = self.SorterClass.sorter_name - output_folder = cache_folder / sorter_name + output_folder = self.cache_folder / sorter_name sorter_params = self.SorterClass.default_params() sorter_params["skip_kilosort_preprocessing"] = True @@ -101,7 +96,7 @@ def test_with_run_skip_preprocessing_and_correction(self): sorter_name = self.SorterClass.sorter_name - output_folder = cache_folder / sorter_name + output_folder = self.cache_folder / sorter_name sorter_params = self.SorterClass.default_params() sorter_params["skip_kilosort_preprocessing"] = True From db53a368622c93859e816fa103be5c0df604a957 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 11:52:35 +0100 Subject: [PATCH 72/81] replace depreciated output_folder by folder in runsorter calls, and replace cache_folder by pytest fixture for test_singularity_containers.py in sorters/external/tests --- .../tests/test_singularity_containers.py | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/spikeinterface/sorters/external/tests/test_singularity_containers.py b/src/spikeinterface/sorters/external/tests/test_singularity_containers.py index 3929c6407b..2db4f8475a 100644 --- a/src/spikeinterface/sorters/external/tests/test_singularity_containers.py +++ b/src/spikeinterface/sorters/external/tests/test_singularity_containers.py @@ -1,17 +1,18 @@ import os import pytest -from pathlib import Path from spikeinterface import generate_ground_truth_recording from spikeinterface.core.core_tools import is_editable_mode import spikeinterface.extractors as se import spikeinterface.sorters as ss -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" + +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + + return cache_folder os.environ["SINGULARITY_DISABLE_CACHE"] = "true" @@ -46,76 +47,86 @@ def run_kwargs(): return generate_run_kwargs() -def test_spykingcircus(run_kwargs): +def test_spykingcircus(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter("spykingcircus", output_folder=cache_folder / "spykingcircus", **run_kwargs) + sorting = ss.run_sorter("spykingcircus", folder=cache_folder / "spykingcircus", **run_kwargs) print("resulting sorting") print(sorting) -def test_mountainsort4(run_kwargs): +def test_mountainsort4(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter("mountainsort4", output_folder=cache_folder / "mountainsort4", **run_kwargs) + sorting = ss.run_sorter("mountainsort4", folder=cache_folder / "mountainsort4", **run_kwargs) print("resulting sorting") print(sorting) -def test_mountainsort5(run_kwargs): +def test_mountainsort5(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter("mountainsort5", output_folder=cache_folder / "mountainsort5", **run_kwargs) + sorting = ss.run_sorter("mountainsort5", folder=cache_folder / "mountainsort5", **run_kwargs) print("resulting sorting") print(sorting) -def test_tridesclous(run_kwargs): +def test_tridesclous(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter("tridesclous", output_folder=cache_folder / "tridesclous", **run_kwargs) + sorting = ss.run_sorter("tridesclous", folder=cache_folder / "tridesclous", **run_kwargs) print("resulting sorting") print(sorting) -def test_ironclust(run_kwargs): +def test_ironclust(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter("ironclust", output_folder=cache_folder / "ironclust", fGpu=False, **run_kwargs) + sorting = ss.run_sorter("ironclust", folder=cache_folder / "ironclust", fGpu=False, **run_kwargs) print("resulting sorting") print(sorting) -def test_waveclus(run_kwargs): +def test_waveclus(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="waveclus", output_folder=cache_folder / "waveclus", **run_kwargs) + sorting = ss.run_sorter(sorter_name="waveclus", folder=cache_folder / "waveclus", **run_kwargs) print("resulting sorting") print(sorting) -def test_hdsort(run_kwargs): +def test_hdsort(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="hdsort", output_folder=cache_folder / "hdsort", **run_kwargs) + sorting = ss.run_sorter(sorter_name="hdsort", folder=cache_folder / "hdsort", **run_kwargs) print("resulting sorting") print(sorting) -def test_kilosort1(run_kwargs): +def test_kilosort1(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="kilosort", output_folder=cache_folder / "kilosort", useGPU=False, **run_kwargs) + sorting = ss.run_sorter(sorter_name="kilosort", folder=cache_folder / "kilosort", useGPU=False, **run_kwargs) print("resulting sorting") print(sorting) -def test_combinato(run_kwargs): +def test_combinato(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() rec = run_kwargs["recording"] channels = rec.get_channel_ids()[0:1] rec_one_channel = rec.channel_slice(channels) run_kwargs["recording"] = rec_one_channel - sorting = ss.run_sorter(sorter_name="combinato", output_folder=cache_folder / "combinato", **run_kwargs) + sorting = ss.run_sorter(sorter_name="combinato", folder=cache_folder / "combinato", **run_kwargs) print(sorting) @pytest.mark.skip("Klusta is not supported anymore for Python>=3.8") -def test_klusta(run_kwargs): +def test_klusta(run_kwargs, create_cache_folder): + cache_folder = create_cache_folder clean_singularity_cache() - sorting = ss.run_sorter("klusta", output_folder=cache_folder / "klusta", **run_kwargs) + sorting = ss.run_sorter("klusta", folder=cache_folder / "klusta", **run_kwargs) print(sorting) From 7dca861b750004f39d8d22b555895f08cd29b90b Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 11:53:32 +0100 Subject: [PATCH 73/81] replace depreciated output_folder by folder in runsorter calls for test_singularity_containers_gpu.py in sorters/external/tests --- .../tests/test_singularity_containers_gpu.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/sorters/external/tests/test_singularity_containers_gpu.py b/src/spikeinterface/sorters/external/tests/test_singularity_containers_gpu.py index a393fde105..ce0cdd6fda 100644 --- a/src/spikeinterface/sorters/external/tests/test_singularity_containers_gpu.py +++ b/src/spikeinterface/sorters/external/tests/test_singularity_containers_gpu.py @@ -42,38 +42,38 @@ def run_kwargs(): def test_kilosort2(run_kwargs): clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="kilosort2", output_folder="kilosort2", **run_kwargs) + sorting = ss.run_sorter(sorter_name="kilosort2", folder="kilosort2", **run_kwargs) print(sorting) def test_kilosort2_5(run_kwargs): clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="kilosort2_5", output_folder="kilosort2_5", **run_kwargs) + sorting = ss.run_sorter(sorter_name="kilosort2_5", folder="kilosort2_5", **run_kwargs) print(sorting) def test_kilosort3(run_kwargs): clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="kilosort3", output_folder="kilosort3", **run_kwargs) + sorting = ss.run_sorter(sorter_name="kilosort3", folder="kilosort3", **run_kwargs) print(sorting) def test_kilosort4(run_kwargs): clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="kilosort4", output_folder="kilosort4", **run_kwargs) + sorting = ss.run_sorter(sorter_name="kilosort4", folder="kilosort4", **run_kwargs) print(sorting) def test_pykilosort(run_kwargs): clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="pykilosort", output_folder="pykilosort", **run_kwargs) + sorting = ss.run_sorter(sorter_name="pykilosort", folder="pykilosort", **run_kwargs) print(sorting) @pytest.mark.skip("YASS is not supported anymore for Python>=3.8") def test_yass(run_kwargs): clean_singularity_cache() - sorting = ss.run_sorter(sorter_name="yass", output_folder="yass", **run_kwargs) + sorting = ss.run_sorter(sorter_name="yass", folder="yass", **run_kwargs) print(sorting) From aaca9965271036095db498c53dedd7541ff8ce7c Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Fri, 31 May 2024 14:57:02 +0100 Subject: [PATCH 74/81] TO DO those three files are the only cache_folder remaining in tests, need to be replaced by pytest fixtures however there are not trivial --- .../deepinterpolation/tests/test_deepinterpolation.py | 2 +- src/spikeinterface/sorters/tests/test_launcher.py | 2 +- src/spikeinterface/sorters/tests/test_runsorter.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index 43b35dfef9..56252746a9 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -20,7 +20,7 @@ HAVE_DEEPINTERPOLATION = False -if hasattr(pytest, "global_test_folder"): +if hasattr(pytest, "global_test_folder"): # TODO try to replace with pytest fixture (tricky one) cache_folder = pytest.global_test_folder / "deepinterpolation" else: cache_folder = Path("cache_folder") / "deepinterpolation" diff --git a/src/spikeinterface/sorters/tests/test_launcher.py b/src/spikeinterface/sorters/tests/test_launcher.py index 4fca09e2a1..57ca357702 100644 --- a/src/spikeinterface/sorters/tests/test_launcher.py +++ b/src/spikeinterface/sorters/tests/test_launcher.py @@ -12,7 +12,7 @@ from spikeinterface.sorters import run_sorter_jobs, run_sorter_by_property -if hasattr(pytest, "global_test_folder"): +if hasattr(pytest, "global_test_folder"): # TODO try to replace with pytest fixture (tricky one) cache_folder = pytest.global_test_folder / "sorters" else: cache_folder = Path("cache_folder") / "sorters" diff --git a/src/spikeinterface/sorters/tests/test_runsorter.py b/src/spikeinterface/sorters/tests/test_runsorter.py index df7389e844..d41bffa075 100644 --- a/src/spikeinterface/sorters/tests/test_runsorter.py +++ b/src/spikeinterface/sorters/tests/test_runsorter.py @@ -11,7 +11,7 @@ ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) -if hasattr(pytest, "global_test_folder"): +if hasattr(pytest, "global_test_folder"): # TODO try to replace with pytest fixture (tricky one) cache_folder = pytest.global_test_folder / "sorters" else: cache_folder = Path("cache_folder") / "sorters" From bb3f4fce397ebc163095f9241d5aabbb0ab156f0 Mon Sep 17 00:00:00 2001 From: paulrignanese Date: Mon, 3 Jun 2024 17:18:17 +0100 Subject: [PATCH 75/81] replace cache_folder by pytest fuxture with new create_cachce_folder for test_deepinterpolation.py in deepinterpolation/tests folder (I reverted those changes because we thought that it was producing a bug but it was unrelated, it is back now - Still 2 pytest fixtures TODO : test_launcher.py and test_runsorter.py) Last commit for the Hackathon 2024 --- .../tests/test_deepinterpolation.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index 56252746a9..5a8473e299 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -20,10 +20,10 @@ HAVE_DEEPINTERPOLATION = False -if hasattr(pytest, "global_test_folder"): # TODO try to replace with pytest fixture (tricky one) - cache_folder = pytest.global_test_folder / "deepinterpolation" -else: - cache_folder = Path("cache_folder") / "deepinterpolation" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder def recording_and_shape(): @@ -70,6 +70,7 @@ def test_deepinterpolation_generator_borders(recording_and_shape_fixture): def test_deepinterpolation_training(recording_and_shape_fixture): recording, desired_shape = recording_and_shape_fixture + cache_folder = create_cache_folder model_folder = Path(cache_folder) / "training" # train model_path = train_deepinterpolation( @@ -95,6 +96,7 @@ def test_deepinterpolation_training(recording_and_shape_fixture): @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): recording, desired_shape = recording_and_shape_fixture + cache_folder = create_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" model_folder = Path(tmp_path) / "transfer" @@ -124,6 +126,7 @@ def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): def test_deepinterpolation_inference(recording_and_shape_fixture): recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 + cache_folder = create_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" recording_di = deepinterpolate( @@ -150,6 +153,7 @@ def test_deepinterpolation_inference(recording_and_shape_fixture): def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture): recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 + cache_folder = create_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" recording_di = deepinterpolate( From 3d4f7f2d5a33b40677bf80b8258be8ce995035f3 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Wed, 5 Jun 2024 13:04:19 +0200 Subject: [PATCH 76/81] Fix deepeinteprolation tests --- .../deepinterpolation/tests/test_deepinterpolation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index 7a1a750838..b7b880bb6b 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -73,7 +73,7 @@ def test_deepinterpolation_generator_borders(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency() -def test_deepinterpolation_training(recording_and_shape_fixture): +def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_folder): recording, desired_shape = recording_and_shape_fixture cache_folder = create_cache_folder @@ -101,7 +101,7 @@ def test_deepinterpolation_training(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): +def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_cache_folder): recording, desired_shape = recording_and_shape_fixture cache_folder = create_cache_folder @@ -130,7 +130,7 @@ def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference(recording_and_shape_fixture): +def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_folder): recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 cache_folder = create_cache_folder @@ -157,7 +157,7 @@ def test_deepinterpolation_inference(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture): +def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_cache_folder): recording, desired_shape = recording_and_shape_fixture pre_frame = post_frame = 20 cache_folder = create_cache_folder From b52e077c8e896ad54b644fe1d79bd595e1933556 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Wed, 5 Jun 2024 13:24:16 +0200 Subject: [PATCH 77/81] Fix remaining TODOs --- src/spikeinterface/sorters/basesorter.py | 2 +- src/spikeinterface/sorters/runsorter.py | 132 +++++++++--------- .../sorters/tests/test_launcher.py | 89 ++++++------ .../sorters/tests/test_runsorter.py | 65 ++++----- 4 files changed, 137 insertions(+), 151 deletions(-) diff --git a/src/spikeinterface/sorters/basesorter.py b/src/spikeinterface/sorters/basesorter.py index cdd5bc1abb..2f87065d9f 100644 --- a/src/spikeinterface/sorters/basesorter.py +++ b/src/spikeinterface/sorters/basesorter.py @@ -102,7 +102,7 @@ def initialize_folder(cls, recording, output_folder, verbose, remove_existing_fo # installed ? if not cls.is_installed(): raise Exception( - f"The sorter {cls.sorter_name} is not installed." f"Please install it with: \n{cls.installation_mesg} " + f"The sorter {cls.sorter_name} is not installed. Please install it with:\n{cls.installation_mesg}" ) if not isinstance(recording, BaseRecordingSnippets): diff --git a/src/spikeinterface/sorters/runsorter.py b/src/spikeinterface/sorters/runsorter.py index b50ddb0a79..baec6aaac3 100644 --- a/src/spikeinterface/sorters/runsorter.py +++ b/src/spikeinterface/sorters/runsorter.py @@ -60,53 +60,53 @@ _common_param_doc = """ Parameters ---------- - sorter_name: str + sorter_name : str The sorter name - recording: RecordingExtractor + recording : RecordingExtractor The recording extractor to be spike sorted - folder: str or Path + folder : str or Path Path to output folder - remove_existing_folder: bool + remove_existing_folder : bool If True and folder exists then delete. - delete_output_folder: bool, default: False + delete_output_folder : bool, default: False If True, output folder is deleted - verbose: bool, default: False + verbose : bool, default: False If True, output is verbose - raise_error: bool, default: True + raise_error : bool, default: True If True, an error is raised if spike sorting fails If False, the process continues and the error is logged in the log file. - docker_image: bool or str, default: False + docker_image : bool or str, default: False If True, pull the default docker container for the sorter and run the sorter in that container using docker. Use a str to specify a non-default container. If that container is not local it will be pulled from docker hub. If False, the sorter is run locally - singularity_image: bool or str, default: False + singularity_image : bool or str, default: False If True, pull the default docker container for the sorter and run the sorter in that container using singularity. Use a str to specify a non-default container. If that container is not local it will be pulled from Docker Hub. If False, the sorter is run locally - with_output: bool, default: True + with_output : bool, default: True If True, the output Sorting is returned as a Sorting - delete_container_files: bool, default: True + delete_container_files : bool, default: True If True, the container temporary files are deleted after the sorting is done - extra_requirements: list, default: None + extra_requirements : list, default: None List of extra requirements to install in the container - installation_mode: "auto" | "pypi" | "github" | "folder" | "dev" | "no-install", default: "auto" + installation_mode : "auto" | "pypi" | "github" | "folder" | "dev" | "no-install", default: "auto" How spikeinterface is installed in the container: - * "auto": if host installation is a pip release then use "github" with tag + * "auto" : if host installation is a pip release then use "github" with tag if host installation is DEV_MODE=True then use "dev" - * "pypi": use pypi with pip install spikeinterface - * "github": use github with `pip install git+https` - * "folder": mount a folder in container and install from this one. + * "pypi" : use pypi with pip install spikeinterface + * "github" : use github with `pip install git+https` + * "folder" : mount a folder in container and install from this one. So the version in the container is a different spikeinterface version from host, useful for cross checks - * "dev": same as "folder", but the folder is the spikeinterface.__file__ to ensure same version as host - * "no-install": do not install spikeinterface in the container because it is already installed - spikeinterface_version: str, default: None + * "dev" : same as "folder", but the folder is the spikeinterface.__file__ to ensure same version as host + * "no-install" : do not install spikeinterface in the container because it is already installed + spikeinterface_version : str, default: None The spikeinterface version to install in the container. If None, the current version is used - spikeinterface_folder_source: Path or None, default: None + spikeinterface_folder_source : Path or None, default: None In case of installation_mode="folder", the spikeinterface folder source to use to install in the container - output_folder: None, default: None + output_folder : None, default: None Do not use. Deprecated output function to be removed in 0.103. - **sorter_params: keyword args + **sorter_params : keyword args Spike sorter specific arguments (they can be retrieved with `get_default_sorter_params(sorter_name_or_class)`) Returns @@ -141,7 +141,7 @@ def run_sorter( >>> sorting = run_sorter("tridesclous", recording) """ - if output_folder is not None: + if output_folder is not None and folder is None: deprecation_msg = ( "`output_folder` is deprecated and will be removed in version 0.103.0 Please use folder instead" ) @@ -205,31 +205,31 @@ def run_sorter_local( Parameters ---------- - sorter_name: str + sorter_name : str The sorter name - recording: RecordingExtractor + recording : RecordingExtractor The recording extractor to be spike sorted - folder: str or Path + folder : str or Path Path to output folder. If None, a folder is created in the current directory - remove_existing_folder: bool, default: True + remove_existing_folder : bool, default: True If True and output_folder exists yet then delete - delete_output_folder: bool, default: False + delete_output_folder : bool, default: False If True, output folder is deleted - verbose: bool, default: False + verbose : bool, default: False If True, output is verbose - raise_error: bool, default: True + raise_error : bool, default: True If True, an error is raised if spike sorting fails. If False, the process continues and the error is logged in the log file - with_output: bool, default: True + with_output : bool, default: True If True, the output Sorting is returned as a Sorting - output_folder: None, default: None + output_folder : None, default: None Do not use. Deprecated output function to be removed in 0.103. - **sorter_params: keyword args + **sorter_params : keyword args """ if isinstance(recording, list): raise Exception("If you want to run several sorters/recordings use run_sorter_jobs(...)") - if output_folder is not None: + if output_folder is not None and folder is None: deprecation_msg = ( "`output_folder` is deprecated and will be removed in version 0.103.0 Please use folder instead" ) @@ -286,52 +286,52 @@ def run_sorter_container( Parameters ---------- - sorter_name: str + sorter_name : str The sorter name - recording: BaseRecording + recording : BaseRecording The recording extractor to be spike sorted - mode: str - The container mode: "docker" or "singularity" - container_image: str, default: None + mode : str + The container mode : "docker" or "singularity" + container_image : str, default: None The container image name and tag. If None, the default container image is used - output_folder: str, default: None + output_folder : str, default: None Path to output folder - remove_existing_folder: bool, default: True + remove_existing_folder : bool, default: True If True and output_folder exists yet then delete - delete_output_folder: bool, default: False + delete_output_folder : bool, default: False If True, output folder is deleted - verbose: bool, default: False + verbose : bool, default: False If True, output is verbose - raise_error: bool, default: True + raise_error : bool, default: True If True, an error is raised if spike sorting fails - with_output: bool, default: True + with_output : bool, default: True If True, the output Sorting is returned as a Sorting - delete_container_files: bool, default: True + delete_container_files : bool, default: True If True, the container temporary files are deleted after the sorting is done - extra_requirements: list, default: None + extra_requirements : list, default: None List of extra requirements to install in the container - installation_mode: "auto" | "pypi" | "github" | "folder" | "dev" | "no-install", default: "auto" + installation_mode : "auto" | "pypi" | "github" | "folder" | "dev" | "no-install", default: "auto" How spikeinterface is installed in the container: - * "auto": if host installation is a pip release then use "github" with tag + * "auto" : if host installation is a pip release then use "github" with tag if host installation is DEV_MODE=True then use "dev" - * "pypi": use pypi with pip install spikeinterface - * "github": use github with `pip install git+https` - * "folder": mount a folder in container and install from this one. + * "pypi" : use pypi with pip install spikeinterface + * "github" : use github with `pip install git+https` + * "folder" : mount a folder in container and install from this one. So the version in the container is a different spikeinterface version from host, useful for cross checks - * "dev": same as "folder", but the folder is the spikeinterface.__file__ to ensure same version as host - * "no-install": do not install spikeinterface in the container because it is already installed - spikeinterface_version: str, default: None + * "dev" : same as "folder", but the folder is the spikeinterface.__file__ to ensure same version as host + * "no-install" : do not install spikeinterface in the container because it is already installed + spikeinterface_version : str, default: None The spikeinterface version to install in the container. If None, the current version is used - spikeinterface_folder_source: Path or None, default: None + spikeinterface_folder_source : Path or None, default: None In case of installation_mode="folder", the spikeinterface folder source to use to install in the container - **sorter_params: keyword args for the sorter + **sorter_params : keyword args for the sorter """ assert installation_mode in ("auto", "pypi", "github", "folder", "dev", "no-install") - if output_folder is not None: + if output_folder is not None and folder is None: deprecation_msg = ( "`output_folder` is deprecated and will be removed in version 0.103.0 Please use folder instead" ) @@ -344,7 +344,7 @@ def run_sorter_container( # common code for docker and singularity if folder is None: - output_folder = sorter_name + "_output" + folder = sorter_name + "_output" if container_image is None: if sorter_name in SORTER_DOCKER_MAP: @@ -380,11 +380,11 @@ def run_sorter_container( json.dumps(check_json(sorter_params), indent=4), encoding="utf8" ) - in_container_sorting_folder = output_folder / "in_container_sorting" + in_container_sorting_folder = folder / "in_container_sorting" # if in Windows, skip C: parent_folder_unix = path_to_unix(parent_folder) - output_folder_unix = path_to_unix(output_folder) + output_folder_unix = path_to_unix(folder) recording_input_folders_unix = [path_to_unix(rf) for rf in recording_input_folders] in_container_sorting_folder_unix = path_to_unix(in_container_sorting_folder) @@ -586,7 +586,7 @@ def run_sorter_container( # this do not work with singularity: # cmd = f'chown {uid}:{uid} -R "{output_folder}"' # this approach is better - cmd = ["chown", f"{uid}:{uid}", "-R", f"{output_folder}"] + cmd = ["chown", f"{uid}:{uid}", "-R", f"{folder}"] res_output = container_client.run_command(cmd) else: # not needed for Windows @@ -646,11 +646,11 @@ def read_sorter_folder(folder, register_recording=True, sorting_info=True, raise Parameters ---------- - folder: Pth or str + folder : Pth or str The sorter folder - register_recording: bool, default: True + register_recording : bool, default: True Attach recording (when json or pickle) to the sorting - sorting_info: bool, default: True + sorting_info : bool, default: True Attach sorting info to the sorting. """ folder = Path(folder) diff --git a/src/spikeinterface/sorters/tests/test_launcher.py b/src/spikeinterface/sorters/tests/test_launcher.py index 57ca357702..69e24488b8 100644 --- a/src/spikeinterface/sorters/tests/test_launcher.py +++ b/src/spikeinterface/sorters/tests/test_launcher.py @@ -1,4 +1,3 @@ -import os import sys import shutil import time @@ -6,49 +5,43 @@ import pytest from pathlib import Path -from spikeinterface.core import load_extractor - from spikeinterface import generate_ground_truth_recording from spikeinterface.sorters import run_sorter_jobs, run_sorter_by_property -if hasattr(pytest, "global_test_folder"): # TODO try to replace with pytest fixture (tricky one) - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" +# no need to have many +NUM_RECORDINGS = 2 +SORTERS = ["tridesclous2"] -base_output = cache_folder / "sorter_output" -# no need to have many -num_recordings = 2 -sorters = ["tridesclous2"] +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def setup_module(): - base_seed = 42 - for i in range(num_recordings): - rec, _ = generate_ground_truth_recording(num_channels=8, durations=[10.0], seed=base_seed + i) - rec_folder = cache_folder / f"toy_rec_{i}" - if rec_folder.is_dir(): - shutil.rmtree(rec_folder) +def create_recordings(NUM_RECORDINGS=2, base_seed=42): + recordings = [] + for i in range(NUM_RECORDINGS): + recording, _ = generate_ground_truth_recording(num_channels=8, durations=[10.0], seed=base_seed + i) if i % 2 == 0: - rec.set_channel_groups(["0"] * 4 + ["1"] * 4) + recording.set_channel_groups(["0"] * 4 + ["1"] * 4) else: - rec.set_channel_groups([0] * 4 + [1] * 4) - - rec.save(folder=rec_folder) + recording.set_channel_groups([0] * 4 + [1] * 4) + recordings.append(recording) + return recordings -def get_job_list(): +def get_job_list(base_folder): jobs = [] - for i in range(num_recordings): - for sorter_name in sorters: - recording = load_extractor(cache_folder / f"toy_rec_{i}") + recordings = create_recordings(NUM_RECORDINGS) + for i, recording in enumerate(recordings): + for sorter_name in SORTERS: kwargs = dict( sorter_name=sorter_name, recording=recording, - folder=base_output / f"{sorter_name}_rec{i}", + folder=base_folder / f"{sorter_name}_rec{i}", verbose=True, raise_error=False, ) @@ -58,30 +51,29 @@ def get_job_list(): @pytest.fixture(scope="module") -def job_list(): - return get_job_list() +def job_list(create_cache_folder): + cache_folder = create_cache_folder + folder = cache_folder / "sorting_output" + return get_job_list(folder) def test_run_sorter_jobs_loop(job_list): - if base_output.is_dir(): - shutil.rmtree(base_output) sortings = run_sorter_jobs(job_list, engine="loop", return_output=True) print(sortings) @pytest.mark.skipif(True, reason="tridesclous is already multiprocessing, joblib cannot run it in parralel") def test_run_sorter_jobs_joblib(job_list): - if base_output.is_dir(): - shutil.rmtree(base_output) sortings = run_sorter_jobs( job_list, engine="joblib", engine_kwargs=dict(n_jobs=2, backend="loky"), return_output=True ) print(sortings) -def test_run_sorter_jobs_processpoolexecutor(job_list): - if base_output.is_dir(): - shutil.rmtree(base_output) +def test_run_sorter_jobs_processpoolexecutor(job_list, create_cache_folder): + cache_folder = create_cache_folder + if (cache_folder / "sorting_output").is_dir(): + shutil.rmtree(cache_folder / "sorting_output") sortings = run_sorter_jobs( job_list, engine="processpoolexecutor", engine_kwargs=dict(max_workers=2), return_output=True ) @@ -90,8 +82,6 @@ def test_run_sorter_jobs_processpoolexecutor(job_list): @pytest.mark.skipif(True, reason="This is tested locally") def test_run_sorter_jobs_dask(job_list): - if base_output.is_dir(): - shutil.rmtree(base_output) # create a dask Client for a slurm queue from dask.distributed import Client @@ -122,11 +112,10 @@ def test_run_sorter_jobs_dask(job_list): @pytest.mark.skip("Slurm launcher need a machine with slurm") -def test_run_sorter_jobs_slurm(job_list): - if base_output.is_dir(): - shutil.rmtree(base_output) +def test_run_sorter_jobs_slurm(job_list, create_cache_folder): + cache_folder = create_cache_folder - working_folder = cache_folder / "test_run_sorters_slurm" + working_folder = cache_folder / "test_run_SORTERS_slurm" if working_folder.is_dir(): shutil.rmtree(working_folder) @@ -143,7 +132,8 @@ def test_run_sorter_jobs_slurm(job_list): ) -def test_run_sorter_by_property(): +def test_run_sorter_by_property(create_cache_folder): + cache_folder = create_cache_folder working_folder1 = cache_folder / "test_run_sorter_by_property_1" if working_folder1.is_dir(): shutil.rmtree(working_folder1) @@ -152,7 +142,9 @@ def test_run_sorter_by_property(): if working_folder2.is_dir(): shutil.rmtree(working_folder2) - rec0 = load_extractor(cache_folder / "toy_rec_0") + recordings = create_recordings(NUM_RECORDINGS) + + rec0 = recordings[0] rec0_by = rec0.split_by("group") group_names0 = list(rec0_by.keys()) @@ -161,7 +153,7 @@ def test_run_sorter_by_property(): assert "group" in sorting0.get_property_keys() assert all([g in group_names0 for g in sorting0.get_property("group")]) - rec1 = load_extractor(cache_folder / "toy_rec_1") + rec1 = recordings[1] rec1_by = rec1.split_by("group") group_names1 = list(rec1_by.keys()) @@ -172,8 +164,9 @@ def test_run_sorter_by_property(): if __name__ == "__main__": - setup_module() - job_list = get_job_list() + # setup_module() + tmp_folder = Path("tmp") + job_list = get_job_list(tmp_folder) # test_run_sorter_jobs_loop(job_list) # test_run_sorter_jobs_joblib(job_list) @@ -182,4 +175,4 @@ def test_run_sorter_by_property(): # test_run_sorter_jobs_dask(job_list) # test_run_sorter_jobs_slurm(job_list) - test_run_sorter_by_property() + test_run_sorter_by_property(tmp_folder) diff --git a/src/spikeinterface/sorters/tests/test_runsorter.py b/src/spikeinterface/sorters/tests/test_runsorter.py index d41bffa075..52c63141d9 100644 --- a/src/spikeinterface/sorters/tests/test_runsorter.py +++ b/src/spikeinterface/sorters/tests/test_runsorter.py @@ -3,33 +3,31 @@ from pathlib import Path import shutil -import spikeinterface as si -from spikeinterface import download_dataset, generate_ground_truth_recording, load_extractor -from spikeinterface.extractors import read_mearec +from spikeinterface import generate_ground_truth_recording from spikeinterface.sorters import run_sorter ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) -if hasattr(pytest, "global_test_folder"): # TODO try to replace with pytest fixture (tricky one) - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" +def _generate_recording(): + recording, _ = generate_ground_truth_recording(num_channels=8, durations=[10.0], seed=2205) + return recording -rec_folder = cache_folder / "recording" +@pytest.fixture(scope="module") +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder -def setup_module(): - 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) +@pytest.fixture(scope="module") +def generate_recording(): + return _generate_recording() -def test_run_sorter_local(): - # local_path = download_dataset(remote_path="mearec/mearec_test_10s.h5") - # recording, sorting_true = read_mearec(local_path) - recording = load_extractor(rec_folder) + +def test_run_sorter_local(generate_recording, create_cache_folder): + recording = generate_recording + cache_folder = create_cache_folder sorter_params = {"detect_threshold": 4.9} @@ -48,11 +46,9 @@ 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(): - # mearec_filename = download_dataset(remote_path="mearec/mearec_test_10s.h5", unlock=True) - # recording, sorting_true = read_mearec(mearec_filename) - - recording = load_extractor(rec_folder) +def test_run_sorter_docker(generate_recording, create_cache_folder): + recording = generate_recording + cache_folder = create_cache_folder sorter_params = {"detect_threshold": 4.9} @@ -82,17 +78,13 @@ 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(): - # mearec_filename = download_dataset(remote_path="mearec/mearec_test_10s.h5", unlock=True) - # recording, sorting_true = read_mearec(mearec_filename) +def test_run_sorter_singularity(generate_recording, create_cache_folder): + recording = generate_recording + cache_folder = create_cache_folder # use an output folder outside of the package. otherwise dev mode will not work - singularity_cache_folder = Path(si.__file__).parents[3] / "sandbox" - singularity_cache_folder.mkdir(exist_ok=True) - - recording = load_extractor(rec_folder) - - sorter_params = {"detect_threshold": 4.9} + # singularity_cache_folder = Path(si.__file__).parents[3] / "sandbox" + # singularity_cache_folder.mkdir(exist_ok=True) sorter_params = {"detect_threshold": 4.9} @@ -100,7 +92,7 @@ def test_run_sorter_singularity(): for installation_mode in ("dev", "pypi", "github"): print(f"\nTest with installation_mode {installation_mode}") - output_folder = singularity_cache_folder / f"sorting_tdc_singularity_{installation_mode}" + output_folder = cache_folder / f"sorting_tdc_singularity_{installation_mode}" sorting = run_sorter( "tridesclous", recording, @@ -121,7 +113,8 @@ def test_run_sorter_singularity(): if __name__ == "__main__": - setup_module() - # test_run_sorter_local() - # test_run_sorter_docker() - test_run_sorter_singularity() + rec = _generate_recording + cache_folder = Path("tmp") + # test_run_sorter_local(rec, cache_folder) + # test_run_sorter_docker(rec, cache_folder) + test_run_sorter_singularity(rec, cache_folder) From 810bce16cf1a03623e925b5b38d5246971367aa3 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 6 Jun 2024 11:26:02 +0200 Subject: [PATCH 78/81] Move create_cache_folder to conftest.py and cleanup pytest session start/cleanup --- conftest.py | 23 ++++--------------- .../tests/test_analyzer_extension_core.py | 6 ----- .../core/tests/test_baserecording.py | 6 ----- .../core/tests/test_basesnippets.py | 6 ----- .../core/tests/test_basesorting.py | 6 ----- .../core/tests/test_binaryfolder.py | 6 ----- .../tests/test_binaryrecordingextractor.py | 6 ----- .../core/tests/test_channelslicerecording.py | 6 ----- src/spikeinterface/core/tests/test_globals.py | 6 ----- .../core/tests/test_npysnippetsextractor.py | 6 ----- .../core/tests/test_npzsortingextractor.py | 6 ----- .../core/tests/test_sorting_folder.py | 6 ----- .../core/tests/test_time_handling.py | 6 ----- .../tests/test_unitsaggregationsorting.py | 6 ----- .../core/tests/test_waveform_tools.py | 6 ----- ...forms_extractor_backwards_compatibility.py | 6 ----- .../exporters/tests/test_export_to_phy.py | 17 +------------- .../exporters/tests/test_report.py | 9 -------- .../extractors/tests/test_mdaextractors.py | 6 ----- .../tests/test_shybridextractors.py | 6 ----- .../generation/tests/test_drift_tools.py | 7 ------ .../tests/test_deepinterpolation.py | 6 ----- .../preprocessing/tests/test_motion.py | 6 ----- .../preprocessing/tests/test_silence.py | 6 ----- .../preprocessing/tests/test_whiten.py | 6 ----- .../external/tests/test_docker_containers.py | 8 ------- .../tests/test_singularity_containers.py | 8 ------- .../sorters/tests/test_launcher.py | 6 ----- .../sorters/tests/test_runsorter.py | 6 ----- .../tests/test_benchmark_clustering.py | 6 ----- .../tests/test_benchmark_matching.py | 6 ----- .../tests/test_benchmark_motion_estimation.py | 6 ----- .../test_benchmark_motion_interpolation.py | 6 ----- .../tests/test_benchmark_peak_detection.py | 6 ----- .../tests/test_benchmark_peak_localization.py | 6 ----- .../tests/test_benchmark_peak_selection.py | 6 ----- 36 files changed, 5 insertions(+), 247 deletions(-) diff --git a/conftest.py b/conftest.py index 040818320e..b09aca59e6 100644 --- a/conftest.py +++ b/conftest.py @@ -14,16 +14,10 @@ "widgets", "exporters", "sortingcomponents", "generation"] -# define global test folder -def pytest_sessionstart(session): - # setup_stuff - pytest.global_test_folder = Path(__file__).parent / "test_folder" - if pytest.global_test_folder.is_dir(): - shutil.rmtree(pytest.global_test_folder) - pytest.global_test_folder.mkdir() - - for mark_name in mark_names: - (pytest.global_test_folder / mark_name).mkdir() +@pytest.fixture +def create_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder def pytest_collection_modifyitems(config, items): """ @@ -45,12 +39,3 @@ def pytest_collection_modifyitems(config, items): item.add_marker("sorters") else: item.add_marker(module) - - - -def pytest_sessionfinish(session, exitstatus): - # teardown_stuff only if tests passed - # We don't delete the test folder in the CI because it was causing problems with the code coverage. - if exitstatus == 0: - if pytest.global_test_folder.is_dir() and not ON_GITHUB: - shutil.rmtree(pytest.global_test_folder) diff --git a/src/spikeinterface/core/tests/test_analyzer_extension_core.py b/src/spikeinterface/core/tests/test_analyzer_extension_core.py index fefe03c236..b4d96a3391 100644 --- a/src/spikeinterface/core/tests/test_analyzer_extension_core.py +++ b/src/spikeinterface/core/tests/test_analyzer_extension_core.py @@ -11,12 +11,6 @@ import numpy as np -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def get_sorting_analyzer(cache_folder, format="memory", sparse=True): recording, sorting = generate_ground_truth_recording( durations=[30.0], diff --git a/src/spikeinterface/core/tests/test_baserecording.py b/src/spikeinterface/core/tests/test_baserecording.py index 00a9bcc529..eb6cf7ac12 100644 --- a/src/spikeinterface/core/tests/test_baserecording.py +++ b/src/spikeinterface/core/tests/test_baserecording.py @@ -19,12 +19,6 @@ from spikeinterface.core import generate_recording -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_BaseRecording(create_cache_folder): cache_folder = create_cache_folder num_seg = 2 diff --git a/src/spikeinterface/core/tests/test_basesnippets.py b/src/spikeinterface/core/tests/test_basesnippets.py index 595973afce..64f7f76819 100644 --- a/src/spikeinterface/core/tests/test_basesnippets.py +++ b/src/spikeinterface/core/tests/test_basesnippets.py @@ -15,12 +15,6 @@ from spikeinterface.core.base import BaseExtractor -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_BaseSnippets(create_cache_folder): cache_folder = create_cache_folder duration = [4, 3] diff --git a/src/spikeinterface/core/tests/test_basesorting.py b/src/spikeinterface/core/tests/test_basesorting.py index c3ab2cf298..42fdf52eb1 100644 --- a/src/spikeinterface/core/tests/test_basesorting.py +++ b/src/spikeinterface/core/tests/test_basesorting.py @@ -26,12 +26,6 @@ from spikeinterface.core.generate import generate_sorting -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_BaseSorting(create_cache_folder): cache_folder = create_cache_folder num_seg = 2 diff --git a/src/spikeinterface/core/tests/test_binaryfolder.py b/src/spikeinterface/core/tests/test_binaryfolder.py index 58cbf37003..1e64afe4e4 100644 --- a/src/spikeinterface/core/tests/test_binaryfolder.py +++ b/src/spikeinterface/core/tests/test_binaryfolder.py @@ -9,12 +9,6 @@ from spikeinterface.core import generate_recording -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_BinaryFolderRecording(create_cache_folder): cache_folder = create_cache_folder rec = generate_recording(num_channels=10, durations=[2.0, 2.0]) diff --git a/src/spikeinterface/core/tests/test_binaryrecordingextractor.py b/src/spikeinterface/core/tests/test_binaryrecordingextractor.py index a49c210bfe..61af8f322d 100644 --- a/src/spikeinterface/core/tests/test_binaryrecordingextractor.py +++ b/src/spikeinterface/core/tests/test_binaryrecordingextractor.py @@ -5,12 +5,6 @@ from spikeinterface.core.numpyextractors import NumpyRecording -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_BinaryRecordingExtractor(create_cache_folder): cache_folder = create_cache_folder num_seg = 2 diff --git a/src/spikeinterface/core/tests/test_channelslicerecording.py b/src/spikeinterface/core/tests/test_channelslicerecording.py index f5738781fc..5d9354de9b 100644 --- a/src/spikeinterface/core/tests/test_channelslicerecording.py +++ b/src/spikeinterface/core/tests/test_channelslicerecording.py @@ -10,12 +10,6 @@ from spikeinterface.core.generate import generate_recording -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_ChannelSliceRecording(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/core/tests/test_globals.py b/src/spikeinterface/core/tests/test_globals.py index 786ec53d00..9677378fc5 100644 --- a/src/spikeinterface/core/tests/test_globals.py +++ b/src/spikeinterface/core/tests/test_globals.py @@ -15,12 +15,6 @@ from spikeinterface.core.job_tools import fix_job_kwargs -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_global_dataset_folder(create_cache_folder): cache_folder = create_cache_folder dataset_folder = get_global_dataset_folder() diff --git a/src/spikeinterface/core/tests/test_npysnippetsextractor.py b/src/spikeinterface/core/tests/test_npysnippetsextractor.py index b4ca6b234a..c3fbfcd885 100644 --- a/src/spikeinterface/core/tests/test_npysnippetsextractor.py +++ b/src/spikeinterface/core/tests/test_npysnippetsextractor.py @@ -5,12 +5,6 @@ from spikeinterface.core import generate_snippets -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_NpySnippetsExtractor(create_cache_folder): cache_folder = create_cache_folder segment_durations = [2, 5] diff --git a/src/spikeinterface/core/tests/test_npzsortingextractor.py b/src/spikeinterface/core/tests/test_npzsortingextractor.py index 6540a2cd42..4d84ee9a4d 100644 --- a/src/spikeinterface/core/tests/test_npzsortingextractor.py +++ b/src/spikeinterface/core/tests/test_npzsortingextractor.py @@ -5,12 +5,6 @@ from spikeinterface.core import create_sorting_npz -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_NpzSortingExtractor(create_cache_folder): cache_folder = create_cache_folder num_seg = 2 diff --git a/src/spikeinterface/core/tests/test_sorting_folder.py b/src/spikeinterface/core/tests/test_sorting_folder.py index 4ed4d0899e..0fe19534ec 100644 --- a/src/spikeinterface/core/tests/test_sorting_folder.py +++ b/src/spikeinterface/core/tests/test_sorting_folder.py @@ -8,12 +8,6 @@ from spikeinterface.core.testing import check_sorted_arrays_equal, check_sortings_equal -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_NumpyFolderSorting(create_cache_folder): cache_folder = create_cache_folder sorting = generate_sorting(seed=42) diff --git a/src/spikeinterface/core/tests/test_time_handling.py b/src/spikeinterface/core/tests/test_time_handling.py index 0783230d1e..487a893096 100644 --- a/src/spikeinterface/core/tests/test_time_handling.py +++ b/src/spikeinterface/core/tests/test_time_handling.py @@ -4,12 +4,6 @@ from spikeinterface.core import generate_recording, generate_sorting -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_time_handling(create_cache_folder): cache_folder = create_cache_folder durations = [[10], [10, 5]] diff --git a/src/spikeinterface/core/tests/test_unitsaggregationsorting.py b/src/spikeinterface/core/tests/test_unitsaggregationsorting.py index 622e33a1eb..b6cb479c7d 100644 --- a/src/spikeinterface/core/tests/test_unitsaggregationsorting.py +++ b/src/spikeinterface/core/tests/test_unitsaggregationsorting.py @@ -7,12 +7,6 @@ from spikeinterface.core import create_sorting_npz -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_unitsaggregationsorting(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/core/tests/test_waveform_tools.py b/src/spikeinterface/core/tests/test_waveform_tools.py index 757c08c5c7..845eaf1310 100644 --- a/src/spikeinterface/core/tests/test_waveform_tools.py +++ b/src/spikeinterface/core/tests/test_waveform_tools.py @@ -15,12 +15,6 @@ ) -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def _check_all_wf_equal(list_wfs_arrays): wfs_arrays0 = list_wfs_arrays[0] for i, wfs_arrays in enumerate(list_wfs_arrays): diff --git a/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py b/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py index 8d7bc341e1..0157965daf 100644 --- a/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py +++ b/src/spikeinterface/core/tests/test_waveforms_extractor_backwards_compatibility.py @@ -16,12 +16,6 @@ from spikeinterface.core import extract_waveforms as old_extract_waveforms -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def get_dataset(): recording, sorting = generate_ground_truth_recording( durations=[30.0, 20.0], diff --git a/src/spikeinterface/exporters/tests/test_export_to_phy.py b/src/spikeinterface/exporters/tests/test_export_to_phy.py index ddd467be4e..bfba672be1 100644 --- a/src/spikeinterface/exporters/tests/test_export_to_phy.py +++ b/src/spikeinterface/exporters/tests/test_export_to_phy.py @@ -1,26 +1,11 @@ -import pytest import shutil import numpy as np -from spikeinterface.postprocessing import compute_principal_components - -from spikeinterface.core import compute_sparsity from spikeinterface.exporters import export_to_phy -from spikeinterface.exporters.tests.common import ( - make_sorting_analyzer, - sorting_analyzer_sparse_for_export, - sorting_analyzer_with_group_for_export, - sorting_analyzer_dense_for_export, -) - - -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder +from spikeinterface.exporters.tests.common import make_sorting_analyzer def test_export_to_phy_dense(sorting_analyzer_dense_for_export, create_cache_folder): diff --git a/src/spikeinterface/exporters/tests/test_report.py b/src/spikeinterface/exporters/tests/test_report.py index 92383a1458..dd08e9bfc6 100644 --- a/src/spikeinterface/exporters/tests/test_report.py +++ b/src/spikeinterface/exporters/tests/test_report.py @@ -1,21 +1,12 @@ import shutil -import pytest - from spikeinterface.exporters import export_report from spikeinterface.exporters.tests.common import ( make_sorting_analyzer, - sorting_analyzer_sparse_for_export, ) -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_export_report(sorting_analyzer_sparse_for_export, create_cache_folder): cache_folder = create_cache_folder report_folder = cache_folder / "report" diff --git a/src/spikeinterface/extractors/tests/test_mdaextractors.py b/src/spikeinterface/extractors/tests/test_mdaextractors.py index 5a17a87c9d..0ef6697c6c 100644 --- a/src/spikeinterface/extractors/tests/test_mdaextractors.py +++ b/src/spikeinterface/extractors/tests/test_mdaextractors.py @@ -5,12 +5,6 @@ from spikeinterface.extractors import MdaRecordingExtractor, MdaSortingExtractor -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_mda_extractors(create_cache_folder): cache_folder = create_cache_folder rec, sort = generate_ground_truth_recording(durations=[10.0], num_units=10) diff --git a/src/spikeinterface/extractors/tests/test_shybridextractors.py b/src/spikeinterface/extractors/tests/test_shybridextractors.py index a091986dee..221e1bfc2d 100644 --- a/src/spikeinterface/extractors/tests/test_shybridextractors.py +++ b/src/spikeinterface/extractors/tests/test_shybridextractors.py @@ -5,12 +5,6 @@ from spikeinterface.extractors import SHYBRIDRecordingExtractor, SHYBRIDSortingExtractor -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skipif(True, reason="SHYBRID only tested locally") def test_shybrid_extractors(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/generation/tests/test_drift_tools.py b/src/spikeinterface/generation/tests/test_drift_tools.py index b0262b3806..8a4837100e 100644 --- a/src/spikeinterface/generation/tests/test_drift_tools.py +++ b/src/spikeinterface/generation/tests/test_drift_tools.py @@ -1,4 +1,3 @@ -import pytest import numpy as np import shutil @@ -15,12 +14,6 @@ from probeinterface import generate_multi_columns_probe -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def make_some_templates(): probe = generate_multi_columns_probe( num_columns=12, diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index b7b880bb6b..65b1bac539 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -25,12 +25,6 @@ HAVE_DEEPINTERPOLATION = False -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def recording_and_shape(): num_cols = 2 num_rows = 64 diff --git a/src/spikeinterface/preprocessing/tests/test_motion.py b/src/spikeinterface/preprocessing/tests/test_motion.py index b994bcc18f..e79fda1ad8 100644 --- a/src/spikeinterface/preprocessing/tests/test_motion.py +++ b/src/spikeinterface/preprocessing/tests/test_motion.py @@ -10,12 +10,6 @@ import numpy as np -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_estimate_and_correct_motion(create_cache_folder): cache_folder = create_cache_folder rec = generate_recording(durations=[30.0], num_channels=12) diff --git a/src/spikeinterface/preprocessing/tests/test_silence.py b/src/spikeinterface/preprocessing/tests/test_silence.py index 62952f2790..ed11eb8fdd 100644 --- a/src/spikeinterface/preprocessing/tests/test_silence.py +++ b/src/spikeinterface/preprocessing/tests/test_silence.py @@ -10,12 +10,6 @@ import numpy as np -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_silence(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/preprocessing/tests/test_whiten.py b/src/spikeinterface/preprocessing/tests/test_whiten.py index 6c2e3d44a2..c3d1544869 100644 --- a/src/spikeinterface/preprocessing/tests/test_whiten.py +++ b/src/spikeinterface/preprocessing/tests/test_whiten.py @@ -6,12 +6,6 @@ from spikeinterface.preprocessing import whiten, scale, compute_whitening_matrix -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def test_whiten(create_cache_folder): cache_folder = create_cache_folder rec = generate_recording(num_channels=4) diff --git a/src/spikeinterface/sorters/external/tests/test_docker_containers.py b/src/spikeinterface/sorters/external/tests/test_docker_containers.py index eaf621d5a2..f5c42eb6d1 100644 --- a/src/spikeinterface/sorters/external/tests/test_docker_containers.py +++ b/src/spikeinterface/sorters/external/tests/test_docker_containers.py @@ -1,5 +1,4 @@ import os -import shutil import pytest @@ -9,13 +8,6 @@ import spikeinterface.sorters as ss -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - - return cache_folder - - ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) diff --git a/src/spikeinterface/sorters/external/tests/test_singularity_containers.py b/src/spikeinterface/sorters/external/tests/test_singularity_containers.py index c4871e88ca..61b928b6f7 100644 --- a/src/spikeinterface/sorters/external/tests/test_singularity_containers.py +++ b/src/spikeinterface/sorters/external/tests/test_singularity_containers.py @@ -4,17 +4,9 @@ from spikeinterface import generate_ground_truth_recording from spikeinterface.core.core_tools import is_editable_mode -import spikeinterface.extractors as se import spikeinterface.sorters as ss -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - - return cache_folder - - os.environ["SINGULARITY_DISABLE_CACHE"] = "true" ON_GITHUB = os.getenv("GITHUB_ACTIONS") diff --git a/src/spikeinterface/sorters/tests/test_launcher.py b/src/spikeinterface/sorters/tests/test_launcher.py index 69e24488b8..ee4ecb50fa 100644 --- a/src/spikeinterface/sorters/tests/test_launcher.py +++ b/src/spikeinterface/sorters/tests/test_launcher.py @@ -14,12 +14,6 @@ SORTERS = ["tridesclous2"] -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - def create_recordings(NUM_RECORDINGS=2, base_seed=42): recordings = [] for i in range(NUM_RECORDINGS): diff --git a/src/spikeinterface/sorters/tests/test_runsorter.py b/src/spikeinterface/sorters/tests/test_runsorter.py index 52c63141d9..470bdc3602 100644 --- a/src/spikeinterface/sorters/tests/test_runsorter.py +++ b/src/spikeinterface/sorters/tests/test_runsorter.py @@ -14,12 +14,6 @@ def _generate_recording(): return recording -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.fixture(scope="module") def generate_recording(): return _generate_recording() diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py index 319d829d1f..bc36fb607c 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_clustering.py @@ -9,12 +9,6 @@ from spikeinterface.core.template_tools import get_template_extremum_channel -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_clustering(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py index 79a4cb5ae1..aa9b16bb97 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_matching.py @@ -15,12 +15,6 @@ from spikeinterface.sortingcomponents.benchmark.benchmark_matching import MatchingStudy -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_matching(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py index 20ae29e0ac..696531b221 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_estimation.py @@ -10,12 +10,6 @@ from spikeinterface.sortingcomponents.benchmark.benchmark_motion_estimation import MotionEstimationStudy -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_motion_estimaton(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py index e7c3c0402b..4b7264a9de 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_motion_interpolation.py @@ -17,12 +17,6 @@ ) -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_motion_interpolation(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py index 7e1b2bb8cc..dffe1529b7 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_detection.py @@ -9,12 +9,6 @@ from spikeinterface.core.template_tools import get_template_extremum_channel -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_peak_detection(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py index ea64b0d52e..b6f89dcd36 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_localization.py @@ -9,12 +9,6 @@ from spikeinterface.sortingcomponents.benchmark.benchmark_peak_localization import UnitLocalizationStudy -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_peak_localization(create_cache_folder): cache_folder = create_cache_folder diff --git a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py index c033871e86..a9e404292d 100644 --- a/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py +++ b/src/spikeinterface/sortingcomponents/benchmark/tests/test_benchmark_peak_selection.py @@ -1,12 +1,6 @@ import pytest -@pytest.fixture(scope="module") -def create_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skip() def test_benchmark_peak_selection(create_cache_folder): cache_folder = create_cache_folder From 62827ae9094834c3248a4ac07cc49e6d4fea984d Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 6 Jun 2024 11:44:55 +0200 Subject: [PATCH 79/81] Fix scope for test_launcher --- src/spikeinterface/sorters/tests/test_launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/sorters/tests/test_launcher.py b/src/spikeinterface/sorters/tests/test_launcher.py index ee4ecb50fa..362d45cbff 100644 --- a/src/spikeinterface/sorters/tests/test_launcher.py +++ b/src/spikeinterface/sorters/tests/test_launcher.py @@ -44,7 +44,7 @@ def get_job_list(base_folder): return jobs -@pytest.fixture(scope="module") +@pytest.fixture(scope="function") def job_list(create_cache_folder): cache_folder = create_cache_folder folder = cache_folder / "sorting_output" From 06639f2c2083215275482205bb4403f5a49c7363 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 6 Jun 2024 12:08:02 +0200 Subject: [PATCH 80/81] Fix deepinterpolation fixtures --- .../tests/test_deepinterpolation.py | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index 65b1bac539..f110d0b954 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -38,11 +38,17 @@ def recording_and_shape(): return recording, desired_shape -@pytest.fixture +@pytest.fixture(scope="module") def recording_and_shape_fixture(): return recording_and_shape() +@pytest.fixture(scope="module") +def create_deepinteprolation_cache_folder(tmp_path_factory): + cache_folder = tmp_path_factory.mktemp("cache_folder") + return cache_folder + + @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") def test_deepinterpolation_generator_borders(recording_and_shape_fixture): """Test that the generator avoids borders in multi-segment and recording lists cases""" @@ -67,10 +73,10 @@ def test_deepinterpolation_generator_borders(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency() -def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_folder): +def test_deepinterpolation_training(recording_and_shape_fixture, create_deepinteprolation_cache_folder): recording, desired_shape = recording_and_shape_fixture - cache_folder = create_cache_folder + cache_folder = create_deepinteprolation_cache_folder model_folder = Path(cache_folder) / "training" # train model_path = train_deepinterpolation( @@ -88,16 +94,15 @@ def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_fo run_uid="si_test", pre_post_omission=1, desired_shape=desired_shape, - nb_workers=1, ) print(model_path) @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_cache_folder): +def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_deepinteprolation_cache_folder): recording, desired_shape = recording_and_shape_fixture - cache_folder = create_cache_folder + cache_folder = create_deepinteprolation_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" model_folder = Path(tmp_path) / "transfer" @@ -124,10 +129,10 @@ def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, creat @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_folder): - recording, desired_shape = recording_and_shape_fixture +def test_deepinterpolation_inference(recording_and_shape_fixture, create_deepinteprolation_cache_folder): + recording, _ = recording_and_shape_fixture pre_frame = post_frame = 20 - cache_folder = create_cache_folder + cache_folder = create_deepinteprolation_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" recording_di = deepinterpolate( @@ -151,10 +156,10 @@ def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_f @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_cache_folder): - recording, desired_shape = recording_and_shape_fixture +def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_deepinteprolation_cache_folder): + recording, _ = recording_and_shape_fixture pre_frame = post_frame = 20 - cache_folder = create_cache_folder + cache_folder = create_deepinteprolation_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" recording_di = deepinterpolate( From e5ca2a8317b740dc52468b730c06df8a3a96068a Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 6 Jun 2024 12:15:34 +0200 Subject: [PATCH 81/81] Make create_cache_folder module scoped and fix exporters --- conftest.py | 2 +- .../exporters/tests/test_export_to_phy.py | 7 +++++- .../exporters/tests/test_report.py | 3 +++ .../tests/test_deepinterpolation.py | 22 +++++++------------ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/conftest.py b/conftest.py index b09aca59e6..c4bac6628a 100644 --- a/conftest.py +++ b/conftest.py @@ -14,7 +14,7 @@ "widgets", "exporters", "sortingcomponents", "generation"] -@pytest.fixture +@pytest.fixture(scope="module") def create_cache_folder(tmp_path_factory): cache_folder = tmp_path_factory.mktemp("cache_folder") return cache_folder diff --git a/src/spikeinterface/exporters/tests/test_export_to_phy.py b/src/spikeinterface/exporters/tests/test_export_to_phy.py index bfba672be1..47294b3cf7 100644 --- a/src/spikeinterface/exporters/tests/test_export_to_phy.py +++ b/src/spikeinterface/exporters/tests/test_export_to_phy.py @@ -5,7 +5,12 @@ from spikeinterface.exporters import export_to_phy -from spikeinterface.exporters.tests.common import make_sorting_analyzer +from spikeinterface.exporters.tests.common import ( + make_sorting_analyzer, + sorting_analyzer_dense_for_export, + sorting_analyzer_sparse_for_export, + sorting_analyzer_with_group_for_export, +) def test_export_to_phy_dense(sorting_analyzer_dense_for_export, create_cache_folder): diff --git a/src/spikeinterface/exporters/tests/test_report.py b/src/spikeinterface/exporters/tests/test_report.py index dd08e9bfc6..c712fcafb1 100644 --- a/src/spikeinterface/exporters/tests/test_report.py +++ b/src/spikeinterface/exporters/tests/test_report.py @@ -4,6 +4,9 @@ from spikeinterface.exporters.tests.common import ( make_sorting_analyzer, + sorting_analyzer_dense_for_export, + sorting_analyzer_sparse_for_export, + sorting_analyzer_with_group_for_export, ) diff --git a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py index f110d0b954..46c0fbb29c 100644 --- a/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py +++ b/src/spikeinterface/preprocessing/deepinterpolation/tests/test_deepinterpolation.py @@ -43,12 +43,6 @@ def recording_and_shape_fixture(): return recording_and_shape() -@pytest.fixture(scope="module") -def create_deepinteprolation_cache_folder(tmp_path_factory): - cache_folder = tmp_path_factory.mktemp("cache_folder") - return cache_folder - - @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") def test_deepinterpolation_generator_borders(recording_and_shape_fixture): """Test that the generator avoids borders in multi-segment and recording lists cases""" @@ -73,10 +67,10 @@ def test_deepinterpolation_generator_borders(recording_and_shape_fixture): @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency() -def test_deepinterpolation_training(recording_and_shape_fixture, create_deepinteprolation_cache_folder): +def test_deepinterpolation_training(recording_and_shape_fixture, create_cache_folder): recording, desired_shape = recording_and_shape_fixture - cache_folder = create_deepinteprolation_cache_folder + cache_folder = create_cache_folder model_folder = Path(cache_folder) / "training" # train model_path = train_deepinterpolation( @@ -100,9 +94,9 @@ def test_deepinterpolation_training(recording_and_shape_fixture, create_deepinte @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_deepinteprolation_cache_folder): +def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, create_cache_folder): recording, desired_shape = recording_and_shape_fixture - cache_folder = create_deepinteprolation_cache_folder + cache_folder = create_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" model_folder = Path(tmp_path) / "transfer" @@ -129,10 +123,10 @@ def test_deepinterpolation_transfer(recording_and_shape_fixture, tmp_path, creat @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference(recording_and_shape_fixture, create_deepinteprolation_cache_folder): +def test_deepinterpolation_inference(recording_and_shape_fixture, create_cache_folder): recording, _ = recording_and_shape_fixture pre_frame = post_frame = 20 - cache_folder = create_deepinteprolation_cache_folder + cache_folder = create_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" recording_di = deepinterpolate( @@ -156,10 +150,10 @@ def test_deepinterpolation_inference(recording_and_shape_fixture, create_deepint @pytest.mark.skipif(not HAVE_DEEPINTERPOLATION, reason="requires deepinterpolation") @pytest.mark.dependency(depends=["test_deepinterpolation_training"]) -def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_deepinteprolation_cache_folder): +def test_deepinterpolation_inference_multi_job(recording_and_shape_fixture, create_cache_folder): recording, _ = recording_and_shape_fixture pre_frame = post_frame = 20 - cache_folder = create_deepinteprolation_cache_folder + cache_folder = create_cache_folder existing_model_path = Path(cache_folder) / "training" / "si_test_training_model.h5" recording_di = deepinterpolate(