code: def test_io_set_raw_more(tmp_path):
      """Test importing EEGLAB .set files."""
      eeg = io.loadmat(
          raw_fname_mat, struct_as_record=False, squeeze_me=True
      )["EEG"]
  
      # test reading file with one event (read old version)
      negative_latency_fname = tmp_path / "test_negative_latency.set"
      events = deepcopy(eeg.event[0])
      events.latency = 0
      io.savemat(
          negative_latency_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": eeg.nbchan,
                  "data": "test_negative_latency.fdt",
                  "epoch": eeg.epoch,
                  "event": events,
                  "chanlocs": eeg.chanlocs,
                  "pnts": eeg.pnts,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      shutil.copyfile(
          base_dir / "test_raw.fdt",
          negative_latency_fname.with_suffix(".fdt"),
      )
      with pytest.warns(
          RuntimeWarning, match="has a sample index of -1."
      ):
          read_raw_eeglab(
              input_fname=negative_latency_fname, preload=True
          )
  
      # test negative event latencies
      events.latency = -1
      io.savemat(
          negative_latency_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": eeg.nbchan,
                  "data": "test_negative_latency.fdt",
                  "epoch": eeg.epoch,
                  "event": events,
                  "chanlocs": eeg.chanlocs,
                  "pnts": eeg.pnts,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      with pytest.raises(
          ValueError, match="event sample index is negative"
      ):
          with pytest.warns(
              RuntimeWarning, match="has a sample index of -1."
          ):
              read_raw_eeglab(
                  input_fname=negative_latency_fname, preload=True
              )
  
      # test overlapping events
      overlap_fname = tmp_path / "test_overlap_event.set"
      io.savemat(
          overlap_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": eeg.nbchan,
                  "data": "test_overlap_event.fdt",
                  "epoch": eeg.epoch,
                  "event": [eeg.event[0], eeg.event[0]],
                  "chanlocs": eeg.chanlocs,
                  "pnts": eeg.pnts,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      shutil.copyfile(
          base_dir / "test_raw.fdt", overlap_fname.with_suffix(".fdt")
      )
      read_raw_eeglab(input_fname=overlap_fname, preload=True)
  
      # test reading file with empty event durations
      empty_dur_fname = tmp_path / "test_empty_durations.set"
      events = deepcopy(eeg.event)
      for ev in events:
          ev.duration = np.array([], dtype="float")
  
      io.savemat(
          empty_dur_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": eeg.nbchan,
                  "data": "test_negative_latency.fdt",
                  "epoch": eeg.epoch,
                  "event": events,
                  "chanlocs": eeg.chanlocs,
                  "pnts": eeg.pnts,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      shutil.copyfile(
          base_dir / "test_raw.fdt", empty_dur_fname.with_suffix(".fdt")
      )
      raw = read_raw_eeglab(input_fname=empty_dur_fname, preload=True)
      assert (raw.annotations.duration == 0).all()
  
      # test reading file when the EEG.data name is wrong
      io.savemat(
          overlap_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": eeg.nbchan,
                  "data": "test_overla_event.fdt",
                  "epoch": eeg.epoch,
                  "event": [eeg.event[0], eeg.event[0]],
                  "chanlocs": eeg.chanlocs,
                  "pnts": eeg.pnts,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      with pytest.warns(
          RuntimeWarning, match="must have changed on disk"
      ):
          read_raw_eeglab(input_fname=overlap_fname, preload=True)
  
      # raise error when both EEG.data and fdt name from set are wrong
      overlap_fname = tmp_path / "test_ovrlap_event.set"
      io.savemat(
          overlap_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": eeg.nbchan,
                  "data": "test_overla_event.fdt",
                  "epoch": eeg.epoch,
                  "event": [eeg.event[0], eeg.event[0]],
                  "chanlocs": eeg.chanlocs,
                  "pnts": eeg.pnts,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      with pytest.raises(
          FileNotFoundError, match="not find the .fdt data file"
      ):
          read_raw_eeglab(input_fname=overlap_fname, preload=True)
  
      # test reading file with one channel
      one_chan_fname = tmp_path / "test_one_channel.set"
      io.savemat(
          one_chan_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": 1,
                  "data": np.random.random((1, 3)),
                  "epoch": eeg.epoch,
                  "event": eeg.epoch,
                  "chanlocs": {
                      "labels": "E1",
                      "Y": -6.6069,
                      "X": 6.3023,
                      "Z": -2.9423,
                  },
                  "times": eeg.times[:3],
                  "pnts": 3,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      read_raw_eeglab(
          input_fname=one_chan_fname, preload=True, montage_units="cm"
      )
  
      # test reading file with 3 channels - one without position information
      # first, create chanlocs structured array
      ch_names = ["F3", "unknown", "FPz"]
      x, y, z = (
          [1.0, 2.0, np.nan],
          [4.0, 5.0, np.nan],
          [7.0, 8.0, np.nan],
      )
      dt = [("labels", "S10"), ("X", "f8"), ("Y", "f8"), ("Z", "f8")]
      nopos_dt = [("labels", "S10"), ("Z", "f8")]
      chanlocs = np.zeros((3,), dtype=dt)
      nopos_chanlocs = np.zeros((3,), dtype=nopos_dt)
      for ind, vals in enumerate(zip(ch_names, x, y, z)):
          for fld in range(4):
              chanlocs[ind][dt[fld][0]] = vals[fld]
              if fld in (0, 3):
                  nopos_chanlocs[ind][dt[fld][0]] = vals[fld]
      # In theory this should work and be simpler, but there is an obscure
      # SciPy writing bug that pops up sometimes:
      # nopos_chanlocs = np.array(chanlocs[['labels', 'Z']])
  
      # test reading channel names but not positions when there is no X (only Z)
      # field in the EEG.chanlocs structure
      nopos_fname = tmp_path / "test_no_chanpos.set"
      io.savemat(
          nopos_fname,
          {
              "EEG": {
                  "trials": eeg.trials,
                  "srate": eeg.srate,
                  "nbchan": 3,
                  "data": np.random.random((3, 2)),
                  "epoch": eeg.epoch,
                  "event": eeg.epoch,
                  "chanlocs": nopos_chanlocs,
                  "times": eeg.times[:2],
                  "pnts": 2,
              }
          },
          appendmat=False,
          oned_as="row",
      )
      # load the file
      raw = read_raw_eeglab(
          input_fname=nopos_fname, preload=True, montage_units="cm"
      )
  
      # test that channel names have been loaded but not channel positions
      for i in range(3):
          assert_equal(raw.info["chs"][i]["ch_name"], ch_names[i])
          assert_array_equal(
              raw.info["chs"][i]["loc"][:3],
              np.array([np.nan, np.nan, np.nan]),
          )
  
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 2 for calling a global function with example usage: test_io_set_raw_more(tmp_path) without return types