code: def test_checksum_file():
      from whoosh.filedb.structfile import ChecksumFile
      from zlib import crc32
  
      def wr(f):
          f.write(b("Testing"))
          f.write_int(-100)
          f.write_varint(10395)
          f.write_string(b("Hello"))
          f.write_ushort(32959)
  
      st = RamStorage()
      # Write a file normally
      f = st.create_file("control")
      wr(f)
      f.close()
      # Checksum the contents
      f = st.open_file("control")
      target = crc32(f.read()) & 0xFFFFFFFF
      f.close()
  
      # Write a file with checksumming
      f = st.create_file("test")
      cf = ChecksumFile(f)
      wr(cf)
      assert cf.checksum() == target
      f.close()
  
      # Read the file with checksumming
      f = st.open_file("test")
      cf = ChecksumFile(f)
      assert cf.read(7) == b("Testing")
      assert cf.read_int() == -100
      assert cf.read_varint() == 10395
      assert cf.read_string() == b("Hello")
      assert cf.read_ushort() == 32959
      assert cf.checksum() == target
      cf.close()
  
file_path: whoosh/tests/test_tables.py
imports: from __future__ import with_statement
  import random
  from whoosh.compat import b, xrange, iteritems
  from whoosh.filedb.filestore import RamStorage
  from whoosh.filedb.filetables import HashReader, HashWriter
  from whoosh.filedb.filetables import OrderedHashWriter, OrderedHashReader
  from whoosh.util.testing import TempStorage
label_desc: Use image node_id 9 for calling a global function with example usage: test_checksum_file() without return types