code: def test_subdatasets(path=None):
      # from scratch
      ds = Dataset(path)
      assert_false(ds.is_installed())
      assert_raises(ValueError, ds.subdatasets)
      ds = ds.create()
      assert_true(ds.is_installed())
      eq_(ds.subdatasets(), [])
      # create some file and commit it
      open(os.path.join(ds.path, "test"), "w").write("some")
      ds.save(path="test", message="Hello!", version_tag=1)
      assert_true(ds.is_installed())
      # Assuming that tmp location was not under a super-dataset
      eq_(ds.get_superdataset(), None)
      eq_(ds.get_superdataset(topmost=True), ds)
  
      # add itself as a subdataset (crazy, isn't it?)
      subds = ds.install(
          "subds",
          source=path,
          result_xfm="datasets",
          return_type="item-or-list",
      )
      assert_true(subds.is_installed())
      eq_(subds.get_superdataset(), ds)
      eq_(subds.get_superdataset(topmost=True), ds)
  
      subdss = ds.subdatasets()
      eq_(len(subdss), 1)
      eq_(subds.path, ds.subdatasets(result_xfm="paths")[0])
      eq_(subdss, ds.subdatasets(recursive=True))
      eq_(subdss, ds.subdatasets(state="present"))
      ds.save(message="with subds", version_tag=2)
      ds.recall_state(1)
      assert_true(ds.is_installed())
      eq_(ds.subdatasets(), [])
  
      # very nested subdataset to test topmost
      subsubds = subds.install(
          _path_("d1/subds"),
          source=path,
          result_xfm="datasets",
          return_type="item-or-list",
      )
      assert_true(subsubds.is_installed())
      eq_(subsubds.get_superdataset(), subds)
      # by default, it will only report a subperdataset that actually
      # has the queries dataset as a registered true subdataset
      eq_(subsubds.get_superdataset(topmost=True), subds)
      # by we can also ask for a dataset that is merely above
      eq_(
          subsubds.get_superdataset(
              topmost=True, registered_only=False
          ),
          ds,
      )
  
      # verify that '^' alias would work
      with chpwd(subsubds.path):
          dstop = Dataset("^")
          eq_(dstop, subds)
          # and while in the dataset we still can resolve into central one
          dscentral = Dataset("///")
          eq_(
              dscentral.path,
              dl_cfg.obtain("datalad.locations.default-dataset"),
          )
  
      with chpwd(ds.path):
          dstop = Dataset("^")
          eq_(dstop, ds)
  
      # TODO actual submodule checkout is still there
  
      # Test ^. (the dataset for curdir) shortcut
      # At the top should point to the top
      with chpwd(ds.path):
          dstop = Dataset("^.")
          eq_(dstop, ds)
  
      # and still does within subdir
      os.mkdir(opj(ds.path, "subdir"))
      with chpwd(opj(ds.path, "subdir")):
          dstop = Dataset("^.")
          eq_(dstop, ds)
  
      # within submodule will point to submodule
      with chpwd(subsubds.path):
          dstop = Dataset("^.")
          eq_(dstop, subsubds)
  
imports: import os
  import os.path
  from os.path import abspath
  from os.path import join
  from os.path import lexists, relpath
  import pytest
  import datalad.utils
  from datalad import cfg
  from datalad.api import clone, create, get
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import NoDatasetFound
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import OBSCURE_FILENAME, SkipTest, assert_equal, assert_false, assert_is, assert_is_instance, assert_is_none, assert_is_not, assert_is_not_none, assert_not_equal, assert_not_in, assert_raises, assert_repo_status, assert_result_count, assert_true, eq_, known_failure_windows, ok_, swallow_logs, with_tempfile
  from datalad.utils import Path, _path_, chpwd, on_windows, rmtree
  from ..dataset import Dataset, EnsureDataset, require_dataset, resolve_path
label_desc: Use image node_id 5 for calling a global function with example usage: test_subdatasets(path) without return types