code: def test_cached_url(cache_dir=None):
      # patch DATALAD_TESTS_CACHE to not use the actual cache with
      # the test testing that very cache.
      cache_dir = Path(cache_dir)
  
      ds_url = "https://github.com/datalad/testrepo--minimalds"
      name_in_cache = url2filename(ds_url)
      annexed_file = Path("inannex") / "animated.gif"
      annexed_file_key = (
          "MD5E-s144625--4c458c62b7ac8ec8e19c8ff14b2e34ad.gif"
      )
  
      with patch(CACHE_PATCH_STR, new=cache_dir):
  
          @cached_url(url=ds_url)
          def decorated_test1(url):
              # we expect a file-scheme url to a cached version of `ds_url`
              expect_origin_path = cache_dir / name_in_cache
              assert_equal(expect_origin_path.as_uri(), url)
              origin = Dataset(expect_origin_path)
              assert_true(origin.is_installed())
              assert_false(
                  origin.repo.file_has_content(str(annexed_file))
              )
  
          decorated_test1()
  
          @cached_url(url=ds_url, keys=annexed_file_key)
          def decorated_test2(url):
              # we expect a file-scheme url to a "different" cached version of
              # `ds_url`
              expect_origin_path = cache_dir / name_in_cache
              assert_equal(expect_origin_path.as_uri(), url)
              origin = Dataset(expect_origin_path)
              assert_true(origin.is_installed())
              assert_true(
                  origin.repo.file_has_content(str(annexed_file))
              )
  
          decorated_test2()
  
      # disable caching. Note, that in reality DATALAD_TESTS_CACHE is determined
      # on import time of datalad.tests.fixtures based on the config
      # "datalad.tests.cache". We patch the result here, not the config itself.
      with patch(CACHE_PATCH_STR, new=None):
  
          @cached_url(url=ds_url)
          def decorated_test3(url):
              # we expect the original url, since caching is disabled
              assert_equal(url, ds_url)
  
          decorated_test3()
  
file_path: datalad/datalad/tests/test_utils_cached_dataset.py
imports: from unittest.mock import patch
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_cached_dataset import cached_dataset, cached_url, get_cached_dataset, url2filename
  from datalad.tests.utils_pytest import DEFAULT_REMOTE, assert_equal, assert_false, assert_in, assert_is, assert_is_instance, assert_not_equal, assert_not_in, assert_raises, assert_result_count, assert_true, skip_if_no_network, with_tempfile
  from datalad.utils import Path, ensure_list, opj
label_desc: Use image node_id 3 for calling a global function with example usage: test_cached_url(cache_dir) without return types