improved tests to check all stored and recovered windows
@@ -6,6 +6,7 @@ import os
import pytest
import numpy as np
+import pandas as pd
from braindecode.datasets.moabb import MOABBDataset
from braindecode.datautil.windowers import create_windows_from_events
@@ -19,8 +20,7 @@ def setup_windows_ds():
return create_windows_from_events(
concat_ds=moabb_ds,
trial_start_offset_samples=0,
- trial_stop_offset_samples=0
- )
+ trial_stop_offset_samples=0)
def test_store_windows_dataset(setup_windows_ds, tmpdir):
@@ -29,9 +29,9 @@ def test_store_windows_dataset(setup_windows_ds, tmpdir):
store_windows_dataset(
windows_dataset=windows_ds, path=tmpdir, overwrite=False)
assert os.path.exists(tmpdir.join(f"description.json"))
- assert os.path.exists(tmpdir.join("./0-epo.fif"))
- assert os.path.exists(tmpdir.join(f"./{n_windows_ds - 1}-epo.fif"))
- assert not os.path.exists(tmpdir.join(f"./{n_windows_ds}-epo.fif"))
+ for windows_i in range(n_windows_ds):
+ assert os.path.exists(tmpdir.join(f"{windows_i}-epo.fif"))
+ assert not os.path.exists(tmpdir.join(f"{n_windows_ds}-epo.fif"))
def test_recover_windows_dataset(setup_windows_ds, tmpdir):
@@ -42,8 +42,11 @@ def test_recover_windows_dataset(setup_windows_ds, tmpdir):
assert len(windows_ds) == len(recovered_windows_ds)
assert len(windows_ds.datasets) == len(recovered_windows_ds.datasets)
assert len(windows_ds.description) == len(recovered_windows_ds.description)
- actual_x, actual_y, actual_crop_inds = windows_ds[0]
- x, y, crop_inds = recovered_windows_ds[0]
+ for windows_i in range(len(windows_ds)):
+ actual_x, actual_y, actual_crop_inds = windows_ds[windows_i]
+ x, y, crop_inds = recovered_windows_ds[windows_i]
np.testing.assert_allclose(x, actual_x, rtol=1e-4, atol=1e-5)
np.testing.assert_allclose(y, actual_y, rtol=1e-4, atol=1e-5)
- np.testing.assert_allclose(crop_inds, actual_crop_inds, rtol=1e-4, atol=1e-5)
+ np.testing.assert_array_equal(crop_inds, actual_crop_inds)
+ pd.testing.assert_frame_equal(
+ windows_ds.description, recovered_windows_ds.description)
