code: def test_random_termkeys():
      def random_fieldname():
          return "".join(
              chr(random.randint(65, 90)) for _ in xrange(1, 20)
          )
  
      def random_btext():
          a = array(
              "H", (random.randint(0, 0xD7FF) for _ in xrange(1, 20))
          )
          return array_tobytes(a).decode("utf-16")
  
      domain = sorted(
          set(
              [
                  (random_fieldname(), random_btext().encode("utf-8"))
                  for _ in xrange(1000)
              ]
          )
      )
  
      st, codec, seg = _make_codec()
      fieldobj = fields.TEXT()
      tw = codec.field_writer(st, seg)
      # Stupid ultra-low-level hand-adding of postings just to check handling of
      # random fieldnames and term texts
      lastfield = None
      for fieldname, text in domain:
          if lastfield and fieldname != lastfield:
              tw.finish_field()
              lastfield = None
          if lastfield is None:
              tw.start_field(fieldname, fieldobj)
              lastfield = fieldname
          tw.start_term(text)
          tw.add(0, 1.0, b(""), 1)
          tw.finish_term()
      if lastfield:
          tw.finish_field()
      tw.close()
  
      tr = codec.terms_reader(st, seg)
      for term in domain:
          assert term in tr
  
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 3 for calling a global function with example usage: test_random_termkeys() and returns: str, array_tobytes