code: def test_HTTPDownloader_basic(toppath=None, topurl=None):
      furl = "%sfile.dat" % topurl
      tfpath = opj(toppath, "file-downloaded.dat")
      downloader = HTTPDownloader()  # no auth/credentials needed
      download = downloader.download
      download(furl, tfpath)
      ok_file_has_content(tfpath, "abc")
  
      # download() creates leading directories if needed for file targets...
      subdir_tfpath = opj(toppath, "l1", "l2", "file-downloaded.dat")
      download(furl, subdir_tfpath)
      ok_file_has_content(subdir_tfpath, "abc")
  
      # ... and for directory targets.
      subdir_dirtarget = opj(toppath, "d1", "d2", "")
      download(furl, subdir_dirtarget)
      ok_file_has_content(opj(subdir_dirtarget, "file.dat"), "abc")
  
      # see if fetch works correctly
      assert_equal(downloader.fetch(furl), "abc")
  
      # By default should not overwrite the file
      assert_raises(DownloadError, download, furl, tfpath)
      # but be able to redownload whenever overwrite==True
      downloaded_path = download(furl, tfpath, overwrite=True)
      assert_equal(downloaded_path, tfpath)
      ok_file_has_content(tfpath, "abc")
  
      # Fail with an informative message if we're downloading into a directory
      # and the file name can't be determined from the URL.
      with assert_raises(DownloadError) as cm:
          download(topurl, toppath)
      assert_in("File name could not be determined", str(cm.value))
  
      # Some errors handling
      # XXX obscure mocking since impossible to mock write alone
      # and it still results in some warning being spit out
      # Note: we need to avoid mocking opening of the lock file!
      with swallow_logs(), patch.object(
          builtins,
          "open",
          fake_open(write_=_raise_IOError, skip_regex=r".*\.lck$"),
      ):
          assert_raises(
              DownloadError, download, furl, tfpath, overwrite=True
          )
  
      # incomplete download scenario - should have 3 tries
      def _fail_verify_download(try_to_fail):
          try_ = [0]
          _orig_verify_download = BaseDownloader._verify_download
  
          def _verify_download(self, *args, **kwargs):
              try_[0] += 1
              if try_[0] >= try_to_fail:
                  return _orig_verify_download(self, *args, **kwargs)
              raise IncompleteDownloadError()
  
          return _verify_download
  
      with patch.object(
          BaseDownloader, "_verify_download", _fail_verify_download(6)
      ), swallow_logs():
          # how was before the "fix":
          # assert_raises(DownloadError, downloader.fetch, furl)
          # assert_raises(DownloadError, downloader.fetch, furl)
          # now should download just fine
          assert_equal(downloader.fetch(furl), "abc")
      # but should fail if keeps failing all 5 times and then on 11th should raise DownloadError
      with patch.object(
          BaseDownloader, "_verify_download", _fail_verify_download(7)
      ), swallow_logs():
          assert_raises(DownloadError, downloader.fetch, furl)
  
imports: import builtins
  import os
  import re
  import time
  from calendar import timegm
  from os.path import join
  from datalad.downloaders.tests.utils import get_test_providers
  from datalad.support.network import download_url, get_url_straight_filename
  from datalad.utils import ensure_unicode
  from ...support.exceptions import AccessFailedError
  from ..base import BaseDownloader, DownloadError, IncompleteDownloadError, NoneAuthenticator
  from ..credentials import LORIS_Token, Token, UserPassword
  from ..http import HTMLFormAuthenticator, HTTPBaseAuthenticator, HTTPBearerTokenAuthenticator, HTTPDownloader, process_www_authenticate
  from unittest.mock import patch
  from ...support.exceptions import AccessDeniedError, AnonymousAccessDeniedError
  from ...support.network import get_url_disposition_filename
  from ...support.status import FileStatus
  from ...tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_greater, assert_in, assert_not_in, assert_raises, known_failure_githubci_win, ok_file_has_content, serve_path_via_http, skip_if, skip_if_no_network, swallow_logs, swallow_outputs, use_cassette, with_fake_cookies_db, with_memory_keyring, with_tempfile, with_testsui, with_tree, without_http_proxy
  from ...utils import read_file
label_desc: Use image node_id 5 for calling a global function with example usage: test_HTTPDownloader_basic(toppath, topurl) and returns: _verify_download, _orig_verify_download