Skip to content

Commit

Permalink
correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qian-chu committed Dec 13, 2024
1 parent 3b707e4 commit e556b96
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions mne/export/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ def test_export_raw_eeglab_annotations(tmp_path, tmin):
# read in the file
with pytest.warns(RuntimeWarning, match="is above the 99th percentile"):
raw_read = read_raw_eeglab(temp_fname, preload=True, montage_units="m")
assert raw_read.first_time == 0

valid_annot = raw.annotations.onset >= tmin
assert raw_read.first_time == 0 # exportation resets first_time
valid_annot = raw.annotations.onset >= tmin # only annotations in the cropped range gets exported

# compare annotations before and after export
assert_array_almost_equal(
raw.annotations.onset[valid_annot] - raw.first_time,
raw_read.annotations.onset - raw_read.first_time,
raw_read.annotations.onset,
)
assert_array_equal(
raw.annotations.duration[valid_annot], raw_read.annotations.duration
Expand Down Expand Up @@ -194,6 +195,7 @@ def test_double_export_edf(tmp_path):
"""Test exporting an EDF file multiple times."""
raw = _create_raw_for_edf_tests(stim_channel_index=2)
raw.info.set_meas_date("2023-09-04 14:53:09.000")
raw.set_annotations(Annotations(onset=[1], duration=[0], description=["test"]))

# include subject info and measurement date
raw.info["subject_info"] = dict(
Expand Down Expand Up @@ -315,7 +317,7 @@ def test_export_edf_annotations(tmp_path, tmin):
raw.crop(tmin)
assert raw.first_time == tmin

if tmin % 1 == 0:
if raw.n_times % raw.info["sfreq"] == 0:
expectation = nullcontext()
else:
expectation = pytest.warns(
Expand All @@ -325,16 +327,20 @@ def test_export_edf_annotations(tmp_path, tmin):
# export
temp_fname = tmp_path / "test.edf"
with expectation:
raw.export(temp_fname, physical_range=(0, 10))
raw.export(temp_fname)

# read in the file
raw_read = read_raw_edf(temp_fname, preload=True)
assert raw_read.first_time == 0

valid_annot = raw.annotations.onset >= tmin
assert raw_read.first_time == 0 # exportation resets first_time
bad_annot = raw_read.annotations.description == "BAD_ACQ_SKIP"
if bad_annot.any():
raw_read.annotations.delete(bad_annot)
valid_annot = raw.annotations.onset >= tmin # only annotations in the cropped range gets exported

# compare annotations before and after export
assert_array_almost_equal(
raw.annotations.onset[valid_annot] - raw.first_time,
raw_read.annotations.onset - raw_read.first_time,
raw_read.annotations.onset
)
assert_array_equal(
raw.annotations.duration[valid_annot], raw_read.annotations.duration
Expand Down

0 comments on commit e556b96

Please sign in to comment.