From 785df3bba5d6191e0104562c7966c53e72207810 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Fri, 16 Dec 2022 15:49:00 -0700 Subject: [PATCH 1/4] docs(readme): fix action build badge (#81) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5b50e2..ffc0261 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # table2ascii -[![build](https://img.shields.io/github/workflow/status/DenverCoder1/table2ascii/Python%20application/main)](https://github.com/DenverCoder1/table2ascii/actions/workflows/python-app.yml) +[![build](https://img.shields.io/github/actions/workflow/status/DenverCoder1/table2ascii/python-test.yml?branch=main)](https://github.com/DenverCoder1/table2ascii/actions/workflows/python-app.yml) [![version](https://img.shields.io/pypi/v/table2ascii)](https://pypi.org/project/table2ascii/) [![downloads](https://static.pepy.tech/personalized-badge/table2ascii?period=total&left_color=grey&right_color=blue&left_text=downloads)](https://pepy.tech/project/table2ascii) [![license](https://img.shields.io/pypi/l/table2ascii)](https://github.com/DenverCoder1/table2ascii/blob/main/LICENSE) From 58c886a925e3bdaebf04802b7a3170816a16a901 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Fri, 16 Dec 2022 16:14:53 -0700 Subject: [PATCH 2/4] ci: Update publish script to use build module (#82) --- .github/workflows/python-publish.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index caf5831..de9e03a 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -21,11 +21,12 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install twine build - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python setup.py sdist bdist_wheel + python3 -m build --sdist + twine check dist/* twine upload dist/* From a9c79f90406f5320cd88a2bbed0cb41818d47d87 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 17 Dec 2022 18:00:47 -0700 Subject: [PATCH 3/4] feat: Add invalid column width error (#83) --- docs/source/api.rst | 2 ++ table2ascii/__init__.py | 2 +- table2ascii/exceptions.py | 25 +++++++++++++++++++++---- table2ascii/table_to_ascii.py | 3 +++ tests/test_column_widths.py | 8 ++++++-- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/docs/source/api.rst b/docs/source/api.rst index 6b16e63..170e480 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -57,6 +57,8 @@ Exceptions .. autoexception:: table2ascii.exceptions.ColumnWidthTooSmallError +.. autoexception:: table2ascii.exceptions.InvalidColumnWidthError + .. autoexception:: table2ascii.exceptions.InvalidAlignmentError .. autoexception:: table2ascii.exceptions.TableStyleTooLongError diff --git a/table2ascii/__init__.py b/table2ascii/__init__.py index c70aad5..ebd9744 100644 --- a/table2ascii/__init__.py +++ b/table2ascii/__init__.py @@ -8,7 +8,7 @@ from .table_style import TableStyle from .table_to_ascii import table2ascii -__version__ = "1.0.1" +__version__ = "1.0.2" __all__ = [ "Alignment", diff --git a/table2ascii/exceptions.py b/table2ascii/exceptions.py index 86be92a..0c57134 100644 --- a/table2ascii/exceptions.py +++ b/table2ascii/exceptions.py @@ -156,7 +156,10 @@ def __init__(self, padding: int): super().__init__(self._message()) def _message(self) -> str: - return f"Invalid cell padding: {self.padding} is not a positive integer." + return ( + f"Invalid cell padding: The cell padding provided was {self.padding} " + f"but it must be a non-negative integer." + ) class ColumnWidthTooSmallError(TableOptionError): @@ -171,7 +174,7 @@ class ColumnWidthTooSmallError(TableOptionError): min_width (int): The minimum width that is allowed """ - def __init__(self, column_index: int, column_width: int, min_width: int): + def __init__(self, column_index: int, column_width: int, min_width: int | None = None): self.column_index = column_index self.column_width = column_width self.min_width = min_width @@ -179,12 +182,26 @@ def __init__(self, column_index: int, column_width: int, min_width: int): def _message(self) -> str: return ( - f"Column width too small: The column width for column index {self.column_index} " - f" of `column_widths` is {self.column_width}, but the minimum width " + f"Column width too small: The column width for index {self.column_index} " + f"of `column_widths` is {self.column_width}, but the minimum width " f"required to display the content is {self.min_width}." ) +class InvalidColumnWidthError(ColumnWidthTooSmallError): + """Exception raised when the column width is invalid + + This class is a subclass of :class:`ColumnWidthTooSmallError`. + """ + + def _message(self) -> str: + return ( + f"Invalid column width: The column width for index {self.column_index} " + f"of `column_widths` is {self.column_width}, but the column width " + f"must be a positive integer." + ) + + class InvalidAlignmentError(TableOptionError): """Exception raised when an invalid value is passed for an :class:`Alignment` diff --git a/table2ascii/table_to_ascii.py b/table2ascii/table_to_ascii.py index 1b3a523..8116467 100644 --- a/table2ascii/table_to_ascii.py +++ b/table2ascii/table_to_ascii.py @@ -16,6 +16,7 @@ FooterColumnCountMismatchError, InvalidAlignmentError, InvalidCellPaddingError, + InvalidColumnWidthError, NoHeaderBodyOrFooterError, ) from .merge import Merge @@ -150,6 +151,8 @@ def __calculate_column_widths( minimum = column_widths[i] if option is None: option = minimum + elif option < 0: + raise InvalidColumnWidthError(i, option) elif option < minimum: raise ColumnWidthTooSmallError(i, option, minimum) column_widths[i] = option diff --git a/tests/test_column_widths.py b/tests/test_column_widths.py index 5a3f1ba..55840eb 100644 --- a/tests/test_column_widths.py +++ b/tests/test_column_widths.py @@ -1,7 +1,11 @@ import pytest from table2ascii import table2ascii as t2a -from table2ascii.exceptions import ColumnWidthsCountMismatchError, ColumnWidthTooSmallError +from table2ascii.exceptions import ( + ColumnWidthsCountMismatchError, + ColumnWidthTooSmallError, + InvalidColumnWidthError, +) def test_column_widths(): @@ -83,7 +87,7 @@ def test_wrong_number_column_widths(): def test_negative_column_widths(): - with pytest.raises(ColumnWidthTooSmallError): + with pytest.raises(InvalidColumnWidthError): t2a( header=["#", "G", "H", "R", "S"], body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], From ebc0b72bca50e031110800b389e136e5a4c63d88 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 17 Dec 2022 18:04:12 -0700 Subject: [PATCH 4/4] docs: Update build status badge (#84) --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 808a71e..1bfb11e 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -27,7 +27,7 @@ Contents styles -.. |build| image:: https://img.shields.io/github/workflow/status/DenverCoder1/table2ascii/Python%20application/main +.. |build| image:: https://img.shields.io/github/actions/workflow/status/DenverCoder1/table2ascii/python-test.yml?branch=main :target: https://github.com/DenverCoder1/table2ascii/actions/workflows/python-app.yml .. |version| image:: https://img.shields.io/pypi/v/table2ascii :target: https://pypi.org/project/table2ascii/ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy