code: def test_fetch_inventory_redirection(
      _read_from_url, InventoryFile, app, status, warning
  ):  # NoQA: PT019
      intersphinx_setup(app)
      _read_from_url().readline.return_value = (
          b"# Sphinx inventory version 2"
      )
  
      # same uri and inv, not redirected
      _read_from_url().url = "https://hostname/" + INVENTORY_FILENAME
      fetch_inventory(
          app,
          "https://hostname/",
          "https://hostname/" + INVENTORY_FILENAME,
      )
      assert "intersphinx inventory has moved" not in status.getvalue()
      assert InventoryFile.load.call_args[0][1] == "https://hostname/"
  
      # same uri and inv, redirected
      status.seek(0)
      status.truncate(0)
      _read_from_url().url = (
          "https://hostname/new/" + INVENTORY_FILENAME
      )
  
      fetch_inventory(
          app,
          "https://hostname/",
          "https://hostname/" + INVENTORY_FILENAME,
      )
      assert status.getvalue() == (
          "intersphinx inventory has moved: "
          "https://hostname/%s -> https://hostname/new/%s\n"
          % (INVENTORY_FILENAME, INVENTORY_FILENAME)
      )
      assert (
          InventoryFile.load.call_args[0][1] == "https://hostname/new"
      )
  
      # different uri and inv, not redirected
      status.seek(0)
      status.truncate(0)
      _read_from_url().url = (
          "https://hostname/new/" + INVENTORY_FILENAME
      )
  
      fetch_inventory(
          app,
          "https://hostname/",
          "https://hostname/new/" + INVENTORY_FILENAME,
      )
      assert "intersphinx inventory has moved" not in status.getvalue()
      assert InventoryFile.load.call_args[0][1] == "https://hostname/"
  
      # different uri and inv, redirected
      status.seek(0)
      status.truncate(0)
      _read_from_url().url = (
          "https://hostname/other/" + INVENTORY_FILENAME
      )
  
      fetch_inventory(
          app,
          "https://hostname/",
          "https://hostname/new/" + INVENTORY_FILENAME,
      )
      assert status.getvalue() == (
          "intersphinx inventory has moved: "
          "https://hostname/new/%s -> https://hostname/other/%s\n"
          % (INVENTORY_FILENAME, INVENTORY_FILENAME)
      )
      assert InventoryFile.load.call_args[0][1] == "https://hostname/"
  
imports: import http.server
  from unittest import mock
  import pytest
  from docutils import nodes
  from sphinx import addnodes
  from sphinx.ext.intersphinx import INVENTORY_FILENAME, _get_safe_url, _strip_basic_auth, fetch_inventory, inspect_main, load_mappings, missing_reference, normalize_intersphinx_mapping
  from sphinx.ext.intersphinx import setup
  from tests.test_util.test_util_inventory import inventory_v2, inventory_v2_not_having_version
  from tests.utils import http_server
label_desc: Use image node_id 4 for calling a global function with example usage: test_fetch_inventory_redirection(_read_from_url, InventoryFile, app, status, warning) without return types