From c9dcd06626eb6787d610813a778887ebfc407f1b Mon Sep 17 00:00:00 2001 From: Dom Batten Date: Mon, 20 Mar 2023 10:04:18 +0000 Subject: [PATCH] clearer error messages --- src/arraytex/api.py | 12 ++++++------ tests/test_api.py | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/arraytex/api.py b/src/arraytex/api.py index 8f9aebe..4e4ea72 100644 --- a/src/arraytex/api.py +++ b/src/arraytex/api.py @@ -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}}}"] @@ -96,8 +96,8 @@ 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): @@ -105,8 +105,8 @@ def to_tabular( 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: diff --git a/tests/test_api.py b/tests/test_api.py index 646cf6f..798599a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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 @@ -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: @@ -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: