code: def test_copy_file(workdir=None, webdir=None, weburl=None):
      workdir = Path(workdir)
      webdir = Path(webdir)
      src_ds = Dataset(workdir / "src").create()
      # put a file into the dataset by URL and drop it again
      src_ds.download_url(
          "/".join((weburl, "webfile1")), path="myfile1.txt"
      )
      src_ds.download_url(
          "/".join((weburl, "webfile2")),
          path=opj("subdir", "myfile2.txt"),
      )
      ok_file_has_content(src_ds.pathobj / "myfile1.txt", "123")
      # now create a fresh dataset
      dest_ds = Dataset(workdir / "dest").create()
      if (
          dest_ds.repo._check_version_kludges(
              "fromkey-supports-unlocked"
          )
          or not dest_ds.repo.is_managed_branch()
      ):
          # unless we have a target ds on a cripples FS (where `annex fromkey`
          # doesn't work until after 8.20210428), we can even drop the file
          # content in the source repo
          src_ds.drop("myfile1.txt", reckless="kill")
          nok_(src_ds.repo.file_has_content("myfile1.txt"))
      # copy the file from the source dataset into it.
      # it must copy enough info to actually put datalad into the position
      # to obtain the file content from the original URL
      dest_ds.copy_file(src_ds.pathobj / "myfile1.txt")
      dest_ds.get("myfile1.txt")
      ok_file_has_content(dest_ds.pathobj / "myfile1.txt", "123")
      # purposefully pollute the employed tmp folder to check that we do not trip
      # over such a condition
      tmploc = (
          dest_ds.pathobj / ".git" / "tmp" / "datalad-copy" / "some"
      )
      tmploc.parent.mkdir(parents=True)
      tmploc.touch()
      # copy again, but to different target file name
      # (source+dest pair now)
      dest_ds.copy_file(
          [
              src_ds.pathobj / "myfile1.txt",
              dest_ds.pathobj / "renamed.txt",
          ]
      )
      ok_file_has_content(dest_ds.pathobj / "renamed.txt", "123")
      # copying more than one at once
      dest_ds.copy_file(
          [
              src_ds.pathobj / "myfile1.txt",
              src_ds.pathobj / "subdir" / "myfile2.txt",
              dest_ds.pathobj,
          ]
      )
      # copy directly from a non-dataset location
      dest_ds.copy_file(webdir / "webfile1")
  
      # copy from annex dataset into gitrepo
      git_ds = Dataset(workdir / "git").create(annex=False)
      git_ds.copy_file(src_ds.pathobj / "subdir" / "myfile2.txt")
  
file_path: datalad/datalad/local/tests/test_copy_file.py
imports: from os.path import join
  from datalad.api import copy_file
  from datalad.consts import DATALAD_SPECIAL_REMOTE
  from datalad.distribution.dataset import Dataset
  from datalad.tests.utils_pytest import assert_in_results, assert_raises, assert_repo_status, assert_status, chpwd, eq_, nok_, ok_, ok_file_has_content, serve_path_via_http, slow, with_tempfile, with_tree
  from datalad.utils import Path
label_desc: Use image node_id 1 for calling a global function with example usage: test_copy_file(workdir, webdir, weburl) without return types