code: def test_basics(path=None, nodspath=None):
      ds = Dataset(path).create()
      last_state = ds.repo.get_hexsha()
      # run inside the dataset
      with chpwd(path), swallow_outputs():
          # provoke command failure
          res = ds.run(
              "7i3amhmuch9invalid",
              on_failure="ignore",
              result_renderer=None,
          )
          assert_result_count(res, 1, action="run", status="error")
          run_res = [r for r in res if r["action"] == "run"][0]
          # let's not speculate that the exit code is always 127
          ok_(run_res["run_info"]["exit"] > 0)
          eq_(last_state, ds.repo.get_hexsha())
          # now one that must work
          res = ds.run("cd .> empty", message="TEST")
          assert_repo_status(ds.path)
          assert_result_count(res, 3)
          # TODO 'state' is still untracked!!!
          assert_result_count(
              res,
              1,
              action="add",
              path=op.join(ds.path, "empty"),
              type="file",
          )
          assert_result_count(res, 1, action="save", path=ds.path)
          commit_msg = last_commit_msg(ds.repo)
          ok_(commit_msg.startswith("[DATALAD RUNCMD] TEST"))
          # crude test that we have a record for the PWD
          assert_in('"pwd": "."', commit_msg)
          last_state = ds.repo.get_hexsha()
          # now run a command that will not alter the dataset
          noop_cmd = ":"
          res = ds.run(noop_cmd, message="NOOP_TEST")
          assert_result_count(res, 1, action="save", status="notneeded")
          eq_(last_state, ds.repo.get_hexsha())
          # We can also run the command via a single-item list because this is
          # what the CLI interface passes in for quoted commands.
          res = ds.run([noop_cmd], message="NOOP_TEST")
          assert_result_count(res, 1, action="save", status="notneeded")
  
      # run outside the dataset, should still work but with limitations
      with chpwd(nodspath), swallow_outputs():
          res = ds.run("cd . > empty2", message="TEST")
          assert_result_count(
              res,
              1,
              action="add",
              path=op.join(ds.path, "empty2"),
              type="file",
              status="ok",
          )
          assert_result_count(res, 1, action="save", status="ok")
  
      # running without a command is a noop
      with chpwd(path):
          with swallow_logs(new_level=logging.WARN) as cml:
              ds.run()
              assert_in("No command given", cml.out)
  
      # running without a command is a noop
      with chpwd(path):
          with swallow_logs(new_level=logging.INFO) as cml:
              assert_raises(
                  IncompleteResultsError,
                  ds.run,
                  "7i3amhmuch9invalid",
                  # this is on_failure=stop by default
              )
              # must give recovery hint in Python notation
              assert_in('can save the changes with "Dataset(', cml.out)
  
      with chpwd(path):
          # make sure that an invalid input declaration prevents command
          # execution by default
          assert_raises(
              IncompleteResultsError,
              ds.run,
              "cd .> dummy0",
              inputs=["not-here"],
          )
          ok_(not (ds.pathobj / "dummy0").exists())
          # but the default behavior can be changed
          assert_raises(
              IncompleteResultsError,
              ds.run,
              "cd .> dummy0",
              inputs=["not-here"],
              on_failure="continue",
          )
          # it has stilled failed, but the command got executed nevertheless
          ok_((ds.pathobj / "dummy0").exists())
  
imports: import logging
  import os
  import os.path
  import sys
  from os import mkdir, remove
  from unittest.mock import patch
  from datalad.api import clone, run
  from datalad.cli.main import main
  from datalad.core.local.run import _format_iospecs, _get_substitutions, format_command, run_command
  from datalad.distribution.dataset import Dataset
  from datalad.support.exceptions import CommandError, IncompleteResultsError, NoDatasetFound
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, OBSCURE_FILENAME, assert_false, assert_in, assert_in_results, assert_not_in, assert_not_in_results, assert_raises, assert_repo_status, assert_result_count, assert_status, create_tree, eq_, known_failure_windows, neq_, ok_, ok_exists, ok_file_has_content, patch_config, swallow_logs, swallow_outputs, with_tempfile, with_tree
  from datalad.utils import chpwd, ensure_unicode, on_windows
label_desc: Use image node_id 3 for calling a global function with example usage: test_basics(path, nodspath) without return types