Skip to content

Commit

Permalink
clearer error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dbatten5 committed Mar 20, 2023
1 parent 2c678d4 commit c9dcd06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/arraytex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def to_matrix(
if len(arr.shape) > 2:
raise TooManyDimensionsError

environment = f"{style}matrix"

lines = _parse_lines(arr, num_format, scientific_notation)

environment = f"{style}matrix"

rv = [f"\\begin{{{environment}}}"]
rv += [line.strip() + r" \\" for line in lines]
rv += [f"\\end{{{environment}}}"]
Expand Down Expand Up @@ -96,17 +96,17 @@ def to_tabular(

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

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

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

if not cols:
Expand Down
9 changes: 4 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import numpy as np
import pytest

from arraytex.api import to_matrix
from arraytex.api import to_tabular
from arraytex import to_matrix
from arraytex import to_tabular
from arraytex.errors import DimensionMismatchError
from arraytex.errors import TooManyDimensionsError

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

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

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

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

def test_default(self) -> None:
Expand Down

0 comments on commit c9dcd06

Please sign in to comment.