diff --git a/.github/workflows/doctests.yml b/.github/workflows/doctests.yml index 05c65469f..f197b8caa 100644 --- a/.github/workflows/doctests.yml +++ b/.github/workflows/doctests.yml @@ -1,6 +1,7 @@ name: doctests on: + pull_request: push: branches: - main @@ -16,8 +17,11 @@ jobs: with: python-version: '3.11' - name: Build treams - run: python -m pip install -e . + run: python -m pip install "numpy<2" -e .[docs,io] + - name: Install requirements for gmsh + run: | + sudo apt-get update + sudo apt-get -y install libglu1 libxcursor-dev libxft2 libxinerama1 libfltk1.3-dev libfreetype6-dev libgl1-mesa-dev - name: Run doctests run: | - python -m pip install treams[docs,io] - sphinx-build -b doctest docs docs/_build/doctest + TZ=UTC sphinx-build -b doctest docs docs/_build/doctest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fc8f22485..94b0437d9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,9 +1,11 @@ name: tests on: + pull_request: push: branches: - main + workflow_dispatch: jobs: tests: @@ -43,6 +45,7 @@ jobs: rm htmlcov/.gitignore - name: Deploy report + if: ${{ matrix.python-version == '3.11' }} uses: s0/git-publish-subdir-action@develop env: REPO: self diff --git a/conftest.py b/conftest.py index 98f53fab8..cad567192 100644 --- a/conftest.py +++ b/conftest.py @@ -4,7 +4,7 @@ subpackage. """ import pytest - +import pathlib def pytest_addoption(parser): """Add option '--runslow' and '--rungmsh'.""" @@ -14,6 +14,8 @@ def pytest_addoption(parser): parser.addoption( "--rungmsh", action="store_true", default=False, help="run tests needing gmsh" ) + parser.addini("datadir", "my own datadir for pytest-regressions") + parser.addini("original_datadir", "my own original_datadir for pytest-regressions") def pytest_configure(config): @@ -36,3 +38,14 @@ def pytest_collection_modifyitems(config, items): for item in items: if "gmsh" in item.keywords: item.add_marker(skip_slow) + +@pytest.fixture() +def original_datadir(request) -> pathlib.Path: + config = request.config + return config.rootpath / config.getini('datadir') + + +@pytest.fixture() +def datadir(request) -> pathlib.Path: + config = request.config + return config.rootpath / config.getini('datadir') \ No newline at end of file diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 18a56b49a..20a7f2aa4 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -21,7 +21,7 @@ Import *treams*, create T-matrices and start calculating. >>> import treams >>> tm = treams.TMatrix.sphere(1, .6, 1, [4, 1]) - >>> tm.xs_ext_avg - 0.3072497765576123 + >>> f"{tm.xs_ext_avg:.4f}" + '0.3072' More detailed examples are given in :doc:`intro`. diff --git a/pyproject.toml b/pyproject.toml index 35278bbc5..f26254f9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "wheel", "Cython", "numpy", - "scipy>=1.6", + "scipy", "setuptools_scm>=6.2" ] build-backend = "setuptools.build_meta" @@ -22,3 +22,6 @@ archs = ["auto64"] skip = ["pp*", "*musllinux*"] test-command = "python -m pytest {project}/tests/unit || cd ." test-extras = ["test", "io"] + +[tool.pytest.ini_options] +datadir = "tests/datadir" diff --git a/setup.cfg b/setup.cfg index 9800fcda2..253686c85 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,10 +15,6 @@ classifiers = Operating System :: POSIX :: Linux Natural Language :: English Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 @@ -40,7 +36,8 @@ packages = install_requires = numpy - scipy >= 1.6 + scipy >= 1.6;python_version<='3.9' + scipy >= 1.14.1;python_version>='3.10' [options.extras_require] coverage = @@ -51,8 +48,11 @@ docs = sphinx io = h5py + gmsh test = pytest + pytest-regressions + pandas [sdist] formats = zip, gztar diff --git a/tests/datadir/.gitignore b/tests/datadir/.gitignore new file mode 100644 index 000000000..5f98a4491 --- /dev/null +++ b/tests/datadir/.gitignore @@ -0,0 +1 @@ +*.obtained.* \ No newline at end of file diff --git a/tests/datadir/test_many.npz b/tests/datadir/test_many.npz new file mode 100644 index 000000000..b0b317ad7 Binary files /dev/null and b/tests/datadir/test_many.npz differ diff --git a/tests/unit/test_special.py b/tests/unit/test_special.py index 01850ae3b..2328e81db 100644 --- a/tests/unit/test_special.py +++ b/tests/unit/test_special.py @@ -4,6 +4,7 @@ import treams.special as sc import treams.special.cython_special as cs +from pytest_regressions.ndarrays_regression import NDArraysRegressionFixture def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): @@ -15,71 +16,29 @@ def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): class TestIncgamma: - def test_zero_real(self): - assert isclose(sc.incgamma(0, 1.5), 0.10001958240663263, rel_tol=EPSSQ) - - ## Failing ## - def test_exp1(self): - assert isclose( - ssc.exp1(2 + 4j), - 0.006575211740584215 + 0.0261438237000811j, - rel_tol=EPSSQ, - ) - - ## Failing ## - def test_zero_complex(self): - assert isclose( - sc.incgamma(0, 2 + 4j), - 0.006575211740584215 + 0.0261438237000811j, - rel_tol=EPSSQ, - ) - - def test_zero_negreal(self): - assert isclose( - sc.incgamma(0, -3 + 0.0j), - -9.933832570625414 - 3.141592653589793j, - rel_tol=EPSSQ, - ) - - def test_zero_negreal_branch(self): - assert isclose( - sc.incgamma(0, complex(-3, -0.0)), - -9.933832570625414 + 3.141592653589793j, - rel_tol=EPSSQ, - ) - - def test_half_real(self): - assert isclose(sc.incgamma(0.5, 1.5), 0.1475825132040964, rel_tol=EPSSQ) - - def test_half_complex(self): - assert isclose( - sc.incgamma(0.5, 2 + 4j), - -0.01415763494202471 + 0.058731665238669344j, - rel_tol=EPSSQ, - ) - - def test_half_negreal(self): - assert isclose( - sc.incgamma(0.5, -3 + 0.0j), - 1.7724538509055152 - 14.626171384019093j, - rel_tol=EPSSQ, - ) - - def test_half_negreal_branch(self): - assert isclose( - sc.incgamma(0.5, complex(-3, -0.0)), - 1.7724538509055152 + 14.626171384019093j, - rel_tol=EPSSQ, - ) - - def test_one_real(self): - assert isclose(sc.incgamma(1, 1.5), 0.22313016014842982, rel_tol=EPSSQ) - - def test_one_complex(self): - assert isclose( - sc.incgamma(1, 2 + 4j), - -0.08846104456538201 + 0.10242208005667372j, - rel_tol=EPSSQ, + def test_many(self, ndarrays_regression: NDArraysRegressionFixture): + relaxed_tolerance = dict(atol=1e-7, rtol=1e-10) + ndarrays_regression.check( + { + 'zero_negreal': sc.incgamma(0, -3 + 0.0j), + 'zero_negreal_branch': sc.incgamma(0, complex(-3, -0.0)), + 'half_real': sc.incgamma(0.5, 1.5), + 'half_complex': sc.incgamma(0.5, 2 + 4j), + 'half_negreal': sc.incgamma(0.5, -3 + 0.0j), + 'half_negreal_branch': sc.incgamma(0.5, complex(-3, -0.0)), + 'one_real': sc.incgamma(1, 1.5), + 'one_complex': sc.incgamma(1, 2 + 4j), + 'zero_real': sc.incgamma(0, 1.5), + 'neg_complex': sc.incgamma(-10, 2 + 4j), + 'zero_complex': sc.incgamma(0, 2 + 4j), + 'exp1': ssc.exp1(2 + 4j), + }, + tolerances={ + 'neg_complex': relaxed_tolerance, + 'zero_complex': relaxed_tolerance, + 'exp1': relaxed_tolerance, + }, + default_tolerance=dict(atol=1e-7, rtol=EPSSQ) ) def test_one_negreal(self): @@ -111,14 +70,6 @@ def test_ten_negreal_branch(self): def test_neg_real(self): assert isclose(sc.incgamma(-10, 1.5), 0.0003324561166899859, rel_tol=EPSSQ) - ## Failing ## - def test_neg_complex(self): - assert isclose( - sc.incgamma(-10, 2 + 4j), - -3.109457703343637e-9 - 9.73849356067146e-10j, - rel_tol=EPSSQ, - ) - def test_neg_negreal(self): assert isclose( sc.incgamma(-10, -3 + 0.0j),