code: def test_stored_fields():
      codec = default_codec()
      fieldobj = fields.TEXT(stored=True)
      with TempStorage("storedfields") as st:
          seg = codec.new_segment(st, "test")
  
          dw = codec.per_document_writer(st, seg)
          dw.start_doc(0)
          dw.add_field("a", fieldobj, "hello", 1)
          dw.add_field("b", fieldobj, "there", 1)
          dw.finish_doc()
  
          dw.start_doc(1)
          dw.add_field("a", fieldobj, "one", 1)
          dw.add_field("b", fieldobj, "two", 1)
          dw.add_field("c", fieldobj, "three", 1)
          dw.finish_doc()
  
          dw.start_doc(2)
          dw.finish_doc()
  
          dw.start_doc(3)
          dw.add_field("a", fieldobj, "alfa", 1)
          dw.add_field("b", fieldobj, "bravo", 1)
          dw.finish_doc()
  
          dw.close()
          seg.set_doc_count(4)
  
          pdr = codec.per_document_reader(st, seg)
          assert pdr.doc_count_all() == 4
          assert pdr.stored_fields(0) == {"a": "hello", "b": "there"}
          # Note: access out of order
          assert pdr.stored_fields(3), {"a": "alfa", "b": "bravo"}
          assert pdr.stored_fields(1) == {
              "a": "one",
              "b": "two",
              "c": "three",
          }
  
          sfs = list(pdr.all_stored_fields())
          assert len(sfs) == 4
          assert sfs == [
              {"a": "hello", "b": "there"},
              {"a": "one", "b": "two", "c": "three"},
              {},
              {"a": "alfa", "b": "bravo"},
          ]
          pdr.close()
  
imports: from __future__ import with_statement
  import random
  from array import array
  import pytest
  from whoosh import analysis, fields, formats, query
  from whoosh.compat import u, b, text_type
  from whoosh.compat import array_tobytes, xrange
  from whoosh.codec import default_codec
  from whoosh.filedb.filestore import RamStorage
  from whoosh.util.testing import TempStorage
label_desc: Use image node_id 4 for calling a global function with example usage: test_stored_fields() without return types