code: def test_io_set_raw(fname):
      """Test importing EEGLAB .set files."""
      montage = read_custom_montage(montage_path)
      montage.ch_names = [
          f"EEG {ii:03d}" for ii in range(len(montage.ch_names))
      ]
  
      kws = dict(reader=read_raw_eeglab, input_fname=fname)
      if fname.name == "test_raw_chanloc.set":
          with pytest.warns(
              RuntimeWarning,
              match="The data contains 'boundary' events",
          ):
              raw0 = _test_raw_reader(**kws)
      elif (
          "_h5" in fname.name
      ):  # should be safe enough, and much faster
          raw0 = read_raw_eeglab(fname, preload=True)
      else:
          raw0 = _test_raw_reader(**kws)
  
      # test that preloading works
      if fname.name == "test_raw_chanloc.set":
          raw0.set_montage(montage, on_missing="ignore")
          # crop to check if the data has been properly preloaded; we cannot
          # filter as the snippet of raw data is very short
          raw0.crop(0, 1)
      else:
          raw0.set_montage(montage)
          raw0.filter(
              1,
              None,
              l_trans_bandwidth="auto",
              filter_length="auto",
              phase="zero",
          )
  
      # test that using uint16_codec does not break stuff
      read_raw_kws = dict(
          input_fname=fname, preload=False, uint16_codec="ascii"
      )
      if fname.name == "test_raw_chanloc.set":
          with pytest.warns(
              RuntimeWarning,
              match="The data contains 'boundary' events",
          ):
              raw0 = read_raw_eeglab(**read_raw_kws)
              raw0.set_montage(montage, on_missing="ignore")
      else:
          raw0 = read_raw_eeglab(**read_raw_kws)
          raw0.set_montage(montage)
  
      # Annotations
      if fname != raw_fname_chanloc:
          assert len(raw0.annotations) == 154
          assert set(raw0.annotations.description) == {"rt", "square"}
          assert_array_equal(raw0.annotations.duration, 0.0)
  
imports: import os
  import shutil
  from copy import deepcopy
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy import io
  import mne
  from mne import read_epochs_eeglab, write_events
  from mne.annotations import events_from_annotations, read_annotations
  from mne.channels import read_custom_montage
  from mne.datasets import testing
  from mne.io import read_raw_eeglab
  from mne.io.eeglab._eeglab import _readmat
  from mne.io.eeglab.eeglab import _dol_to_lod, _get_montage_information
  from mne.io.tests.test_raw import _test_raw_reader
  from mne.utils import Bunch, _check_pymatreader_installed
label_desc: Use image node_id 1 for calling a global function with example usage: test_io_set_raw(fname) without return types