From 51c0d699f95cfa660c678fd6ce3d5011f9f12ffb Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Wed, 30 Aug 2023 20:21:46 -0700 Subject: [PATCH] Add expression tests --- tests/test_graphblas.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/test_graphblas.py b/tests/test_graphblas.py index ed880c3..075360b 100644 --- a/tests/test_graphblas.py +++ b/tests/test_graphblas.py @@ -4,7 +4,7 @@ import unittest -from matrepr import to_html, to_latex +from matrepr import to_html, to_latex, to_str import matrepr from .test_scipy import generate_fixed_value @@ -13,7 +13,7 @@ import graphblas as gb # Context initialization must happen before any other imports - gb.init("suitesparse", blocking=True) + gb.init("suitesparse", blocking=False) have_gb = True except ImportError: @@ -24,8 +24,10 @@ @unittest.skipIf(not have_gb, "python-graphblas not installed") class GraphBLASMatrixTests(unittest.TestCase): def setUp(self): + mat = gb.Matrix.from_coo([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], nrows=5, ncols=5) self.mats = [ - gb.Matrix.from_coo([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], nrows=5, ncols=5), + mat, + mat @ mat, # an expression class ] def test_no_crash(self): @@ -36,6 +38,9 @@ def test_no_crash(self): res = to_latex(mat, title=True) self.assertGreater(len(res), 10) + res = to_str(mat, title=True) + self.assertGreater(len(res), 10) + def test_shape(self): mat = gb.Matrix.from_coo([0, 1, 2, 3, 4], [0, 0, 0, 0, 0], [0, 1, 2, 3, 4], nrows=5, ncols=1) adapter = matrepr._get_adapter(mat, None) @@ -68,8 +73,10 @@ def test_truncate(self): @unittest.skipIf(not have_gb, "python-graphblas not installed") class GraphBLASVectorTests(unittest.TestCase): def setUp(self): + vec = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8) self.vecs = [ - gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8) + vec, + vec + vec, # an expression ] def test_no_crash(self): @@ -80,6 +87,9 @@ def test_no_crash(self): res = to_latex(vec, title=True) self.assertGreater(len(res), 10) + res = to_str(vec, title=True) + self.assertGreater(len(res), 10) + def test_shape(self): vec = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8) adapter = matrepr._get_adapter(vec, None)