code: def test_io_evoked(tmp_path):
      """Test IO for evoked data (fif + gz) with integer and str args."""
      ave = read_evokeds(fname, 0)
      ave_double = ave.copy()
      ave_double.comment = ave.comment + " doubled nave"
      ave_double.nave = ave.nave * 2
  
      write_evokeds(tmp_path / "evoked-ave.fif", [ave, ave_double])
      ave2, ave_double = read_evokeds(tmp_path / "evoked-ave.fif")
      assert ave2.nave * 2 == ave_double.nave
  
      # This not being assert_array_equal due to windows rounding
      assert np.allclose(ave.data, ave2.data, atol=1e-16, rtol=1e-3)
      assert_array_almost_equal(ave.times, ave2.times)
      assert_equal(ave.nave, ave2.nave)
      assert_equal(ave._aspect_kind, ave2._aspect_kind)
      assert_equal(ave.kind, ave2.kind)
      assert_equal(ave.last, ave2.last)
      assert_equal(ave.first, ave2.first)
      assert repr(ave)
      assert ave._repr_html_()  # test _repr_html_
  
      # test compressed i/o
      ave2 = read_evokeds(fname_gz, 0)
      assert np.allclose(ave.data, ave2.data, atol=1e-16, rtol=1e-8)
  
      # test str access
      condition = "Left Auditory"
      pytest.raises(
          ValueError, read_evokeds, fname, condition, kind="stderr"
      )
      pytest.raises(
          ValueError,
          read_evokeds,
          fname,
          condition,
          kind="standard_error",
      )
      ave3 = read_evokeds(fname, condition)
      assert_array_almost_equal(ave.data, ave3.data, 19)
  
      # test read_evokeds and write_evokeds
      aves1 = read_evokeds(fname)[1::2]
      aves2 = read_evokeds(fname, [1, 3])
      aves3 = read_evokeds(fname, ["Right Auditory", "Right visual"])
      write_evokeds(tmp_path / "evoked-ave.fif", aves1, overwrite=True)
      aves4 = read_evokeds(tmp_path / "evoked-ave.fif")
      for aves in [aves2, aves3, aves4]:
          for [av1, av2] in zip(aves1, aves):
              assert_array_almost_equal(av1.data, av2.data)
              assert_array_almost_equal(av1.times, av2.times)
              assert_equal(av1.nave, av2.nave)
              assert_equal(av1.kind, av2.kind)
              assert_equal(av1._aspect_kind, av2._aspect_kind)
              assert_equal(av1.last, av2.last)
              assert_equal(av1.first, av2.first)
              assert_equal(av1.comment, av2.comment)
  
      # test saving and reading complex numbers in evokeds
      ave_complex = ave.copy()
      ave_complex._data = 1j * ave_complex.data
      fname_temp = str(tmp_path / "complex-ave.fif")
      ave_complex.save(fname_temp)
      ave_complex = read_evokeds(fname_temp)[0]
      assert_allclose(ave.data, ave_complex.data.imag)
  
      # test non-ascii comments (gh 11684)
      aves1[0].comment = "🙃"
      write_evokeds(tmp_path / "evoked-ave.fif", aves1, overwrite=True)
      aves1_read = read_evokeds(tmp_path / "evoked-ave.fif")[0]
      assert aves1_read.comment == aves1[0].comment
  
      # test warnings on bad filenames
      fname2 = tmp_path / "test-bad-name.fif"
      with pytest.warns(RuntimeWarning, match="-ave.fif"):
          write_evokeds(fname2, ave)
      with pytest.warns(RuntimeWarning, match="-ave.fif"):
          read_evokeds(fname2)
  
      # test writing when order of bads doesn't match
      fname3 = tmp_path / "test-bad-order-ave.fif"
      condition = "Left Auditory"
      ave4 = read_evokeds(fname, condition)
      ave4.info["bads"] = ave4.ch_names[:3]
      ave5 = ave4.copy()
      ave5.info["bads"] = ave4.info["bads"][::-1]
      write_evokeds(fname3, [ave4, ave5])
  
      # constructor
      pytest.raises(TypeError, Evoked, fname)
  
      # MaxShield
      fname_ms = tmp_path / "test-ave.fif"
      assert ave.info["maxshield"] is False
      with ave.info._unlock():
          ave.info["maxshield"] = True
      ave.save(fname_ms)
      pytest.raises(ValueError, read_evokeds, fname_ms)
      with pytest.warns(RuntimeWarning, match="Elekta"):
          aves = read_evokeds(fname_ms, allow_maxshield=True)
      assert all(ave.info["maxshield"] is True for ave in aves)
      aves = read_evokeds(fname_ms, allow_maxshield="yes")
      assert all(ave.info["maxshield"] is True for ave in aves)
  
      # Channel names
      with ave.info._unlock():
          ave.info["maxshield"] = False
      ave.rename_channels(lambda ch_name: ch_name.replace(" ", ":"))
      assert ":" in ave.ch_names[0]
      ave.save(fname_ms, overwrite=True)
      ave6 = read_evokeds(fname_ms)[0]
      assert ave.ch_names == ave6.ch_names
  
imports: import pickle
  from copy import deepcopy
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy import fftpack
  from mne import Epochs, EpochsArray, combine_evoked, create_info, equalize_channels, pick_types, read_events, read_evokeds, write_evokeds
  from mne._fiff.constants import FIFF
  from mne.evoked import Evoked, EvokedArray, _get_peak
  from mne.io import read_raw_fif
  from mne.utils import grand_average
label_desc: Use image node_id 7 for calling a global function with example usage: test_io_evoked(tmp_path) without return types