diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..bcc6cd7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name: Test + +on: + push: + pull_request: + schedule: + - cron: '52 4 3 * *' # 4:52a on third day of the month + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + + test: + name: Run tests + if: + github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + + runs-on: ${{ matrix.os }} + + defaults: + run: + shell: bash -l {0} + + strategy: + matrix: + os: [ubuntu-latest] + python-version: ["3.14"] + + steps: + - uses: actions/checkout@v7 + + - name: Install Python ${{ matrix.python-version }} + uses: actions/setup-python@v7 + with: + python-version: ${{ matrix.python-version }} + + - name: Install package and dependencies + run: pip install .[testing] + + - name: Check example script + run: | + python -m diffusion_model > model.out + + - name: Check example notebook + run: | + pytest notebooks --nbmake --nbmake-timeout=3000 --nbmake-kernel=python3 -v + + - name: Run unit tests + run: | + pytest -v diff --git a/pyproject.toml b/pyproject.toml index 50243e2..a070fc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,5 +14,11 @@ dependencies = [ "numpy", ] +[project.optional-dependencies] +testing = [ + "pytest", + "nbmake", +] + [tool.setuptools] py-modules = ["diffusion_model"] diff --git a/tests/test_diffusion_model.py b/tests/test_diffusion_model.py index c0cbffc..2462d90 100644 --- a/tests/test_diffusion_model.py +++ b/tests/test_diffusion_model.py @@ -36,10 +36,10 @@ def test_time_step_decreases_with_diffusivity(): def test_step_like_is_array_of_float(): """Check profile is a numpy array of floats.""" z = step_like([1.0, 2.0, 3.0]) - return isinstance(z, np.ndarray) and np.issubdtype(z.dtype, np.floating) + assert isinstance(z, np.ndarray) and np.issubdtype(z.dtype, np.floating) z = step_like([1, 2, 3]) - return isinstance(z, np.ndarray) and np.issubdtype(z.dtype, np.floating) + assert isinstance(z, np.ndarray) and np.issubdtype(z.dtype, np.floating) def test_step_like_length():