Skip to content

Commit

Permalink
Add custom doctest wrapper (#25)
Browse files Browse the repository at this point in the history
* Add custom doctest wrapper

This should make sure that doctests pass for various versions of numpy and python.

* Bump workflow version

* Make set_printoptions test override more strict
  • Loading branch information
tammojan authored Sep 9, 2024
1 parent 04a3a0c commit 307d74d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "lofarantpos"
version = "0.7.0"
version = "0.7.1"
description = "Access, query, and manipulate LOFAR antenna positions"
authors = [
{name = "Tammo Jan Dijkema", email = "[email protected]"},
Expand Down Expand Up @@ -31,3 +31,7 @@ requires=[

[project.urls]
Homepage = "https://github.com/lofar-astron/lofar-antenna-positions"

[tool.pytest.ini_options]
doctest_optionflags = "ELLIPSIS"
addopts = "--doctest-modules --doctest-continue-on-failure --ignore=scripts --ignore=docs"
20 changes: 20 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import doctest
import pytest
import re


class NumpyOutputChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
# Remove the np.float64 wrapper from both want and got
want = re.sub(r'np\.float64\(([\d.-]*)\)', r'\1', want)
got = re.sub(r'np\.float64\(([\d.-]*)\)', r'\1', got)

# numpy.set_printoptions started producing output in some version
if got.strip().startswith("<Token") and want == "":
return True

return super().check_output(want, got, optionflags)

@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
doctest.OutputChecker = NumpyOutputChecker

0 comments on commit 307d74d

Please sign in to comment.