def test_invalid_classes(self): with self.assertRaises(TypeError): pred2str(self.predictions, 'abc')
def test_unequal_lengths(self): with self.assertRaises(IndexError): pred2str(self.predictions, self.classes[:-2])
def test_invalid_preds(self): with self.assertRaises(TypeError): pred2str('abc', self.classes) with self.assertRaises(TypeError): pred2str(['a', 0.9, 0.8], self.classes)
def test_classonly(self): expected = "tiger" result = pred2str(self.predictions, self.classes, class_only=True, full=False) self.assertEqual(expected, result)
def test_notfull(self): expected = "tiger : 0.690" result = pred2str(self.predictions, self.classes, full=False) self.assertEqual(expected, result)
def test_full_precedence(self): expected = "bear : 0.010\ncat : 0.100\ndog : 0.190\ntiger : 0.690" result = pred2str(self.predictions, self.classes, full=True, class_only=True) self.assertEqual(expected, result)
def test_normal(self): expected = "bear : 0.010\ncat : 0.100\ndog : 0.190\ntiger : 0.690" result = pred2str(self.predictions, self.classes) self.assertEqual(expected, result)