Skip to content

Commit

Permalink
add: git action
Browse files Browse the repository at this point in the history
  • Loading branch information
khalsz committed Dec 31, 2024
1 parent baf7477 commit ad4055a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI workflow

# We can specify which Github events will trigger a CI build
on:
push:
branches: [main, develop]
pull_request:
branches:
- main
# 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: ubuntu-latest
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: "3.9"
- 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
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))

0 comments on commit ad4055a

Please sign in to comment.