code: def test_downloads(tmp_path, monkeypatch, capsys):
      """Test dataset URL and version handling."""
      # Try actually downloading a dataset
      kwargs = dict(path=str(tmp_path), verbose=True)
      # XXX we shouldn't need to disable capsys here, but there's a pytest bug
      # that we're hitting (https://github.com/pytest-dev/pytest/issues/5997)
      # now that we use pooch
      with capsys.disabled():
          with pytest.raises(
              RuntimeError, match="Do not download .* in tests"
          ):
              path = datasets._fake.data_path(
                  update_path=False, **kwargs
              )
          monkeypatch.setattr(
              datasets.utils,
              "_MODULES_TO_ENSURE_DOWNLOAD_IS_FALSE_IN_TESTS",
              (),
          )
          path = datasets._fake.data_path(update_path=False, **kwargs)
      assert op.isdir(path)
      assert op.isfile(op.join(path, "bar"))
      assert not datasets.has_dataset("fake")  # not in the desired path
      assert datasets._fake.get_version() is None
      assert datasets.utils._get_version("fake") is None
      monkeypatch.setenv("_MNE_FAKE_HOME_DIR", str(tmp_path))
      with pytest.warns(RuntimeWarning, match="non-standard config"):
          new_path = datasets._fake.data_path(
              update_path=True, **kwargs
          )
      assert path == new_path
      out, _ = capsys.readouterr()
      assert "Downloading" not in out
      # No version: shown as existing but unknown version
      assert datasets.has_dataset("fake")
      # XXX logic bug, should be "unknown"
      assert datasets._fake.get_version() == "0.0"
      # With a version but no required one: shown as existing and gives version
      fname = tmp_path / "foo" / "version.txt"
      with open(fname, "w") as fid:
          fid.write("0.1")
      assert datasets.has_dataset("fake")
      assert datasets._fake.get_version() == "0.1"
      datasets._fake.data_path(download=False, **kwargs)
      out, _ = capsys.readouterr()
      assert "out of date" not in out
      # With the required version: shown as existing with the required version
      monkeypatch.setattr(datasets._fetch, "_FAKE_VERSION", "0.1")
      assert datasets.has_dataset("fake")
      assert datasets._fake.get_version() == "0.1"
      datasets._fake.data_path(download=False, **kwargs)
      out, _ = capsys.readouterr()
      assert "out of date" not in out
      monkeypatch.setattr(datasets._fetch, "_FAKE_VERSION", "0.2")
      # With an older version:
      # 1. Marked as not actually being present
      assert not datasets.has_dataset("fake")
      # 2. Will try to update when `data_path` gets called, with logged message
      want_msg = "Correctly trying to download newer version"
  
      def _error_download(self, fname, downloader, processor):
          url = self.get_url(fname)
          full_path = self.abspath / fname
          assert "foo.tgz" in url
          assert str(tmp_path) in str(full_path)
          raise RuntimeError(want_msg)
  
      monkeypatch.setattr(pooch.Pooch, "fetch", _error_download)
      with pytest.raises(RuntimeError, match=want_msg):
          datasets._fake.data_path(**kwargs)
      out, _ = capsys.readouterr()
      assert re.match(
          r".* 0\.1 .*out of date.* 0\.2.*", out, re.MULTILINE
      ), out
  
      # Hash mismatch suggestion
      # https://mne.discourse.group/t/fsaverage-hash-value-mismatch/4663/3
      want_msg = "MD5 hash of downloaded file (MNE-sample-data-processed.tar.gz) does not match the known hash: expected md5:e8f30c4516abdc12a0c08e6bae57409c but got a9dfc7e8843fd7f8a928901e12fb3d25. Deleted download for safety. The downloaded file may have been corrupted or the known hash may be outdated."  # noqa: E501
  
      def _error_download_2(self, fname, downloader, processor):
          url = self.get_url(fname)
          full_path = self.abspath / fname
          assert "foo.tgz" in url
          assert str(tmp_path) in str(full_path)
          raise ValueError(want_msg)
  
      shutil.rmtree(tmp_path / "foo")
      monkeypatch.setattr(pooch.Pooch, "fetch", _error_download_2)
      with pytest.raises(
          ValueError, match=".*known hash.*force_update=True.*"
      ):
          datasets._fake.data_path(
              download=True, force_update=True, **kwargs
          )
  
imports: import os
  import re
  import shutil
  import zipfile
  from functools import partial
  from os import path
  import pooch
  import pytest
  from mne import datasets, read_labels_from_annot, write_labels_to_annot
  from mne.datasets import fetch_dataset, fetch_infant_template, fetch_phantom, testing
  from mne.datasets._fsaverage.base import _set_montage_coreg_path
  from mne.datasets._infant import base
  from mne.datasets._phantom import base
  from mne.datasets.utils import _manifest_check_download
  from mne.utils import ArgvSetter, _pl, catch_logging, get_subjects_dir, hashfunc, requires_good_network, use_log_level
label_desc: Use image node_id 2 for calling a global function with example usage: test_downloads(tmp_path, monkeypatch, capsys) without return types