code: def check_datasets_order(res, order="bottom-up"):
      """Check that all type=dataset records not violating the expected order
  
      it is somewhat weak test, i.e. records could be produced so we
      do not detect that order is violated, e.g. a/b c/d would satisfy
      either although they might be neither depth nor breadth wise.  But
      this test would allow to catch obvious violations like a, a/b, a
      """
      prev = None
      for r in res:
          if r.get("type") != "dataset":
              continue
          if prev and r["path"] != prev:
              if order == "bottom-up":
                  assert_false(path_startswith(r["path"], prev))
              elif order == "top-down":
                  assert_false(path_startswith(prev, r["path"]))
              else:
                  raise ValueError(order)
          prev = r["path"]
  
imports: import logging
  import os
  import pytest
  from datalad.core.distributed.clone import Clone
  from datalad.core.distributed.push import Push
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import IncompleteResultsError, InsufficientArgumentsError
  from datalad.support.external_versions import external_versions
  from datalad.support.gitrepo import GitRepo
  from datalad.support.network import get_local_file_url
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, SkipTest, assert_false, assert_in, assert_in_results, assert_not_in, assert_not_in_results, assert_raises, assert_repo_status, assert_result_count, assert_status, eq_, known_failure_githubci_osx, known_failure_githubci_win, neq_, ok_, ok_file_has_content, serve_path_via_http, skip_if_adjusted_branch, skip_if_on_windows, skip_ssh, slow, swallow_logs, with_tempfile, with_tree
  from datalad.utils import Path, chpwd, path_startswith, swallow_outputs
label_desc: Use image node_id 5 for calling a global function with example usage: check_datasets_order(res, order) without return types