code: def test_add_events():
      """Test adding events to a Raw file."""
      # need preload
      raw = read_raw_fif(raw_fname)
      events = np.array([[raw.first_samp, 0, 1]])
      pytest.raises(RuntimeError, raw.add_events, events, "STI 014")
      raw = read_raw_fif(raw_fname, preload=True)
      orig_events = find_events(raw, "STI 014")
      # add some events
      events = np.array([raw.first_samp, 0, 1])
      pytest.raises(
          ValueError, raw.add_events, events, "STI 014"
      )  # bad shape
      events[0] = raw.first_samp + raw.n_times + 1
      events = events[np.newaxis, :]
      pytest.raises(
          ValueError, raw.add_events, events, "STI 014"
      )  # bad time
      events[0, 0] = raw.first_samp - 1
      pytest.raises(
          ValueError, raw.add_events, events, "STI 014"
      )  # bad time
      events[0, 0] = raw.first_samp + 1  # can't actually be first_samp
      pytest.raises(ValueError, raw.add_events, events, "STI FOO")
      raw.add_events(events, "STI 014")
      new_events = find_events(raw, "STI 014")
      assert_array_equal(
          new_events, np.concatenate((events, orig_events))
      )
      raw.add_events(events, "STI 014", replace=True)
      new_events = find_events(raw, "STI 014")
      assert_array_equal(new_events, events)
  
imports: import os
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from mne import Annotations, Epochs, compute_raw_covariance, count_events, create_info, find_events, find_stim_steps, make_fixed_length_events, pick_channels, pick_events, read_events, read_evokeds, write_events
  from mne.datasets import testing
  from mne.event import AcqParserFIF, define_target_events, match_event_names, merge_events, shift_time_events
  from mne.io import RawArray, read_raw_fif
label_desc: Use image node_id 2 for calling a global function with example usage: test_add_events() without return types