Skip to content

Commit

Permalink
factor out overwrite test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalt committed Aug 14, 2023
1 parent 5bdbf92 commit 1747aac
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions mne/tests/test_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ def test_epochs_io_preload(tmp_path, preload):

@pytest.fixture(scope="session")
def epochs_factory():
"""Function to create fake Epochs object.""" # noqa: D401
"""Function to create fake Epochs object.""" # noqa: D401 (imperative mood)

def factory(n_epochs, metadata=False, concat=False):
if metadata:
Expand Down Expand Up @@ -1565,9 +1565,6 @@ def test_split_naming(tmp_path, epochs_to_split):
epochs.save(split_fname, split_naming="bids", verbose=True)
assert split_fname.is_file()
assert not split_fname_bids_part1.is_file()
for split_naming in ("neuromag", "bids"):
with pytest.raises(FileExistsError, match="Destination file"):
epochs.save(split_fname, split_naming=split_naming, verbose=True)
os.remove(split_fname)
# we don't test for reserved files as it's not implemented here

Expand All @@ -1586,6 +1583,20 @@ def test_split_naming(tmp_path, epochs_to_split):
assert split_fname_bids_part1.is_file()


@pytest.mark.parametrize("split_naming", ["neuromag", "bids"])
def test_saving_fails_with_not_permitted_overwrite(
tmp_path, epochs_factory, split_naming
):
"""Check exception is raised when overwriting without explicit flag."""
dst_fpath = tmp_path / "test-epo.fif"
epochs = epochs_factory(n_epochs=5)

epochs.save(dst_fpath, split_naming=split_naming, verbose=True)

with pytest.raises(FileExistsError, match="Destination file"):
epochs.save(dst_fpath, split_naming=split_naming, verbose=True)


@pytest.mark.slowtest
def test_split_many_reset(tmp_path):
"""Test splitting with many events and using reset."""
Expand Down

0 comments on commit 1747aac

Please sign in to comment.