Handle error messages with line breaks in confusion_matrix_test

Depending on the specifics of the condition (in particular whether it
can be evaluated statically), the error message produced by an assertion
can either be shown on one line or split across multiple lines.

In the latter case, the use of a .* regex fails, because the . doesn't
match the line breaks. To fix that we can just use [\s\S]* instead.
This commit is contained in:
Harry Slatyer 2020-01-08 09:21:58 +11:00
parent 2aaa53e21f
commit 0e59af232b

View File

@ -188,7 +188,7 @@ class ConfusionMatrixTest(test.TestCase):
def testLabelsTooLarge(self):
labels = np.asarray([1, 1, 0, 3, 5], dtype=np.int32)
predictions = np.asarray([2, 1, 0, 2, 2], dtype=np.int32)
with self.assertRaisesOpError("`labels`.*x < y"):
with self.assertRaisesOpError("`labels`[\s\S]*x < y"):
self._testConfMatrix(
labels=labels, predictions=predictions, num_classes=3, truth=None)
@ -203,7 +203,7 @@ class ConfusionMatrixTest(test.TestCase):
def testPredictionsTooLarge(self):
labels = np.asarray([1, 1, 0, 2, 2], dtype=np.int32)
predictions = np.asarray([2, 1, 0, 3, 5], dtype=np.int32)
with self.assertRaisesOpError("`predictions`.*x < y"):
with self.assertRaisesOpError("`predictions`[\s\S]*x < y"):
self._testConfMatrix(
labels=labels, predictions=predictions, num_classes=3, truth=None)