-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented custom errors (#186)
* feat: implemented custom errors This adds custom exception types, which should make error management by users easier closes #45 Signed-off-by: Luka Peschke <[email protected]> * replace match with .map_err Signed-off-by: Luka Peschke <[email protected]> * added docstirngs to exception types Signed-off-by: Luka Peschke <[email protected]> * reorder __all__ to be more logical in html docs Signed-off-by: Luka Peschke <[email protected]> * ci: added a docs check job Signed-off-by: Luka Peschke <[email protected]> --------- Signed-off-by: Luka Peschke <[email protected]>
- Loading branch information
1 parent
5d33b75
commit 6d76a19
Showing
13 changed files
with
456 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,3 +110,31 @@ jobs: | |
command: build | ||
args: "-o dist --interpreter python${{ matrix.python-version }}" | ||
target: ${{ steps.target.outputs.target }} | ||
|
||
check-docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
- name: Set up rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- run: | | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
# venv required by maturin | ||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
make install-test-requirements | ||
make install-doc-requirements | ||
# Required for pdoc to be able to import the sources | ||
make dev-install | ||
make doc |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from __future__ import annotations | ||
|
||
import fastexcel | ||
import pytest | ||
from utils import path_for_fixture | ||
|
||
|
||
def test_does_not_exist() -> None: | ||
expected_message = """calamine error: Cannot detect file format | ||
Context: | ||
0: Could not open workbook at path_does_not_exist.nope | ||
1: could not load excel file at path_does_not_exist.nope""" | ||
|
||
with pytest.raises(fastexcel.CalamineError, match=expected_message) as exc_info: | ||
fastexcel.read_excel("path_does_not_exist.nope") | ||
|
||
assert exc_info.value.__doc__ == "Generic calamine error" | ||
|
||
# Should also work with the base error type | ||
with pytest.raises(fastexcel.FastExcelError, match=expected_message): | ||
fastexcel.read_excel("path_does_not_exist.nope") | ||
|
||
|
||
def test_sheet_not_found_error() -> None: | ||
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet.xlsx")) | ||
expected_message = """sheet at index 42 not found | ||
Context: | ||
0: Sheet index 42 is out of range. File has 1 sheets""" | ||
|
||
with pytest.raises(fastexcel.SheetNotFoundError, match=expected_message) as exc_info: | ||
excel_reader.load_sheet(42) | ||
|
||
assert exc_info.value.__doc__ == "Sheet was not found" | ||
|
||
# Should also work with the base error type | ||
with pytest.raises(fastexcel.FastExcelError, match=expected_message): | ||
excel_reader.load_sheet(42) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"exc_class, expected_docstring", | ||
[ | ||
(fastexcel.FastExcelError, "The base class for all fastexcel errors"), | ||
( | ||
fastexcel.UnsupportedColumnTypeCombinationError, | ||
"Column contains an unsupported type combination", | ||
), | ||
(fastexcel.CannotRetrieveCellDataError, "Data for a given cell cannot be retrieved"), | ||
( | ||
fastexcel.CalamineCellError, | ||
"calamine returned an error regarding the content of the cell", | ||
), | ||
(fastexcel.CalamineError, "Generic calamine error"), | ||
(fastexcel.SheetNotFoundError, "Sheet was not found"), | ||
(fastexcel.ArrowError, "Generic arrow error"), | ||
(fastexcel.InvalidParametersError, "Provided parameters are invalid"), | ||
], | ||
) | ||
def test_docstrings(exc_class: type[Exception], expected_docstring: str) -> None: | ||
assert exc_class.__doc__ == expected_docstring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.