code: def test_events_from_annot_in_raw_objects():
      """Test basic functionality of events_fron_annot for raw objects."""
      raw = read_raw_fif(fif_fname)
      events = mne.find_events(raw)
      event_id = {
          "Auditory/Left": 1,
          "Auditory/Right": 2,
          "Visual/Left": 3,
          "Visual/Right": 4,
          "Visual/Smiley": 32,
          "Motor/Button": 5,
      }
      event_map = {v: k for k, v in event_id.items()}
      annot = Annotations(
          onset=raw.times[events[:, 0] - raw.first_samp],
          duration=np.zeros(len(events)),
          description=[event_map[vv] for vv in events[:, 2]],
          orig_time=None,
      )
      raw.set_annotations(annot)
  
      events2, event_id2 = events_from_annotations(
          raw, event_id=event_id, regexp=None
      )
      assert_array_equal(events, events2)
      assert_equal(event_id, event_id2)
  
      events3, event_id3 = events_from_annotations(
          raw, event_id=None, regexp=None
      )
  
      assert_array_equal(events[:, 0], events3[:, 0])
      assert set(event_id.keys()) == set(event_id3.keys())
  
      # ensure that these actually got sorted properly
      expected_event_id = {
          desc: idx + 1
          for idx, desc in enumerate(sorted(event_id.keys()))
      }
      assert event_id3 == expected_event_id
  
      first = np.unique(events3[:, 2])
      second = np.arange(1, len(event_id) + 1, 1).astype(first.dtype)
      assert_array_equal(first, second)
  
      first = np.unique(list(event_id3.values()))
      second = np.arange(1, len(event_id) + 1, 1).astype(first.dtype)
      assert_array_equal(first, second)
  
      events4, event_id4 = events_from_annotations(
          raw, event_id=None, regexp=".*Left"
      )
  
      expected_event_id4 = {
          k: v for k, v in event_id.items() if "Left" in k
      }
      assert_equal(event_id4.keys(), expected_event_id4.keys())
  
      expected_events4 = events[
          (events[:, 2] == 1) | (events[:, 2] == 3)
      ]
      assert_array_equal(expected_events4[:, 0], events4[:, 0])
  
      events5, event_id5 = events_from_annotations(
          raw, event_id=event_id, regexp=".*Left"
      )
  
      expected_event_id5 = {
          k: v for k, v in event_id.items() if "Left" in k
      }
      assert_equal(event_id5, expected_event_id5)
  
      expected_events5 = events[
          (events[:, 2] == 1) | (events[:, 2] == 3)
      ]
      assert_array_equal(expected_events5, events5)
  
      with pytest.raises(
          ValueError, match="not find any of the events"
      ):
          events_from_annotations(raw, regexp="not_there")
  
      with pytest.raises(ValueError, match="Invalid type for event_id"):
          events_from_annotations(raw, event_id="wrong")
  
      # concat does not introduce BAD or EDGE
      raw_concat = concatenate_raws([raw.copy(), raw.copy()])
      _, event_id = events_from_annotations(raw_concat)
      assert isinstance(event_id, dict)
      assert len(event_id) > 0
      for kind in ("BAD", "EDGE"):
          assert (
              "%s boundary" % kind in raw_concat.annotations.description
          )
          for key in event_id.keys():
              assert kind not in key
  
      # remove all events
      raw.set_annotations(None)
      events7, _ = events_from_annotations(raw)
      assert_array_equal(events7, np.empty((0, 3), dtype=int))
  
imports: import sys
  from collections import OrderedDict
  from datetime import datetime, timedelta, timezone
  from itertools import repeat
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from pytest import approx
  import mne
  from mne import Annotations, Epochs, annotations_from_events, count_annotations, create_info, events_from_annotations, read_annotations
  from mne.annotations import _handle_meas_date, _read_annotations_txt_parse_header, _sync_onset
  from mne.datasets import testing
  from mne.io import RawArray, concatenate_raws, read_raw_fif
  from mne.utils import _dt_to_stamp, _raw_annot, _record_warnings, _stamp_to_dt, assert_and_remove_boundary_annot, catch_logging, check_version
label_desc: Use image node_id 17 for calling a global function with example usage: test_events_from_annot_in_raw_objects() without return types