Skip to content

Commit c9dcd06

Browse files
committed
clearer error messages
1 parent 2c678d4 commit c9dcd06

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/arraytex/api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def to_matrix(
4141
if len(arr.shape) > 2:
4242
raise TooManyDimensionsError
4343

44-
environment = f"{style}matrix"
45-
4644
lines = _parse_lines(arr, num_format, scientific_notation)
4745

46+
environment = f"{style}matrix"
47+
4848
rv = [f"\\begin{{{environment}}}"]
4949
rv += [line.strip() + r" \\" for line in lines]
5050
rv += [f"\\end{{{environment}}}"]
@@ -96,17 +96,17 @@ def to_tabular(
9696

9797
if isinstance(col_align, list) and len(col_align) != n_cols:
9898
raise DimensionMismatchError(
99-
"Number of `col_align` items doesn't match number of columns "
100-
+ f"({len(col_align)} against {n_cols})"
99+
f"Number of `col_align` items ({len(col_align)}) "
100+
+ f"doesn't match number of columns ({n_cols})"
101101
)
102102

103103
if isinstance(col_align, str):
104104
col_align = [col_align for _ in range(n_cols)]
105105

106106
if cols and len(cols) != n_cols:
107107
raise DimensionMismatchError(
108-
"Number of `cols` items doesn't match number of columns "
109-
+ f"({len(cols)} against {n_cols})"
108+
f"Number of `cols` items ({len(cols)}) "
109+
+ f"doesn't match number of columns ({n_cols})"
110110
)
111111

112112
if not cols:

tests/test_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import numpy as np
66
import pytest
77

8-
from arraytex.api import to_matrix
9-
from arraytex.api import to_tabular
8+
from arraytex import to_matrix
9+
from arraytex import to_tabular
1010
from arraytex.errors import DimensionMismatchError
1111
from arraytex.errors import TooManyDimensionsError
1212

@@ -176,8 +176,7 @@ def test_mismatch_col_align(self) -> None:
176176
to_tabular(mat, col_align=["c", "c"])
177177

178178
assert str(exc.value) == (
179-
"Number of `col_align` items doesn't match number of "
180-
+ "columns (2 against 3)"
179+
"Number of `col_align` items (2) doesn't match number of columns (3)"
181180
)
182181

183182
def test_mismatch_cols(self) -> None:
@@ -188,7 +187,7 @@ def test_mismatch_cols(self) -> None:
188187
to_tabular(mat, cols=["1", "2"])
189188

190189
assert str(exc.value) == (
191-
"Number of `cols` items doesn't match number of " + "columns (2 against 3)"
190+
"Number of `cols` items (2) doesn't match number of columns (3)"
192191
)
193192

194193
def test_default(self) -> None:

0 commit comments

Comments
 (0)