Python 3 Migration: SDR Classifier Test

In sdr_classifier_test.py there is a test called testComputeCategory. I think this test is working but in python 3 the following line

self.assertIsInstance(value, (type(None), bytes))

breaks when the value is “D”. Could somebody check if the predictResult["actualValues"] has a “D” in it when running in python 2.7?

Here is the complete test:

  def testComputeCategory(self):
    c = self._classifier([1], 0.1, 0.1, 0)
    c.compute(recordNum=0, patternNZ=[1, 5, 9],
              classification={"bucketIdx": 4, "actValue": "D"},
              learn=True, infer=True)
    result = c.compute(recordNum=1, patternNZ=[1, 5, 9],
                       classification={"bucketIdx": 4, "actValue": "D"},
                       learn=True, infer=True)
    self.assertSetEqual(set(result.keys()), set(("actualValues", 1)))
    self.assertEqual(result["actualValues"][4], "D")

    predictResult = c.compute(recordNum=2, patternNZ=[1, 5, 9],
                              classification={"bucketIdx": 5,
                                              "actValue": None},
                              learn=True, infer=True)
    for value in predictResult["actualValues"]:
      self.assertIsInstance(value, (type(None), bytes))

Thanks!

Turns out that the “2to3” script changes the following line:
self.assertIsInstance(value, (types.NoneType, types.StringType))
to
self.assertIsInstance(value, (type(None), bytes))

which doesn’t actually work.

The correct transformation, I think, is:
self.assertIsInstance(value, (type(None), str))

So you got this resolved then?

Yes. It was my fault, as always. :wink:

1 Like