code: def test_download_url_dataset(toppath=None, topurl=None, path=None):
      # Non-dataset directory.
      file1_fullpath = opj(path, "file1.txt")
      with chpwd(path):
          download_url(topurl + "file1.txt")
          ok_exists(file1_fullpath)
      os.remove(file1_fullpath)
  
      files_tosave = ["file1.txt", "file2.txt"]
      urls_tosave = [topurl + f for f in files_tosave]
  
      ds = Dataset(opj(path, "ds")).create()
  
      # By default, files are saved when called in a dataset.
      ds.download_url(urls_tosave)
      for fname in files_tosave:
          ok_(ds.repo.file_has_content(fname))
  
      eq_(ds.repo.get_urls("file1.txt"), [urls_tosave[0]])
      eq_(ds.repo.get_urls("file2.txt"), [urls_tosave[1]])
  
      ds.download_url([topurl + "file3.txt"], save=False)
      assert_false(ds.repo.file_has_content("file3.txt"))
  
      # Leading paths for target are created if needed.
      subdir_target = opj("l1", "l2", "f")
      ds.download_url([opj(topurl, "file1.txt")], path=subdir_target)
      ok_(ds.repo.file_has_content(subdir_target))
  
      subdir_path = opj(ds.path, "subdir", "")
      os.mkdir(subdir_path)
      with chpwd(subdir_path):
          download_url(topurl + "file4.txt")
          download_url(topurl + "file5.txt", path="five.txt")
          ds.download_url(topurl + "file6.txt")
          download_url(topurl + "file7.txt", dataset=ds.path)
      # download_url calls within a subdirectory save the file there
      ok_(ds.repo.file_has_content(opj("subdir", "file4.txt")))
      ok_(ds.repo.file_has_content(opj("subdir", "five.txt")))
      # ... unless the dataset instance is provided
      ok_(ds.repo.file_has_content("file6.txt"))
      # ... but a string for the dataset (as it would be from the command line)
      # still uses CWD semantics
      ok_(ds.repo.file_has_content(opj("subdir", "file7.txt")))
  
      with chpwd(path):
          # We're in a non-dataset path and pass in a string as the dataset. The
          # path is taken as relative to the current working directory, so we get
          # an error when trying to save it.
          assert_in_results(
              download_url(
                  topurl + "file8.txt",
                  dataset=ds.path,
                  on_failure="ignore",
              ),
              status="error",
              action="status",
          )
      assert_false((ds.pathobj / "file8.txt").exists())
  
file_path: datalad/datalad/local/tests/test_download_url.py
imports: import os
  from os.path import join
  from datalad.api import Dataset, clone, download_url
  from datalad.tests.utils_pytest import DEFAULT_REMOTE, assert_cwd_unchanged, assert_false, assert_in, assert_in_results, assert_message, assert_not_in, assert_result_count, create_tree, eq_, ok_, ok_exists, serve_path_via_http, skip_if_no_network, slow, with_tempfile, with_tree
  from datalad.utils import Path, chpwd
label_desc: Use image node_id 4 for calling a global function with example usage: test_download_url_dataset(toppath, topurl, path) without return types