code: def test_run_path_semantics(path=None):
      # Test that we follow path resolution from gh-3435: paths are relative to
      # dataset if a dataset instance is given and relative to the current
      # working directory otherwise.
  
      ds0 = Dataset(op.join(path, "ds0")).create()
      ds0_subdir = op.join(ds0.path, "s0")
      os.mkdir(ds0_subdir)
  
      # Although not useful, we can specify `dataset` as a string that lines up
      # with the one from the current directory.
      with chpwd(ds0_subdir):
          run("cd .> one", dataset="..")
          run("cd .> one", outputs=["one"], dataset=ds0.path)
      ok_exists(op.join(ds0_subdir, "one"))
      assert_repo_status(ds0.path)
  
      # Specify string dataset argument, running from another dataset ...
  
      ds1 = Dataset(op.join(path, "ds1")).create()
      ds1_subdir = op.join(ds1.path, "s1")
      os.mkdir(ds1_subdir)
  
      # ... producing output file in specified dataset
      with chpwd(ds1_subdir):
          run(
              "cd .> {}".format(op.join(ds0.path, "two")),
              dataset=ds0.path,
          )
      ok_exists(op.join(ds0.path, "two"))
      assert_repo_status(ds0.path)
  
      # ... producing output file in specified dataset and passing output file as
      # relative to current directory
      with chpwd(ds1_subdir):
          out = op.join(ds0.path, "three")
          run(
              "cd .> {}".format(out),
              dataset=ds0.path,
              explicit=True,
              outputs=[op.relpath(out, ds1_subdir)],
          )
      ok_exists(op.join(ds0.path, "three"))
      assert_repo_status(ds0.path)
  
      # ... producing output file outside of specified dataset, leaving it
      # untracked in the other dataset
      assert_repo_status(ds1.path)
      with chpwd(ds1_subdir):
          run("cd .> four", dataset=ds0.path)
      assert_repo_status(ds1.path, untracked=[ds1_subdir])
  
      # If we repeat above with an instance instead of the string, the directory
      # for the run is the specified dataset.
      with chpwd(ds1_subdir):
          run("cd .> five", dataset=ds0)
      ok_exists(op.join(ds0.path, "five"))
      assert_repo_status(ds0.path)
  
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 15 for calling a global function with example usage: test_run_path_semantics(path) without return types