class_docstr: Unit tests for CategoryEncoder class
code: def testReadWrite(self):
      categories = ["ES", "GB", "US"]
  
      # forced: is not recommended, but is used here for readability. see
      # scalar.py
      original = CategoryEncoder(
          w=3, categoryList=categories, forced=True
      )
      output = original.encode("US")
      target = numpy.array(
          [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], dtype=defaultDtype
      )
      self.assertTrue(numpy.array_equal(output, target))
  
      decoded = original.decode(output)
  
      proto1 = CategoryEncoderProto.new_message()
      original.write(proto1)
  
      # Write the proto to a temp file and read it back into a new proto
      with tempfile.TemporaryFile() as f:
          proto1.write(f)
          f.seek(0)
          proto2 = CategoryEncoderProto.read(f)
  
      encoder = CategoryEncoder.read(proto2)
  
      self.assertIsInstance(encoder, CategoryEncoder)
      self.assertEqual(encoder.verbosity, original.verbosity)
      self.assertEqual(encoder.width, original.width)
      self.assertEqual(encoder.description, original.description)
      self.assertEqual(encoder.name, original.name)
      self.assertDictEqual(
          encoder.categoryToIndex, original.categoryToIndex
      )
      self.assertDictEqual(
          encoder.indexToCategory, original.indexToCategory
      )
      self.assertTrue(numpy.array_equal(encoder.encode("US"), output))
      self.assertEqual(
          original.decode(encoder.encode("US")),
          encoder.decode(original.encode("US")),
      )
      self.assertEqual(decoded, encoder.decode(output))
  
file_path: nupic-legacy/tests/unit/nupic/encoders/category_test.py
imports: import tempfile
  import unittest
  import numpy
  from nupic.data import SENTINEL_VALUE_FOR_MISSING_DATA
  from nupic.encoders.base import defaultDtype
  from nupic.encoders.category import CategoryEncoder, UNKNOWN
label_desc: Use image node_id 2 for calling the CategoryEncoderTest obj's underlying member method code with example usage: obj.testReadWrite() without return types