Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fccoelho committed Dec 18, 2024
1 parent e79687e commit 18beb7e
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 64 deletions.
42 changes: 18 additions & 24 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,24 @@ on:
branches: [ master ]

jobs:
build:

uv-example:
name: python
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"

- name: Install the project
run: uv sync --all-extras --dev

- name: Run tests
# For example, using `pytest`
run: uv run pytest tests
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Simple SIR simulation

```python
from epimodels.continuous.models import SIR

model = SIR()
model([1000, 1, 0], [0, 50], 1001, {'beta': 2, 'gamma': .1})
model.plot_traces()
Expand Down
3 changes: 2 additions & 1 deletion docs/Examples/Continuous_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"outputs": [],
"source": [
"import epimodels.continuous.models as CM"
"\n",
"import epimodels as CM"
]
},
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
u"""
"""
Created on 29/10/18
by fccoelho
license: GPL V3 or Later
"""

from .models import *
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
by fccoelho
license: GPL V3 or Later
"""
from .models import *

File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ dependencies = [
"sphinx>=8.1.3",
"sympy>=1.13.3",
]
packages = ["epimodels"]

[project.urls]
Homepage = "https://github.com/fccoelho/epimodels"
Documentation = "https://epimodels.readthedocs.io"
#packages = [{ include = "epimodels" }]


[tool.uv]
dev-dependencies = [
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
11 changes: 0 additions & 11 deletions tests/conftest.py

This file was deleted.

2 changes: 2 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import unittest
import sys
sys.path.append('..')
from epimodels.continuous import models as cm
from epimodels.discrete import models as dm

Expand Down
20 changes: 9 additions & 11 deletions tests/test_continuous_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
__author__ = 'fccoelho'

import unittest
import pytest
import sys
sys.path.append('..')
from matplotlib import pyplot as P

from epimodels.continuous.models import *
from epimodels.continuous import (SIS, SIR, SIR1D, SIRS, SEIR, SEQIAHR)


def test_SIR():
Expand All @@ -13,7 +11,7 @@ def test_SIR():
assert len(model.traces) == 4
# assert len(model.traces['time']) == 50
model.plot_traces()
P.show()
# P.show()

def test_SIR_with_t_eval():
model = SIR()
Expand All @@ -27,15 +25,15 @@ def test_SIR1D():
# assert len(model.traces['R']) == 500
assert len(model.traces) == 2
model.plot_traces()
P.show()
# P.show()

def test_SIS():
model = SIS()
model([1000, 1], [0, 50], 1001, {'beta': 2, 'gamma': .1})
assert len(model.traces) == 3
# assert len(model.traces['time']) == 50
model.plot_traces()
P.show()
# P.show()


def test_SIRS():
Expand All @@ -44,7 +42,7 @@ def test_SIRS():
assert len(model.traces) == 4
# assert len(model.traces['time']) == 50
model.plot_traces()
P.show()
# P.show()


def test_SEIR():
Expand All @@ -54,7 +52,7 @@ def test_SEIR():
assert len(model.traces) == 5 # state variables plus time
# assert len(model.traces['time']) == 50
model.plot_traces()
P.show()
# P.show()


def test_SEQIAHR():
Expand All @@ -68,7 +66,7 @@ def test_SEQIAHR():
assert len(model.traces) == 9 # state variables plus time
# assert len(model.traces['time']) == 50
model.plot_traces()
P.show()
# P.show()

# def test_SIS_with_cache():
# model = SIS()
Expand Down
29 changes: 15 additions & 14 deletions tests/test_discrete_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
__author__ = 'fccoelho'

import pytest
# import pyximport; pyximport.install(pyimport=True)
from epimodels.discrete.models import (DiscreteModel, Influenza, SIS, SIR, SEIS, SEIR,
SIpRpS, SEIpRpS, SIpR, SEIpR, SIRS, SEQIAHR)
import sys
sys.path.append('..')
from epimodels.discrete import (DiscreteModel, Influenza, SIS, SIR, SEIS, SEIR,
SIpRpS, SEIpRpS, SIpR, SEIpR, SIRS, SEQIAHR)
from matplotlib import pyplot as P


Expand All @@ -13,7 +14,7 @@ def test_SIS():
assert len(modelsis.traces) == 3
assert len(modelsis.traces['time']) == 50
modelsis.plot_traces()
P.show()
# P.show()
assert isinstance(modelsis, DiscreteModel)


Expand All @@ -23,7 +24,7 @@ def test_SIR():
assert len(modelsir.traces) == 4
assert len(modelsir.traces['time']) == 500
modelsir.plot_traces()
P.show()
# P.show()
assert isinstance(modelsir, DiscreteModel)


Expand Down Expand Up @@ -52,7 +53,7 @@ def test_FLU():
assert len(modelflu.traces['time']) == 50
print(list(modelflu.traces.keys()))
modelflu.plot_traces()
P.show()
# P.show()
assert isinstance(modelflu, DiscreteModel)


Expand All @@ -62,7 +63,7 @@ def test_SEIS():
assert len(modelseis.traces) == 4
assert len(modelseis.traces['time']) == 50
modelseis.plot_traces()
P.show()
# P.show()
assert isinstance(modelseis, DiscreteModel)


Expand All @@ -73,7 +74,7 @@ def test_SEIR():
assert len(modelseir.traces) == 5
assert len(modelseir.traces['time']) == tsteps[1]
modelseir.plot_traces()
P.show()
# P.show()
assert isinstance(modelseir, DiscreteModel)


Expand All @@ -84,7 +85,7 @@ def test_SIpRpS():
assert len(modelsiprps.traces) == 4
assert len(modelsiprps.traces['time']) == tsteps[1]
modelsiprps.plot_traces()
P.show()
# P.show()
assert isinstance(modelsiprps, DiscreteModel)


Expand All @@ -95,7 +96,7 @@ def test_SEIpRpS():
assert len(modelseiprps.traces) == 5
assert len(modelseiprps.traces['time']) == tsteps[1]
modelseiprps.plot_traces()
P.show()
# P.show()
assert isinstance(modelseiprps, DiscreteModel)


Expand All @@ -105,7 +106,7 @@ def test_SIpR():
assert len(modelsipr.traces) == 4
assert len(modelsipr.traces['time']) == 50
modelsipr.plot_traces()
P.show()
# P.show()
assert isinstance(modelsipr, DiscreteModel)

def test_SEIpR():
Expand All @@ -115,7 +116,7 @@ def test_SEIpR():
assert len(modelseipr.traces) == 5
assert len(modelseipr.traces['time']) == tsteps[1]
modelseipr.plot_traces()
P.show()
# P.show()
assert isinstance(modelseipr, DiscreteModel)

def test_SIRS():
Expand All @@ -124,7 +125,7 @@ def test_SIRS():
assert len(modelsirs.traces) == 4
assert len(modelsirs.traces['time']) == 50
modelsirs.plot_traces()
P.show()
# P.show()
assert isinstance(modelsirs, DiscreteModel)

def test_SEQIAHR():
Expand All @@ -135,5 +136,5 @@ def test_SEQIAHR():
})
assert len(model.traces) == 9
model.plot_traces()
P.show()
# P.show()
assert isinstance(model, DiscreteModel)

0 comments on commit 18beb7e

Please sign in to comment.