diff --git a/tools/python/test/test_matrix.py b/tools/python/test/test_matrix.py index a010a13f7..cdd9bed13 100644 --- a/tools/python/test/test_matrix.py +++ b/tools/python/test/test_matrix.py @@ -7,9 +7,9 @@ from pytest import raises try: import numpy + have_numpy = True except ImportError: - # Just skip these tests if numpy isn't installed - exit(0) + have_numpy = False def test_matrix_empty_init(): @@ -57,23 +57,24 @@ def test_matrix_from_list_as_column_vector(): assert str(m) == "0 \n1 \n2" -def test_matrix_from_object_with_2d_shape(): - m1 = numpy.array([[0, 1, 2], - [3, 4, 5], - [6, 7, 8]]) - m = matrix(m1) - assert m.nr() == 3 - assert m.nc() == 3 - assert m.shape == (3, 3) - assert len(m) == 3 - assert repr(m) == "< dlib.matrix containing: \n0 1 2 \n3 4 5 \n6 7 8 >" - assert str(m) == "0 1 2 \n3 4 5 \n6 7 8" +if have_numpy: + def test_matrix_from_object_with_2d_shape(): + m1 = numpy.array([[0, 1, 2], + [3, 4, 5], + [6, 7, 8]]) + m = matrix(m1) + assert m.nr() == 3 + assert m.nc() == 3 + assert m.shape == (3, 3) + assert len(m) == 3 + assert repr(m) == "< dlib.matrix containing: \n0 1 2 \n3 4 5 \n6 7 8 >" + assert str(m) == "0 1 2 \n3 4 5 \n6 7 8" -def test_matrix_from_object_without_2d_shape(): - with raises(IndexError): - m1 = numpy.array([0, 1, 2]) - matrix(m1) + def test_matrix_from_object_without_2d_shape(): + with raises(IndexError): + m1 = numpy.array([0, 1, 2]) + matrix(m1) def test_matrix_from_object_without_shape():