code: def _test_initremote_basic(url, io, store, ds_path, link):
      ds_path = Path(ds_path)
      store = Path(store)
      link = Path(link)
      ds = Dataset(ds_path).create()
      populate_dataset(ds)
  
      init_opts = common_init_opts + ["url={}".format(url)]
  
      # fails on non-existing storage location
      assert_raises(
          CommandError,
          ds.repo.init_remote,
          "ria-remote",
          options=init_opts,
      )
      # Doesn't actually create a remote if it fails
      assert_not_in(
          "ria-remote",
          [
              cfg["name"]
              for uuid, cfg in ds.repo.get_special_remotes().items()
          ],
      )
  
      # fails on non-RIA URL
      assert_raises(
          CommandError,
          ds.repo.init_remote,
          "ria-remote",
          options=common_init_opts + ["url={}".format(store.as_uri())],
      )
      # Doesn't actually create a remote if it fails
      assert_not_in(
          "ria-remote",
          [
              cfg["name"]
              for uuid, cfg in ds.repo.get_special_remotes().items()
          ],
      )
  
      # set up store:
      create_store(io, store, "1")
      # still fails, since ds isn't setup in the store
      assert_raises(
          CommandError,
          ds.repo.init_remote,
          "ria-remote",
          options=init_opts,
      )
      # Doesn't actually create a remote if it fails
      assert_not_in(
          "ria-remote",
          [
              cfg["name"]
              for uuid, cfg in ds.repo.get_special_remotes().items()
          ],
      )
      # set up the dataset as well
      create_ds_in_store(io, store, ds.id, "2", "1")
      # now should work
      ds.repo.init_remote("ria-remote", options=init_opts)
      assert_in(
          "ria-remote",
          [
              cfg["name"]
              for uuid, cfg in ds.repo.get_special_remotes().items()
          ],
      )
      assert_repo_status(ds.path)
      # git-annex:remote.log should have:
      #   - url
      #   - common_init_opts
      #   - archive_id (which equals ds id)
      remote_log = ds.repo.call_git(
          ["cat-file", "blob", "git-annex:remote.log"], read_only=True
      )
      assert_in("url={}".format(url), remote_log)
      [assert_in(c, remote_log) for c in common_init_opts]
      assert_in("archive-id={}".format(ds.id), remote_log)
  
      # re-configure with invalid URL should fail:
      assert_raises(
          CommandError,
          ds.repo.call_annex,
          ["enableremote", "ria-remote"]
          + common_init_opts
          + ["url=ria+file:///non-existing"],
      )
      # but re-configure with valid URL should work
      if has_symlink_capability():
          link.symlink_to(store)
          new_url = "ria+{}".format(link.as_uri())
          ds.repo.call_annex(
              ["enableremote", "ria-remote"]
              + common_init_opts
              + ["url={}".format(new_url)]
          )
          # git-annex:remote.log should have:
          #   - url
          #   - common_init_opts
          #   - archive_id (which equals ds id)
          remote_log = ds.repo.call_git(
              ["cat-file", "blob", "git-annex:remote.log"],
              read_only=True,
          )
          assert_in("url={}".format(new_url), remote_log)
          [assert_in(c, remote_log) for c in common_init_opts]
          assert_in("archive-id={}".format(ds.id), remote_log)
  
      # we can deal with --sameas, which leads to a special remote not having a
      # 'name' property, but only a 'sameas-name'. See gh-4259
      try:
          ds.repo.init_remote(
              "ora2", options=init_opts + ["--sameas", "ria-remote"]
          )
      except CommandError as e:
          if "Invalid option `--sameas" in e.stderr:
              # annex too old - doesn't know --sameas
              pass
          else:
              raise
  
imports: import logging
  import stat
  from datalad.api import Dataset, clone, create_sibling_ria
  from datalad.cmd import NoCapture
  from datalad.customremotes.ria_utils import create_ds_in_store, create_store, get_layout_locations
  from datalad.distributed.ora_remote import LocalIO, SSHRemoteIO, _sanitize_key
  from datalad.distributed.tests.ria_utils import common_init_opts, get_all_files, populate_dataset
  from datalad.support.exceptions import CommandError, IncompleteResultsError
  from datalad.tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_in, assert_not_in, assert_raises, assert_repo_status, assert_status, assert_true, has_symlink_capability, known_failure_windows, serve_path_via_http, skip_if_adjusted_branch, skip_if_no_network, skip_if_root, skip_ssh, skip_wo_symlink_capability, slow, swallow_logs, turtle, with_tempfile
  from datalad.utils import Path
label_desc: Use image node_id 1 for calling a global function with example usage: _test_initremote_basic(url, io, store, ds_path, link) without return types