From 1747aacb8be625003f2ffa7ca3581aae00ff33b7 Mon Sep 17 00:00:00 2001 From: Dmitrii Altukhov Date: Mon, 14 Aug 2023 20:03:33 +0200 Subject: [PATCH] factor out overwrite test --- mne/tests/test_epochs.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mne/tests/test_epochs.py b/mne/tests/test_epochs.py index d557307b428..eed3d99bcd4 100644 --- a/mne/tests/test_epochs.py +++ b/mne/tests/test_epochs.py @@ -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: @@ -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 @@ -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."""