code: def test_add_version_to_url():
      base_url = "http://ex.com/f.txt"
      base_url_query = "http://ex.com/f.txt?k=v"
      for replace in True, False:
          eq_(
              add_version_to_url(
                  URL(base_url), "new.id", replace=replace
              ),
              base_url + "?versionId=new.id",
          )
  
          eq_(
              add_version_to_url(
                  URL(base_url_query), "new.id", replace=replace
              ),
              base_url_query + "&versionId=new.id",
          )
  
          expected = "new.id" if replace else "orig.id"
          eq_(
              add_version_to_url(
                  URL(base_url + "?versionId=orig.id"),
                  "new.id",
                  replace=replace,
              ),
              base_url + "?versionId=" + expected,
          )
  
          eq_(
              add_version_to_url(
                  URL(base_url_query + "&versionId=orig.id"),
                  "new.id",
                  replace=replace,
              ),
              base_url_query + "&versionId=" + expected,
          )
  
imports: from datalad.downloaders.tests.utils import get_test_providers
  from datalad.support.network import URL
  from datalad.support.s3 import add_version_to_url, get_versioned_url
  from datalad.tests.utils_pytest import assert_raises, eq_, ok_startswith, skip_if_no_network, use_cassette
label_desc: Use image node_id 1 for calling a global function with example usage: test_add_version_to_url() without return types