code: def _test_anonymize_info(base_info):
      """Test that sensitive information can be anonymized."""
      pytest.raises(TypeError, anonymize_info, "foo")
  
      default_anon_dos = datetime(
          2000, 1, 1, 0, 0, 0, tzinfo=timezone.utc
      )
      default_str = "mne_anonymize"
      default_subject_id = 0
      default_desc = (
          "Anonymized using a time shift"
          + " to preserve age at acquisition"
      )
  
      # Test no error for incomplete info
      info = base_info.copy()
      info.pop("file_id")
      anonymize_info(info)
  
      # Fake some subject data
      meas_date = datetime(2010, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
      with base_info._unlock():
          base_info["meas_date"] = meas_date
          base_info["subject_info"] = dict(
              id=1,
              his_id="foobar",
              last_name="bar",
              first_name="bar",
              birthday=(1987, 4, 8),
              sex=0,
              hand=1,
          )
  
      # generate expected info...
      # first expected result with no options.
      # will move DOS from 2010/1/1 to 2000/1/1 which is 3653 days.
      exp_info = base_info.copy()
      exp_info._unlocked = True
      exp_info["description"] = default_desc
      exp_info["experimenter"] = default_str
      exp_info["proj_name"] = default_str
      exp_info["proj_id"] = np.array([0])
      exp_info["subject_info"]["first_name"] = default_str
      exp_info["subject_info"]["last_name"] = default_str
      exp_info["subject_info"]["id"] = default_subject_id
      exp_info["subject_info"]["his_id"] = str(default_subject_id)
      exp_info["subject_info"]["sex"] = 0
      del exp_info["subject_info"][
          "hand"
      ]  # there's no "unknown" setting
  
      # this bday is 3653 days different. the change in day is due to a
      # different number of leap days between 1987 and 1977 than between
      # 2010 and 2000.
      exp_info["subject_info"]["birthday"] = (1977, 4, 7)
      exp_info["meas_date"] = default_anon_dos
      exp_info._unlocked = False
  
      # make copies
      exp_info_3 = exp_info.copy()
  
      # adjust each expected outcome
      delta_t = timedelta(days=3653)
      for key in ("file_id", "meas_id"):
          value = exp_info.get(key)
          if value is not None:
              assert "msecs" not in value
              tmp = _add_timedelta_to_stamp(
                  (value["secs"], value["usecs"]), -delta_t
              )
              value["secs"] = tmp[0]
              value["usecs"] = tmp[1]
              value["machid"][:] = 0
  
      # exp 2 tests the keep_his option
      exp_info_2 = exp_info.copy()
      with exp_info_2._unlock():
          exp_info_2["subject_info"]["his_id"] = "foobar"
          exp_info_2["subject_info"]["sex"] = 0
          exp_info_2["subject_info"]["hand"] = 1
  
      # exp 3 tests is a supplied daysback
      delta_t_2 = timedelta(days=43)
      with exp_info_3._unlock():
          exp_info_3["subject_info"]["birthday"] = (1987, 2, 24)
          exp_info_3["meas_date"] = meas_date - delta_t_2
      for key in ("file_id", "meas_id"):
          value = exp_info_3.get(key)
          if value is not None:
              assert "msecs" not in value
              tmp = _add_timedelta_to_stamp(
                  (value["secs"], value["usecs"]), -delta_t_2
              )
              value["secs"] = tmp[0]
              value["usecs"] = tmp[1]
              value["machid"][:] = 0
  
      # exp 4 tests is a supplied daysback
      delta_t_3 = timedelta(days=223 + 364 * 500)
  
      new_info = anonymize_info(base_info.copy())
      assert_object_equal(new_info, exp_info)
  
      new_info = anonymize_info(base_info.copy(), keep_his=True)
      assert_object_equal(new_info, exp_info_2)
  
      new_info = anonymize_info(
          base_info.copy(), daysback=delta_t_2.days
      )
      assert_object_equal(new_info, exp_info_3)
  
      with pytest.raises(
          RuntimeError, match="anonymize_info generated"
      ):
          anonymize_info(base_info.copy(), daysback=delta_t_3.days)
      # assert_object_equal(new_info, exp_info_4)
  
      # test with meas_date = None
      with base_info._unlock():
          base_info["meas_date"] = None
      exp_info_3._unlocked = True
      exp_info_3["meas_date"] = None
      exp_info_3["file_id"]["secs"] = DATE_NONE[0]
      exp_info_3["file_id"]["usecs"] = DATE_NONE[1]
      exp_info_3["meas_id"]["secs"] = DATE_NONE[0]
      exp_info_3["meas_id"]["usecs"] = DATE_NONE[1]
      exp_info_3["subject_info"].pop("birthday", None)
      exp_info_3._unlocked = False
  
      if base_info["meas_date"] is None:
          with pytest.warns(RuntimeWarning, match="all information"):
              new_info = anonymize_info(
                  base_info.copy(), daysback=delta_t_2.days
              )
      else:
          new_info = anonymize_info(
              base_info.copy(), daysback=delta_t_2.days
          )
      assert_object_equal(new_info, exp_info_3)
  
      with _record_warnings():  # meas_date is None
          new_info = anonymize_info(base_info.copy())
      assert_object_equal(new_info, exp_info_3)
  
imports: import pickle
  import string
  from datetime import date, datetime, timedelta, timezone
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from scipy import sparse
  from mne import Annotations, Epochs, compute_covariance, make_forward_solution, make_sphere_model, pick_info, pick_types, read_cov, read_epochs, read_events, read_evokeds, read_forward_solution, setup_volume_source_space, write_cov, write_forward_solution
  from mne._fiff import meas_info
  from mne._fiff._digitization import DigPoint, _make_dig_points
  from mne._fiff.constants import FIFF
  from mne._fiff.meas_info import RAW_INFO_FIELDS, Info, MNEBadsList, _add_timedelta_to_stamp, _bad_chans_comp, _dt_to_stamp, _force_update_info, _get_valid_units, _merge_info, _read_extended_ch_info, _stamp_to_dt, anonymize_info, create_info, read_fiducials, read_info, write_fiducials, write_info
  from mne._fiff.proj import Projection
  from mne._fiff.tag import _coil_trans_to_loc, _loc_to_coil_trans
  from mne._fiff.write import DATE_NONE, _generate_meas_id
  from mne.channels import equalize_channels, make_standard_montage, read_polhemus_fastscan
  from mne.datasets import testing
  from mne.event import make_fixed_length_events
  from mne.io import BaseRaw, RawArray, read_raw_ctf, read_raw_fif
  from mne.minimum_norm import apply_inverse, make_inverse_operator, read_inverse_operator, write_inverse_operator
  from mne.transforms import Transform
  from mne.utils import _empty_hash, _record_warnings, assert_object_equal, catch_logging
label_desc: Use image node_id 16 for calling a global function with example usage: _test_anonymize_info(base_info) without return types