Skip to content

Commit

Permalink
Add more base_model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaCourtier committed Jun 13, 2024
1 parent 10df0d2 commit 467f1f4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ def test_build(self, model):

@pytest.mark.unit
def test_rebuild(self, model):
# Test rebuild before build
with pytest.raises(
ValueError, match="Model must be built before calling rebuild"
):
model.rebuild()

model.build()
initial_built_model = model._built_model
assert model._built_model is not None

model.set_params()
assert model.model_with_set_params is not None

# Test that the model can be built again
model.rebuild()
rebuilt_model = model._built_model
Expand Down Expand Up @@ -252,6 +261,12 @@ def test_reinit(self):
k = 0.1
y0 = 1
model = ExponentialDecay(pybamm.ParameterValues({"k": k, "y0": y0}))

with pytest.raises(
ValueError, match="Model must be built before calling get_state"
):
model.get_state({"k": k, "y0": y0}, 0, np.array([0]))

model.build()
state = model.reinit(inputs={})
np.testing.assert_array_almost_equal(state.as_ndarray(), np.array([[y0]]))
Expand Down

0 comments on commit 467f1f4

Please sign in to comment.