Skip to content

Commit

Permalink
Address conda test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Aug 31, 2023
1 parent 5ee5d14 commit ad36b35
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
25 changes: 18 additions & 7 deletions tests/test_graphblas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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"<td>{value}</td>", 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
Expand All @@ -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"<td>{value}</td>" in res:
count += 1
self.assertEqual(expected_count, count)
Expand Down
15 changes: 14 additions & 1 deletion tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
15 changes: 14 additions & 1 deletion tests/test_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 15 additions & 1 deletion tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 14 additions & 1 deletion tests/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ad36b35

Please sign in to comment.