Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI workflow

# We can specify which Github events will trigger a CI build
on:
push:
# now define a single job 'build' (but could define more, can be anything other than build)
jobs:
build:
# we can also specify the OS to run tests on
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
python-version: ["3.12", "3.10"]
steps:
# Next we need to checkout out repository, and set up Python
# A 'name' is just an optional label shown in the log - helpful to clarify progress - and can be anything
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt

- name: Test with Pytest
run: |
python -m pytest --cov=inflammation.models tests/test_models.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
*.pyc
*.egg-info
.pytest_cache
py_venv/
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
contourpy==1.3.0
coverage==7.6.1
cycler==0.12.1
fonttools==4.54.1
iniconfig==2.0.0
kiwisolver==1.4.7
matplotlib==3.9.2
numpy==2.1.2
packaging==24.1
pillow==10.4.0
pluggy==1.5.0
pyparsing==3.1.4
pytest==8.3.3
pytest-cov==5.0.0
python-dateutil==2.9.0.post0
six==1.16.0
74 changes: 74 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import numpy.testing as npt
import os
import pytest


def test_daily_mean_zeros():
Expand Down Expand Up @@ -37,3 +38,76 @@ def test_load_from_json(tmpdir):
temp_json_file.write('[{"observations":[1, 2, 3]},{"observations":[4, 5, 6]}]')
result = load_json(example_path)
npt.assert_array_equal(result, [[1, 2, 3], [4, 5, 6]])


def test_daily_max():
from inflammation.models import daily_max

test_input = np.array([[4,2,5],
[1,6,2],
[4,1,9]])

test_result = np.array([4,6,9])

npt.assert_array_equal(daily_max(test_input), test_result)


def test_daily_min():
from inflammation.models import daily_min
test_input = np.array([[4,-2,5],
[1,-6,2],
[-4,-1,9]])

test_result = np.array([-4,-6,2])


npt.assert_array_equal(daily_min(test_input), test_result)


def test_daily_min_string():
from inflammation.models import daily_min
with pytest.raises(TypeError):
expected_error = test_daily_min([['Hello', 'there'], ['General', 'Kenobi']])


@pytest.mark.parametrize(
"test, expected",
[
([[0,0], [0,0], [0,0]], [0,0]),
([[1,2], [3,4], [5,6]], [3,4])
]
)
def test_daily_mean(test, expected):
"""Test mean function works for array of zeroes and positive integers."""
from inflammation.models import daily_mean
npt.assert_array_equal(daily_mean(np.array(test)), np.array(expected))



@pytest.mark.parametrize(
"test, expected",
[
([ [0, 0, 0], [0, 0, 0], [0, 0, 0] ], [0, 0, 0]),
([ [4, 2, 5], [1, 6, 2], [4, 1, 9] ], [4, 6, 9]),
([ [4, -2, 5], [1, -6, 2], [-4, -1, 9] ], [4, -1, 9]),
]
)
def test_daily_max(test, expected):
from inflammation.models import daily_max
npt.assert_array_equal(daily_max(np.array(test)), np.array(expected))



@pytest.mark.parametrize(
"test, expected",
[
([ [0, 0, 0], [0, 0, 0], [0, 0, 0] ], [0, 0, 0]),
([ [4, 2, 5], [1, 6, 2], [4, 1, 9] ], [1, 1, 2]),
([ [4, -2, 5], [1, -6, 2], [-4, -1, 9] ], [-4, -6, 2])

]
)
def test_daily_min(test, expected):
from inflammation.models import daily_min

npt.assert_array_equal(daily_min(np.array(test)), np.array(expected))