code: def test_annotate_breaks(meas_date):
      """Test annotate_breaks."""
      raw = read_raw_fif(raw_fname, allow_maxshield="yes")
      if meas_date is None:
          raw.set_meas_date(None)
  
      annots = Annotations(
          onset=[12, 15, 16, 20, 21],
          duration=[1, 1, 1, 2, 0.5],
          description=["test"],
          orig_time=raw.info["meas_date"],
      )
  
      if raw.info["meas_date"] is None:
          annots.onset -= raw.first_time
  
      raw.set_annotations(annots)
  
      min_break_duration = 0.5
      t_start_after_previous = 0.1
      t_stop_before_next = 0.1
  
      expected_onsets = np.array(
          [
              raw.first_time,
              13 + t_start_after_previous,
              17 + t_start_after_previous,
              22 + t_start_after_previous,
          ]
      )
  
      if raw.info["meas_date"] is None:
          expected_onsets -= raw.first_time
  
      expected_durations = np.array(
          [
              12 - raw.first_time - t_stop_before_next,
              15 - 13 - t_start_after_previous - t_stop_before_next,
              20 - 17 - t_start_after_previous - t_stop_before_next,
              raw._last_time - 22 - t_start_after_previous,
          ]
      )
  
      break_annots = annotate_break(
          raw=raw,
          min_break_duration=min_break_duration,
          t_start_after_previous=t_start_after_previous,
          t_stop_before_next=t_stop_before_next,
      )
  
      assert break_annots.orig_time == raw.info["meas_date"]
      assert_allclose(break_annots.onset, expected_onsets)
      assert_allclose(break_annots.duration, expected_durations)
      assert all(
          description == "BAD_break"
          for description in break_annots.description
      )
  
      # try setting the annotations, this should not omit anything
      raw.set_annotations(break_annots)
      current_annotations = raw.annotations
      if raw.info["meas_date"] is None:
          current_annotations.onset -= raw.first_time
      raw.set_annotations(current_annotations + break_annots)
  
      # reset before next test
      raw.set_annotations(annots)
  
      # `ignore` parameter should be respected
      raw.annotations.description[0] = "BAD_"
      break_annots = annotate_break(
          raw=raw,
          min_break_duration=min_break_duration,
          t_start_after_previous=t_start_after_previous,
          t_stop_before_next=t_stop_before_next,
      )
  
      assert_allclose(
          break_annots.onset, expected_onsets[[True, False, True, True]]
      )
      assert_allclose(
          break_annots.duration,
          [15 - raw.first_time - t_stop_before_next]
          + list(expected_durations[2:]),
      )
  
      # try setting the annotations, this should not omit anything
      raw.set_annotations(break_annots)
      current_annotations = raw.annotations
      if raw.info["meas_date"] is None:
          current_annotations.onset -= raw.first_time
      raw.set_annotations(current_annotations + break_annots)
  
      # Restore annotations for next test
      raw.set_annotations(annots)
      raw.annotations.description[0] = "test"
  
      # Test with events
      events, _ = events_from_annotations(raw=raw)
      raw.set_annotations(None)
  
      expected_onsets = np.array(
          [
              raw.first_time,
              12 + t_start_after_previous,
              15 + t_start_after_previous,
              16 + t_start_after_previous,
              20 + t_start_after_previous,
              21 + t_start_after_previous,
          ]
      )
  
      expected_durations = np.array(
          [
              12 - raw.first_time - t_stop_before_next,
              15 - 12 - t_start_after_previous - t_stop_before_next,
              16 - 15 - t_start_after_previous - t_stop_before_next,
              20 - 16 - t_start_after_previous - t_stop_before_next,
              21 - 20 - t_start_after_previous - t_stop_before_next,
              raw._last_time - 21 - t_start_after_previous,
          ]
      )
  
      break_annots = annotate_break(
          raw=raw,
          events=events,
          min_break_duration=min_break_duration,
          t_start_after_previous=t_start_after_previous,
          t_stop_before_next=t_stop_before_next,
      )
  
      if raw.info["meas_date"] is None:
          expected_onsets -= raw.first_time
  
      assert_allclose(break_annots.onset, expected_onsets)
      assert_allclose(break_annots.duration, expected_durations)
  
      # try setting the annotations, this should not omit anything
      raw.set_annotations(break_annots)
      current_annotations = raw.annotations
      if raw.info["meas_date"] is None:
          current_annotations.onset -= raw.first_time
      raw.set_annotations(current_annotations + break_annots)
  
      # reset before next test
      raw.set_annotations(annots)
  
      # Not finding any break periods
      break_annots = annotate_break(
          raw=raw,
          events=events,
          min_break_duration=1000,
      )
  
      assert len(break_annots) == 0
  
      # Implausible parameters (would produce break annot of duration < 0)
      with pytest.raises(ValueError, match="must be greater than 0"):
          annotate_break(
              raw=raw,
              min_break_duration=5,
              t_start_after_previous=5,
              t_stop_before_next=5,
          )
  
      # Empty events array
      with pytest.raises(
          ValueError, match="events array must not be empty"
      ):
          annotate_break(raw=raw, events=np.array([]))
  
      # Invalid `ignore` value
      with pytest.raises(TypeError, match="must be an instance of str"):
          annotate_break(raw=raw, ignore=("foo", 1))
  
      # No annotations to work with
      raw.set_annotations(None)
      with pytest.raises(
          ValueError, match="Could not find.*annotations"
      ):
          annotate_break(raw=raw)
  
file_path: mne-python/mne/preprocessing/tests/test_artifact_detection.py
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from mne import Annotations, events_from_annotations
  from mne.chpi import read_head_pos
  from mne.datasets import testing
  from mne.io import read_raw_fif
  from mne.preprocessing import annotate_break, annotate_movement, annotate_muscle_zscore, compute_average_dev_head_t
  from mne.tests.test_annotations import _assert_annotations_equal
label_desc: Use image node_id 4 for calling a global function with example usage: test_annotate_breaks(meas_date) without return types