From ad36b356b51edfe77c82b28f643e2abd4cf2804c Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Wed, 30 Aug 2023 22:46:40 -0700 Subject: [PATCH] Address conda test fails --- pyproject.toml | 2 +- tests/test_graphblas.py | 25 ++++++++++++++++++------- tests/test_latex.py | 15 ++++++++++++++- tests/test_scipy.py | 15 ++++++++++++++- tests/test_sparse.py | 16 +++++++++++++++- tests/test_str.py | 15 ++++++++++++++- 6 files changed, 76 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 59b0d96..84b9a16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "matrepr" -version = "0.7.3" +version = "0.7.4" description="Sparse matrix string, HTML, and LaTeX rendering with Jupyter integration." readme = "README.md" authors = [ diff --git a/tests/test_graphblas.py b/tests/test_graphblas.py index 075360b..2e7eb90 100644 --- a/tests/test_graphblas.py +++ b/tests/test_graphblas.py @@ -7,7 +7,6 @@ from matrepr import to_html, to_latex, to_str import matrepr -from .test_scipy import generate_fixed_value try: import graphblas as gb @@ -21,6 +20,20 @@ gb = None +def generate_fixed_value(m, n): + row_factor = 10**(1+len(str(n))) + nnz = m*n + rows, cols, data = [1] * nnz, [1] * nnz, [1] * nnz + for i in range(nnz): + r = int(i / n) + c = i % n + rows[i] = r + cols[i] = c + data[i] = (r+1)*row_factor + c + + return gb.Matrix.from_coo(rows, cols, data, nrows=m, ncols=n, dtype='int64'), data + + @unittest.skipIf(not have_gb, "python-graphblas not installed") class GraphBLASMatrixTests(unittest.TestCase): def setUp(self): @@ -47,15 +60,13 @@ def test_shape(self): self.assertEqual((5, 1), adapter.get_shape()) def test_contents(self): - mat = generate_fixed_value(10, 10) - gb_mat = gb.io.from_scipy_sparse(mat) + gb_mat, data = generate_fixed_value(10, 10) res = to_html(gb_mat, notebook=False, max_rows=20, max_cols=20, title=True, indices=True) - for value in mat.data: + for value in data: self.assertIn(f"{value}", res) def test_truncate(self): - mat = generate_fixed_value(20, 20) - gb_mat = gb.io.from_scipy_sparse(mat) + gb_mat, data = generate_fixed_value(20, 20) for after_dots, expected_count in [ (0, 25), # 5*5 @@ -64,7 +75,7 @@ def test_truncate(self): ]: res = to_html(gb_mat, notebook=False, max_rows=6, max_cols=6, num_after_dots=after_dots) count = 0 - for value in mat.data: + for value in data: if f"{value}" in res: count += 1 self.assertEqual(expected_count, count) diff --git a/tests/test_latex.py b/tests/test_latex.py index 1a15175..8fbf167 100644 --- a/tests/test_latex.py +++ b/tests/test_latex.py @@ -8,11 +8,24 @@ import scipy.sparse from matrepr import to_latex -from .test_html import generate_fixed_value numpy.random.seed(123) +def generate_fixed_value(m, n): + row_factor = 10**(1+len(str(n))) + nnz = m*n + rows, cols, data = [1] * nnz, [1] * nnz, [1] * nnz + for i in range(nnz): + r = int(i / n) + c = i % n + rows[i] = r + cols[i] = c + data[i] = (r+1)*row_factor + c + + return scipy.sparse.coo_matrix((data, (rows, cols)), shape=(m, n), dtype='int64') + + class ToLatexTests(unittest.TestCase): def setUp(self): self.mats = [ diff --git a/tests/test_scipy.py b/tests/test_scipy.py index a83eba6..6401f97 100644 --- a/tests/test_scipy.py +++ b/tests/test_scipy.py @@ -8,11 +8,24 @@ import scipy.sparse from matrepr import to_html, to_latex, to_str -from .test_html import generate_fixed_value numpy.random.seed(123) +def generate_fixed_value(m, n): + row_factor = 10**(1+len(str(n))) + nnz = m*n + rows, cols, data = [1] * nnz, [1] * nnz, [1] * nnz + for i in range(nnz): + r = int(i / n) + c = i % n + rows[i] = r + cols[i] = c + data[i] = (r+1)*row_factor + c + + return scipy.sparse.coo_matrix((data, (rows, cols)), shape=(m, n), dtype='int64') + + class SciPyTests(unittest.TestCase): def setUp(self): self.mats = [ diff --git a/tests/test_sparse.py b/tests/test_sparse.py index d123839..3df0e69 100644 --- a/tests/test_sparse.py +++ b/tests/test_sparse.py @@ -10,12 +10,26 @@ sparse = None from matrepr import to_html, to_latex, to_str -from .test_html import generate_fixed_value import numpy.random numpy.random.seed(123) +def generate_fixed_value(m, n): + import scipy + row_factor = 10**(1+len(str(n))) + nnz = m*n + rows, cols, data = [1] * nnz, [1] * nnz, [1] * nnz + for i in range(nnz): + r = int(i / n) + c = i % n + rows[i] = r + cols[i] = c + data[i] = (r+1)*row_factor + c + + return scipy.sparse.coo_matrix((data, (rows, cols)), shape=(m, n), dtype='int64') + + @unittest.skipIf(sparse is None, "pydata/sparse not installed") class PyDataSparseTests(unittest.TestCase): def setUp(self): diff --git a/tests/test_str.py b/tests/test_str.py index 5021aee..378de06 100644 --- a/tests/test_str.py +++ b/tests/test_str.py @@ -8,7 +8,20 @@ from matrepr import to_str from matrepr.string_formatter import max_line_width -from .test_html import generate_fixed_value + + +def generate_fixed_value(m, n): + row_factor = 10**(1+len(str(n))) + nnz = m*n + rows, cols, data = [1] * nnz, [1] * nnz, [1] * nnz + for i in range(nnz): + r = int(i / n) + c = i % n + rows[i] = r + cols[i] = c + data[i] = (r+1)*row_factor + c + + return scipy.sparse.coo_matrix((data, (rows, cols)), shape=(m, n), dtype='int64') class ToStrTests(unittest.TestCase):