code: def test_source_candidate_subdataset(
      store1=None,
      store2=None,
      intermediate=None,
      super=None,
      clone=None,
  ):
      # This tests the scenario of gh-6159.
      # However, the actual point is to test that `get` does not overwrite a
      # source candidate config in subdatasets, if they already have such a
      # config. This could come from any postclone_cfg routine, but the only one
      # actually doing this ATM is postclone_cfg_ria.
  
      ds = Dataset(intermediate).create(force=True)
      ds.create("sub1", force=True)
      ds.create("sub2", force=True)
      ds.save(recursive=True)
      ria_url_1 = "ria+" + get_local_file_url(
          store1, compatibility="git"
      )
      ds.create_sibling_ria(
          ria_url_1, "firststore", recursive=True, new_store_ok=True
      )
      ds.push(".", to="firststore", recursive=True)
      superds = Dataset(super).create()
      superds.clone(source=ria_url_1 + "#" + ds.id, path="intermediate")
      ria_url_2 = "ria+" + get_local_file_url(
          store2, compatibility="git"
      )
      superds.create_sibling_ria(
          ria_url_2, "secondstore", new_store_ok=True
      )
      superds.push(".", to="secondstore")
  
      cloneds = install(clone, source=ria_url_2 + "#" + superds.id)
  
      # This would fail if source candidates weren't right, since cloneds only
      # knows the second store so far (which doesn't have the subdatasets).
      cloneds.get("intermediate", recursive=True)
  
imports: from os import curdir
  from os.path import basename
  from os.path import join
  from unittest.mock import patch
  import pytest
  from datalad.api import clone, create, get, install
  from datalad.distribution.get import _get_flexible_source_candidates_for_submodule
  from datalad.interface.results import only_matching_paths
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import InsufficientArgumentsError, RemoteNotAvailableError
  from datalad.support.network import get_local_file_url
  from datalad.tests.utils_testdatasets import _make_dataset_hierarchy, _mk_submodule_annex
  from datalad.tests.utils_pytest import create_tree, assert_false, assert_raises, assert_in, assert_status, assert_in_results, assert_not_in_results, assert_repo_status, assert_result_count, assert_message, DEFAULT_REMOTE, eq_, known_failure_windows, known_failure_githubci_win, ok_, serve_path_via_http, skip_if_adjusted_branch, skip_ssh, skip_if_on_windows, slow, with_tempfile, with_tree
  from datalad.utils import Path, chpwd, rmtree, with_pathsep
  from ..dataset import Dataset
label_desc: Use image node_id 18 for calling a global function with example usage: test_source_candidate_subdataset(store1, store2, intermediate, super, clone) without return types