code: def test_invalid_date(tmp_path):
      """Test handling of invalid date in EDF header."""
      with open(edf_path, "rb") as f:  # read valid test file
          edf = bytearray(f.read())
  
      # original date in header is 29.04.14 (2014-04-29) at pos 168:176
      # but we also use Startdate if available,
      # which starts at byte 88 and is b'Startdate 29-APR-2014 X X X'
      # create invalid date 29.02.14 (2014 is not a leap year)
  
      # one wrong: no warning
      edf[101:104] = b"FEB"
      assert edf[172] == ord("4")
      fname = tmp_path / "temp.edf"
      with open(fname, "wb") as f:
          f.write(edf)
      read_raw_edf(fname)
  
      # other wrong: no warning
      edf[101:104] = b"APR"
      edf[172] = ord("2")
      with open(fname, "wb") as f:
          f.write(edf)
      read_raw_edf(fname)
  
      # both wrong: warning
      edf[101:104] = b"FEB"
      edf[172] = ord("2")
      with open(fname, "wb") as f:
          f.write(edf)
      with pytest.warns(RuntimeWarning, match="Invalid date"):
          read_raw_edf(fname)
  
      # another invalid date 29.00.14 (0 is not a month)
      assert edf[101:104] == b"FEB"
      edf[172] = ord("0")
      with open(fname, "wb") as f:
          f.write(edf)
      with pytest.warns(RuntimeWarning, match="Invalid date"):
          read_raw_edf(fname)
  
imports: import datetime
  from contextlib import nullcontext
  from functools import partial
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy.io import loadmat
  from mne import Annotations, pick_types
  from mne._fiff.pick import channel_indices_by_type, get_channel_type_constants
  from mne.annotations import _ndarray_ch_names, events_from_annotations, read_annotations
  from mne.datasets import testing
  from mne.io import edf, read_raw_bdf, read_raw_edf, read_raw_fif, read_raw_gdf
  from mne.io.edf.edf import _edf_str, _parse_prefilter_string, _read_annotations_edf, _read_ch, _read_edf_header, _read_header
  from mne.io.tests.test_raw import _test_raw_reader
  from mne.tests.test_annotations import _assert_annotations_equal
label_desc: Use image node_id 27 for calling a global function with example usage: test_invalid_date(tmp_path) without return types