code: def test_IndexBuilder():
      domain1 = DummyDomain(
          [
              (
                  "objname1",
                  "objdispname1",
                  "objtype1",
                  "docname1_1",
                  "#anchor",
                  1,
              ),
              (
                  "objname2",
                  "objdispname2",
                  "objtype2",
                  "docname1_2",
                  "",
                  -1,
              ),
          ]
      )
      domain2 = DummyDomain(
          [
              (
                  "objname1",
                  "objdispname1",
                  "objtype1",
                  "docname2_1",
                  "#anchor",
                  1,
              ),
              (
                  "objname2",
                  "objdispname2",
                  "objtype2",
                  "docname2_2",
                  "",
                  -1,
              ),
          ]
      )
      env = DummyEnvironment(
          "1.0", {"dummy1": domain1, "dummy2": domain2}
      )
      doc = utils.new_document(b"test data", settings)
      doc["file"] = "dummy"
      parser.parse(FILE_CONTENTS, doc)
  
      # feed
      index = IndexBuilder(env, "en", {}, None)
      index.feed("docname1_1", "filename1_1", "title1_1", doc)
      index.feed("docname1_2", "filename1_2", "title1_2", doc)
      index.feed("docname2_2", "filename2_2", "title2_2", doc)
      index.feed("docname2_1", "filename2_1", "title2_1", doc)
      assert index._titles == {
          "docname1_1": "title1_1",
          "docname1_2": "title1_2",
          "docname2_1": "title2_1",
          "docname2_2": "title2_2",
      }
      assert index._filenames == {
          "docname1_1": "filename1_1",
          "docname1_2": "filename1_2",
          "docname2_1": "filename2_1",
          "docname2_2": "filename2_2",
      }
      assert index._mapping == {
          "ar": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          },
          "fermion": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          },
          "comment": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          },
          "non": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          },
          "index": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          },
          "test": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          },
      }
      assert index._title_mapping == {
          "section_titl": {
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          }
      }
      assert index._objtypes == {}
      assert index._objnames == {}
  
      # freeze
      assert index.freeze() == {
          "docnames": (
              "docname1_1",
              "docname1_2",
              "docname2_1",
              "docname2_2",
          ),
          "envversion": "1.0",
          "filenames": [
              "filename1_1",
              "filename1_2",
              "filename2_1",
              "filename2_2",
          ],
          "objects": {
              "": [
                  (0, 0, 1, "#anchor", "objdispname1"),
                  (2, 1, 1, "#anchor", "objdispname1"),
              ]
          },
          "objnames": {
              0: ("dummy1", "objtype1", "objtype1"),
              1: ("dummy2", "objtype1", "objtype1"),
          },
          "objtypes": {0: "dummy1:objtype1", 1: "dummy2:objtype1"},
          "terms": {
              "ar": [0, 1, 2, 3],
              "comment": [0, 1, 2, 3],
              "fermion": [0, 1, 2, 3],
              "index": [0, 1, 2, 3],
              "non": [0, 1, 2, 3],
              "test": [0, 1, 2, 3],
          },
          "titles": ("title1_1", "title1_2", "title2_1", "title2_2"),
          "titleterms": {"section_titl": [0, 1, 2, 3]},
          "alltitles": {
              "section_title": [
                  (0, "section-title"),
                  (1, "section-title"),
                  (2, "section-title"),
                  (3, "section-title"),
              ]
          },
          "indexentries": {},
      }
      assert index._objtypes == {
          ("dummy1", "objtype1"): 0,
          ("dummy2", "objtype1"): 1,
      }
      assert index._objnames == {
          0: ("dummy1", "objtype1", "objtype1"),
          1: ("dummy2", "objtype1", "objtype1"),
      }
  
      env = DummyEnvironment(
          "1.0", {"dummy1": domain1, "dummy2": domain2}
      )
  
      # dump / load
      stream = BytesIO()
      index.dump(stream, "pickle")
      stream.seek(0)
  
      index2 = IndexBuilder(env, "en", {}, None)
      index2.load(stream, "pickle")
  
      assert index2._titles == index._titles
      assert index2._filenames == index._filenames
      assert index2._mapping == index._mapping
      assert index2._title_mapping == index._title_mapping
      assert index2._objtypes == {}
      assert index2._objnames == {}
  
      # freeze after load
      assert index2.freeze() == index.freeze()
      assert index2._objtypes == index._objtypes
      assert index2._objnames == index._objnames
  
      # prune
      index.prune(["docname1_2", "docname2_2"])
      assert index._titles == {
          "docname1_2": "title1_2",
          "docname2_2": "title2_2",
      }
      assert index._filenames == {
          "docname1_2": "filename1_2",
          "docname2_2": "filename2_2",
      }
      assert index._mapping == {
          "ar": {"docname1_2", "docname2_2"},
          "fermion": {"docname1_2", "docname2_2"},
          "comment": {"docname1_2", "docname2_2"},
          "non": {"docname1_2", "docname2_2"},
          "index": {"docname1_2", "docname2_2"},
          "test": {"docname1_2", "docname2_2"},
      }
      assert index._title_mapping == {
          "section_titl": {"docname1_2", "docname2_2"}
      }
      assert index._objtypes == {
          ("dummy1", "objtype1"): 0,
          ("dummy2", "objtype1"): 1,
      }
      assert index._objnames == {
          0: ("dummy1", "objtype1", "objtype1"),
          1: ("dummy2", "objtype1", "objtype1"),
      }
  
      # freeze after prune
      assert index.freeze() == {
          "docnames": ("docname1_2", "docname2_2"),
          "envversion": "1.0",
          "filenames": ["filename1_2", "filename2_2"],
          "objects": {},
          "objnames": {
              0: ("dummy1", "objtype1", "objtype1"),
              1: ("dummy2", "objtype1", "objtype1"),
          },
          "objtypes": {0: "dummy1:objtype1", 1: "dummy2:objtype1"},
          "terms": {
              "ar": [0, 1],
              "comment": [0, 1],
              "fermion": [0, 1],
              "index": [0, 1],
              "non": [0, 1],
              "test": [0, 1],
          },
          "titles": ("title1_2", "title2_2"),
          "titleterms": {"section_titl": [0, 1]},
          "alltitles": {
              "section_title": [
                  (0, "section-title"),
                  (1, "section-title"),
              ]
          },
          "indexentries": {},
      }
      assert index._objtypes == {
          ("dummy1", "objtype1"): 0,
          ("dummy2", "objtype1"): 1,
      }
      assert index._objnames == {
          0: ("dummy1", "objtype1", "objtype1"),
          1: ("dummy2", "objtype1", "objtype1"),
      }
  
imports: import json
  import warnings
  from io import BytesIO
  import pytest
  from docutils import frontend, utils
  from docutils.parsers import rst
  from sphinx.search import IndexBuilder
label_desc: Use image node_id 11 for calling a global function with example usage: test_IndexBuilder() without return types