Skip to content

Commit a905e85

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 32e3a04 commit a905e85

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

tests/test_integration/test_diagnostic_plots.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
1-
import pytest
1+
import shutil
22
from pathlib import Path
33

4-
from spikewrap.structure._preprocess_run import PreprocessedRun
5-
import spikewrap.visualise
6-
import numpy as np
74
import matplotlib.pyplot as plt
8-
import shutil
5+
import numpy as np
6+
import pytest
7+
8+
from spikewrap.structure._preprocess_run import PreprocessedRun
9+
910

1011
@pytest.fixture
1112
def mock_preprocessed_run(tmp_path, monkeypatch):
1213
"""
1314
Fixture to create a temporary PreprocessedRun instance with mock data.
1415
"""
1516

16-
from spikewrap.structure._preprocess_run import PreprocessedRun
17-
1817
def mock_plot(*args, **kwargs):
1918
pass
20-
19+
2120
def mock_figure(*args, **kwargs):
2221
class MockFigure:
2322
def savefig(self, path):
2423
Path(path).parent.mkdir(parents=True, exist_ok=True)
2524
Path(path).touch()
26-
25+
2726
def clf(self):
2827
pass
29-
28+
3029
return MockFigure()
31-
30+
3231
def mock_visualise(*args, **kwargs):
3332
return mock_figure()
34-
33+
3534
monkeypatch.setattr(plt, "figure", mock_figure)
3635
monkeypatch.setattr(plt, "plot", mock_plot)
3736
monkeypatch.setattr(plt, "subplot", lambda *args, **kwargs: None)
3837
monkeypatch.setattr(plt, "title", lambda *args, **kwargs: None)
39-
38+
4039
import sys
40+
4141
module_name = PreprocessedRun.__module__
4242
module = sys.modules[module_name]
4343
monkeypatch.setattr(module, "visualise_run_preprocessed", mock_visualise)
44-
44+
4545
class MockRecording:
4646
def __init__(self):
4747
self.properties = {}
48-
self.data = np.random.random((10, 1000))
49-
48+
self.data = np.random.random((10, 1000))
49+
5050
def save(self, folder, chunk_duration):
5151
Path(folder).mkdir(parents=True, exist_ok=True)
5252
(Path(folder) / "mock_recording_saved.txt").touch()
5353
return True
54-
54+
5555
def get_property(self, property_name):
5656
return self.properties.get(property_name, [])
57-
57+
5858
def get_traces(self, *args, **kwargs):
5959
return self.data
60-
60+
6161
def __array__(self):
6262
return self.data
63-
63+
6464
# Set up a mock recording with bad channels
6565
mock_recording = MockRecording()
66-
mock_recording.properties["bad_channels"] = [0, 1]
67-
66+
mock_recording.properties["bad_channels"] = [0, 1]
67+
6868
raw_data_path = tmp_path / "raw_data"
6969
session_output_path = tmp_path / "output"
7070
run_name = "test_run"
71-
71+
7272
preprocessed_data = {"shank_0": {"0": mock_recording, "1": mock_recording}}
7373

74-
raw_data_path.mkdir(parents=True, exist_ok=True)
74+
raw_data_path.mkdir(parents=True, exist_ok=True)
7575
session_output_path.mkdir(parents=True, exist_ok=True)
76-
76+
7777
preprocessed_path = session_output_path / run_name / "preprocessed"
7878
preprocessed_path.mkdir(parents=True, exist_ok=True)
79-
79+
8080
diagnostic_path = session_output_path / "diagnostic_plots"
8181
diagnostic_path.mkdir(parents=True, exist_ok=True)
82-
82+
8383
preprocessed_run = PreprocessedRun(
8484
raw_data_path=raw_data_path,
8585
ses_name="test_session",
@@ -89,20 +89,24 @@ def __array__(self):
8989
preprocessed_data=preprocessed_data,
9090
pp_steps={"step_1": "bad_channel_detection"},
9191
)
92-
92+
9393
def mock_save_diagnostic_plots(self):
9494
diagnostic_path = self._output_path / "diagnostic_plots"
9595
diagnostic_path.mkdir(parents=True, exist_ok=True)
96-
96+
9797
for shank_name in self._preprocessed:
9898
(diagnostic_path / f"{shank_name}_before_detection.png").touch()
9999
(diagnostic_path / f"{shank_name}_after_detection.png").touch()
100-
100+
101101
for ch in [0, 1]:
102102
(diagnostic_path / f"{shank_name}_bad_channel_{ch}.png").touch()
103-
103+
104104
# Monkeypatch the method to create placeholder files instead of real plots
105-
monkeypatch.setattr(preprocessed_run, "_save_diagnostic_plots", mock_save_diagnostic_plots.__get__(preprocessed_run))
105+
monkeypatch.setattr(
106+
preprocessed_run,
107+
"_save_diagnostic_plots",
108+
mock_save_diagnostic_plots.__get__(preprocessed_run),
109+
)
106110

107111
yield preprocessed_run
108112

@@ -120,10 +124,14 @@ def test_diagnostic_plots_saved(self, mock_preprocessed_run):
120124

121125
if output_dir.exists():
122126
shutil.rmtree(output_dir)
123-
assert not output_dir.exists(), "Diagnostic plots directory should not exist before running save_preprocessed"
127+
assert (
128+
not output_dir.exists()
129+
), "Diagnostic plots directory should not exist before running save_preprocessed"
124130

125131
# Should trigger the diagnostic plot saving
126-
mock_preprocessed_run.save_preprocessed(overwrite=True, chunk_duration_s=1.0, n_jobs=1, slurm=False)
132+
mock_preprocessed_run.save_preprocessed(
133+
overwrite=True, chunk_duration_s=1.0, n_jobs=1, slurm=False
134+
)
127135

128136
assert output_dir.exists(), "Diagnostic plots directory was not created"
129137
shank_name = "shank_0"

0 commit comments

Comments
 (0)