code: def check_basic_resilience(populator, path=None):
      ds = populator(path)
      ds.save()
      kwargs = dict(recursive=True)
  
      res_external = ds.foreach_dataset(
          [
              sys.executable,
              "-c",
              'from datalad.distribution.dataset import Dataset; ds=Dataset("."); print(ds.path)',
          ],
          **kwargs,
      )
      res_python = ds.foreach_dataset(
          "ds.path", cmd_type="eval", **kwargs
      )
  
      # a sample python function to pass to foreach
      def get_path(ds, **kwargs):
          return ds.path
  
      res_python_func = ds.foreach_dataset(get_path, **kwargs)
  
      assert_status("ok", res_external)
      assert_status("ok", res_python)
  
      # consistency checks
      eq_(len(res_external), len(res_python))
      eq_(len(res_external), len(res_python_func))
      eq_(
          _without_command(res_python),
          _without_command(res_python_func),
      )
  
      # Test correct order for bottom-up vs top-down
      topdown_dss = [ds.path] + ds.subdatasets(
          result_xfm="paths", bottomup=False, **kwargs
      )
      eq_(topdown_dss, [_["result"] for _ in res_python])
  
      bottomup_dss = ds.subdatasets(
          result_xfm="paths", recursive=True, bottomup=True
      ) + [ds.path]
      eq_(
          bottomup_dss,
          [
              _["result"]
              for _ in ds.foreach_dataset(
                  "ds.path", bottomup=True, cmd_type="eval", **kwargs
              )
          ],
      )
  
      # more radical example - cleanup
      # Make all datasets dirty
      for d in bottomup_dss:
          (Path(d) / "dirt").write_text("")
      res_clean = ds.foreach_dataset(
          ["git", "clean", "-f"], jobs=10, **kwargs
      )
      assert_status("ok", res_clean)
      # no dirt should be left
      for d in bottomup_dss:
          assert_false((Path(d) / "dirt").exists())
  
      if populator is get_deeply_nested_structure:
          ok_clean_git(
              ds.path, index_modified=[ds.pathobj / "subds_modified"]
          )
      else:
          ok_clean_git(ds.path)
  
file_path: datalad/datalad/local/tests/test_foreach_dataset.py
imports: import os.path
  import sys
  from pathlib import Path
  import pytest
  from datalad.api import create
  from datalad.distribution.dataset import Dataset
  from datalad.tests.utils_pytest import assert_false, assert_greater, assert_in, assert_not_in, assert_status, eq_, get_deeply_nested_structure, ok_clean_git, swallow_outputs, with_tempfile
label_desc: Use image node_id 2 for calling a global function with example usage: check_basic_resilience(populator, path) and returns: ds