Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic test and CI #15

Merged
merged 6 commits into from
Jan 16, 2025
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
branches:
- main
- tests_ci
pull_request:
branches:
- main
- tests_ci

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests
run: |
python -m unittest discover -s tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add this to the README

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in bf1ee26


8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ p_lv = solver.model.commponents['lv'].P_i.values

## Example values pv loops for all 4 chambers:
![Example PV loops!](Figures/PV_loops.png)

## Run tests

You can run locally the tests by running the following command:
```bash
python -m unittest discover -s tests
```
there is also a autamtated test pipeline that runs the tests on every push to the repository (see [here](.github/workflows/ci.yml)).
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ matplotlib==3.8.2
numba==0.59.0
numpy==1.26.4
pandas==2.2.1
pandera==0.18.0
pandera==0.22.1
scipy==1.12.0
joblib==1.4.2
tdqm==0.0.1
38 changes: 38 additions & 0 deletions tests/test_NaghaviModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest
from ModularCirc.Models.NaghaviModel import NaghaviModelParameters, NaghaviModel
from ModularCirc.Solver import Solver

class TestModularCirc(unittest.TestCase):

def setUp(self):
self.time_setup_dict = {
'name': 'TimeTest',
'ncycles': 40,
'tcycle': 1.0,
'dt': 0.001,
'export_min': 1
}
self.parobj = NaghaviModelParameters()
self.model = NaghaviModel(time_setup_dict=self.time_setup_dict, parobj=self.parobj)
self.solver = Solver(model=self.model)
self.solver.setup()

def test_model_initialization(self):
self.assertIsInstance(self.model, NaghaviModel)
self.assertTrue(hasattr(self.solver.model, 'commponents'))
self.assertIn('lv', self.solver.model.commponents)
self.assertEqual( self.solver.model.commponents['lv'].E_pas, self.parobj.components['lv']['E_pas'])
self.assertEqual( self.solver.model.commponents['ao'].R, self.parobj.components['ao']['r'])


def test_solver_initialization(self):
self.assertIsInstance(self.solver, Solver)
self.assertEqual(self.solver.model, self.model)

def test_solver_run(self):
self.solver.solve()
self.assertTrue(len(self.solver.model.commponents['lv'].V.values) > 0)
self.assertTrue(len(self.solver.model.commponents['lv'].P_i.values) > 0)

if __name__ == '__main__':
unittest.main()
Loading