Skip to content

Commit

Permalink
Merge pull request #58 from RangamaniLabUCSD/finsberg/add-first-tests
Browse files Browse the repository at this point in the history
Add first unit tests
  • Loading branch information
emmetfrancis authored Mar 2, 2023
2 parents 7575ae8 + 7e087cb commit c30a09e
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 152 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/run_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Run examples

on:
push:
# The CI is executed on every push on every branch
branches:
- development
pull_request:
# The CI is executed on every pull request to the main branch
branches:
- development

schedule:
# The CI is executed every day at 8am
- cron: "0 8 * * *"
jobs:
check-code:
runs-on: ubuntu-22.04
# Runs against FEniCS main branch built the 16-01-2023
container: ghcr.io/scientificcomputing/fenics-gmsh:2023-02-17a
steps:
# This action sets the current path to the root of your github repo
- uses: actions/checkout@v3

- name: "Install code"
run: python3 -m pip install --no-binary=h5py .[dev] jupytext

- name: Run example 1
run: |
cd examples/example1/
jupytext example1.ipynb --to py
python3 example1.py
# - name: Run tests
# run: |
# cd tests/
# python3 -m pytest .
13 changes: 3 additions & 10 deletions .github/workflows/test_fenics_stubs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ jobs:
- uses: actions/checkout@v3

- name: "Install code"
run: python3 -m pip install --no-binary=h5py .[dev] jupytext
run: python3 -m pip install .[test]

- name: Run example 1
- name: Run tests
run: |
cd examples/example1/
jupytext example1.ipynb --to py
python3 example1.py
# - name: Run tests
# run: |
# cd tests/
# python3 -m pytest .
python3 -m pytest
10 changes: 10 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[pytest]
addopts = --cov=stubs --cov-report html --cov-report term-missing -v
testpaths =
tests
integration
markers =
stubs_model_init: tests for model initialiation (deselect with '-m "not slow"')
filterwarnings =
ignore::UserWarning
ignore::DeprecationWarning
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
"termplotlib",
"meshio",
"gmsh",
"h5py"
"h5py",
], # Required packages, pulls from pip if needed; do not use for Conda deployment
# python_requires=">=3.5", # Python version restrictions
extras_require={"docs": [
"jupyter-book@git+https://github.com/executablebooks/jupyter-book.git@master"]},
extras_require={
"docs": ["jupyter-book"],
"test": ["pytest", "pytest-cov"],
},
# Manual control if final package is compressible or not, set False to prevent the .egg from being made
# zip_safe=False,
)
7 changes: 0 additions & 7 deletions stubs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ class Config():
directory: OutputConfig = field(default_factory=OutputConfig)
probe_plot: Dict[str, npt.NDArray[np.float64]] = field(default_factory=dict)

def __init__(self):
self.solver = SolverConfig()
self.flags = FlagsConfig()
self.directory = OutputConfig()
self.loglevel = LogLevelConfig()
self.plot_settings = PlottingConfig()

@property
def reaction_database(self) -> Dict[str, str]:
"""
Expand Down
3 changes: 1 addition & 2 deletions stubs/model_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from sympy.parsing.sympy_parser import parse_expr
from tabulate import tabulate

import stubs.common as common

from . import common
from .common import _fancy_print as fancy_print
from .common import (np_smart_hstack, pint_quantity_to_unit,
pint_unit_to_quantity, sub)
Expand Down
66 changes: 66 additions & 0 deletions tests/test_compartment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pytest

import stubs


@pytest.fixture(name="Cyto_kwargs")
def example_compartment():
kwargs = dict(
dimensionality=3,
name="Cyto",
compartment_units=stubs.unit.um,
cell_marker=1,
)

Cyto = stubs.model_assembly.Compartment(**kwargs)
return (Cyto, kwargs)


def test_Compartment_initialization(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs

assert Cyto.V is None
assert Cyto.cell_marker == kwargs["cell_marker"]
assert Cyto.dimensionality == kwargs["dimensionality"]
assert Cyto.name == kwargs["name"]
assert Cyto.num_dofs == 0
assert Cyto.num_dofs_local == 0
assert Cyto.species == {}
assert Cyto.u == {}
assert Cyto.v is None


@pytest.mark.xfail
def test_Compartment_access_dolfin_mesh(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs
Cyto.dolfin_mesh


@pytest.mark.xfail
def test_Compartment_access_mesh_id(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs
Cyto.mesh_id


@pytest.mark.xfail
def test_Compartment_access_num_cells(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs
Cyto.num_cells


@pytest.mark.xfail
def test_Compartment_access_num_facets(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs
Cyto.num_facets


@pytest.mark.xfail
def test_Compartment_access_num_vertices(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs
Cyto.num_vertices


@pytest.mark.xfail
def test_Compartment_access_nvolume(Cyto_kwargs):
Cyto, kwargs = Cyto_kwargs
Cyto.nvolume
75 changes: 0 additions & 75 deletions tests/test_dolfin_subdomains.py

This file was deleted.

65 changes: 65 additions & 0 deletions tests/test_species.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import math

import pytest

import stubs


@pytest.fixture(name="A_kwargs")
def example_species():
kwargs = dict(
concentration_units=stubs.unit.uM,
diffusion_units=stubs.unit.um**2 / stubs.unit.sec,
initial_condition=0.01,
D=2.0,
name="A",
compartment_name="Cyto",
group="Some group",
)

A = stubs.model_assembly.Species(**kwargs)
return (A, kwargs)


def test_Species_initialization(A_kwargs):
A, kwargs = A_kwargs
assert A.name == kwargs["name"]
assert A.latex_name == kwargs["name"]
assert str(A.sym) == kwargs["name"]

assert math.isclose(A.initial_condition, kwargs["initial_condition"])
assert (
A.initial_condition_quantity
== kwargs["initial_condition"] * kwargs["concentration_units"]
)
assert A.concentration_units == stubs.common.pint_unit_to_quantity(
kwargs["concentration_units"]
)
assert math.isclose(A.D, kwargs["D"])
assert A.diffusion_units == stubs.common.pint_unit_to_quantity(
kwargs["diffusion_units"]
)
assert A.D_quantity == kwargs["D"] * kwargs["diffusion_units"]

assert A.compartment_name == kwargs["compartment_name"]
assert A.group == kwargs["group"]
assert A.dof_map is None
assert A.ut is None
assert A.v is None
assert A.u == {}
assert A.is_an_added_species is False
assert A.is_in_a_reaction is False


@pytest.mark.xfail
def test_access_vscalar(A_kwargs):
A, kwargs = A_kwargs
# We should have proper error handling here
A.vscalar


@pytest.mark.xfail
def test_access_dolfin_quatity(A_kwargs):
A, kwargs = A_kwargs
# We should have proper error handling here
A.dolfin_quantity
Loading

0 comments on commit c30a09e

Please sign in to comment.