Skip to content

Commit

Permalink
modified tests to include dispatch entry points api
Browse files Browse the repository at this point in the history
  • Loading branch information
santacodes committed Nov 10, 2024
1 parent 69d90da commit 2ae38db
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
from .pybamm_data import DataLoader

# Pybamm entry point API for parameter_sets and models
from .dispatch.entry_points import Model, parameter_sets
from .dispatch import parameter_sets, Model

# Fix Casadi import
import os
Expand Down
2 changes: 2 additions & 0 deletions src/pybamm/dispatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .entry_points import parameter_sets, models, Model

__all__ = [
"parameter_sets",
"models",
Expand Down
6 changes: 3 additions & 3 deletions src/pybamm/dispatch/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EntryPoint(Mapping):
>>> import pybamm
>>> list(pybamm.parameter_sets)
['Ai2020', 'Chen2020', ...]
>>> list(pybamm.models)
>>> list(pybamm.dispatch.models)
['SPM']
Get the docstring for a parameter set/model:
Expand All @@ -32,7 +32,7 @@ class EntryPoint(Mapping):
See also: :ref:`adding-parameter-sets`
>>> print(pybamm.models.get_docstring("SPM"))
>>> print(pybamm.dispatch.models.get_docstring("SPM"))
<BLANKLINE>
Single Particle Model (SPM) of a lithium-ion battery, from
:footcite:t:`Marquis2019`.
Expand Down Expand Up @@ -136,7 +136,7 @@ def Model(model: str): # doctest: +SKIP
--------
Listing available models:
>>> import pybamm
>>> list(pybamm.models)
>>> list(pybamm.dispatch.models)
['SPM']
>>> pybamm.Model('SPM') # doctest: +SKIP
<pybamm.models.full_battery_models.lithium_ion.spm.SPM object>
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_parameters/test_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ def test_iter(self):
assert isinstance(k, str)


class TestModelSets:
class TestModelEntryPoints:
def test_all_registered(self):
"""Check that all models have been registered with the
``pybamm_models`` entry point"""
known_entry_points = set(
ep.name for ep in pybamm.model_sets.get_entries("pybamm_models")
ep.name for ep in pybamm.dispatch.models.get_entries("pybamm_models")
)
assert set(pybamm.model_sets.keys()) == known_entry_points
assert len(known_entry_points) == len(pybamm.model_sets)
assert set(pybamm.dispatch.models.keys()) == known_entry_points
assert len(known_entry_points) == len(pybamm.dispatch.models)

def test_get_docstring(self):
"""Test that :meth:`pybamm.model_sets.get_doctstring` works"""
docstring = pybamm.model_sets.get_docstring("SPM")
"""Test that :meth:`pybamm.dispatch.models.get_doctstring` works"""
docstring = pybamm.dispatch.models.get_docstring("SPM")
print(docstring)
assert re.search(
"Single Particle Model",
Expand All @@ -61,5 +61,5 @@ def test_get_docstring(self):

def test_iter(self):
"""Test that iterating `pybamm.models` iterates over keys"""
for k in pybamm.model_sets:
for k in pybamm.dispatch.models:
assert isinstance(k, str)

0 comments on commit 2ae38db

Please sign in to comment.