code: def test_read_vhdr_annotations_and_events(tmp_path):
      """Test load brainvision annotations and parse them to events."""
      # First we add a custom event that contains a comma in its description
      for src, dest in zip(
          (vhdr_path, vmrk_path, eeg_path),
          ("test.vhdr", "test.vmrk", "test.eeg"),
      ):
          shutil.copyfile(src, tmp_path / dest)
  
      # Commas are encoded as "\1"
      with open(tmp_path / "test.vmrk", "a") as fout:
          fout.write(r"Mk15=Comma\1Type,CommaValue\11,7800,1,0\n")
  
      sfreq = 1000.0
      expected_orig_time = _stamp_to_dt((1384359243, 794232))
      expected_onset_latency = np.array(
          [
              0,
              486.0,
              496.0,
              1769.0,
              1779.0,
              3252.0,
              3262.0,
              4935.0,
              4945.0,
              5999.0,
              6619.0,
              6629.0,
              7629.0,
              7699.0,
              7799.0,
          ]
      )
      expected_annot_description = [
          "New Segment/",
          "Stimulus/S253",
          "Stimulus/S255",
          "Event/254",
          "Stimulus/S255",
          "Event/254",
          "Stimulus/S255",
          "Stimulus/S253",
          "Stimulus/S255",
          "Response/R255",
          "Event/254",
          "Stimulus/S255",
          "SyncStatus/Sync On",
          "Optic/O  1",
          "Comma,Type/CommaValue,1",
      ]
      expected_events = (
          np.stack(
              [
                  expected_onset_latency,
                  np.zeros_like(expected_onset_latency),
                  [
                      99999,
                      253,
                      255,
                      254,
                      255,
                      254,
                      255,
                      253,
                      255,
                      1255,
                      254,
                      255,
                      99998,
                      2001,
                      10001,
                  ],
              ]
          )
          .astype("int64")
          .T
      )
      expected_event_id = {
          "New Segment/": 99999,
          "Stimulus/S253": 253,
          "Stimulus/S255": 255,
          "Event/254": 254,
          "Response/R255": 1255,
          "SyncStatus/Sync On": 99998,
          "Optic/O  1": 2001,
          "Comma,Type/CommaValue,1": 10001,
      }
  
      raw = read_raw_brainvision(tmp_path / "test.vhdr", eog=eog)
  
      # validate annotations
      assert raw.annotations.orig_time == expected_orig_time
      assert_allclose(
          raw.annotations.onset, expected_onset_latency / sfreq
      )
      assert_array_equal(
          raw.annotations.description, expected_annot_description
      )
  
      # validate event extraction
      events, event_id = events_from_annotations(raw)
      assert_array_equal(events, expected_events)
      assert event_id == expected_event_id
  
      # validate that None gives us a sorted list
      expected_none_event_id = {
          desc: idx + 1
          for idx, desc in enumerate(sorted(event_id.keys()))
      }
      events, event_id = events_from_annotations(raw, event_id=None)
      assert event_id == expected_none_event_id
  
      # Add some custom ones, plus a 2-digit one
      s_10 = "Stimulus/S 10"
      raw.annotations.append([1, 2, 3], 10, ["ZZZ", s_10, "YYY"])
      # others starting at 10001 ...
      # we already have "Comma,Type/CommaValue,1" as 10001
      expected_event_id.update(YYY=10002, ZZZ=10003)
      expected_event_id[s_10] = 10
      _, event_id = events_from_annotations(raw)
      assert event_id == expected_event_id
  
      # Concatenating two shouldn't change the resulting event_id
      # (BAD and EDGE should be ignored)
      with pytest.warns(RuntimeWarning, match="expanding outside"):
          raw_concat = concatenate_raws([raw.copy(), raw.copy()])
      _, event_id = events_from_annotations(raw_concat)
      assert event_id == expected_event_id
  
imports: import datetime
  import re
  import shutil
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from mne import concatenate_raws, pick_types, read_annotations
  from mne._fiff.constants import FIFF
  from mne.annotations import events_from_annotations
  from mne.datasets import testing
  from mne.io import read_raw_brainvision, read_raw_fif
  from mne.io.tests.test_raw import _test_raw_reader
  from mne.utils import _stamp_to_dt, object_diff
label_desc: Use image node_id 18 for calling a global function with example usage: test_read_vhdr_annotations_and_events(tmp_path) without return types