Skip to content

Commit

Permalink
added type check
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Jun 4, 2024
1 parent ede311e commit 2f3c60d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ def T(self, value):
self._T = value
elif isinstance(value, (int, float, sp.Expr)):
self._T = festim.Temperature(value)
else:
raise TypeError(
"accepted types for T attribute are int, float, sympy.Expr or festim.Temperature"
)

def attribute_source_terms(self):
"""Assigns the source terms (in self.sources) to the correct field
Expand Down
15 changes: 15 additions & 0 deletions test/simulation/test_initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,18 @@ def test_error_is_raised_when_no_temp():

with pytest.raises(AttributeError, match="Temperature is not defined"):
my_model.initialise()


@pytest.mark.parametrize("value", ["coucou", [0, 0]])
def test_wrong_type_temperature(value):
"""
Creates a Simulation object and checks that a TypeError is raised
when the T attribute is given a value of the wrong type
"""
my_model = F.Simulation()

with pytest.raises(
TypeError,
match="accepted types for T attribute are int, float, sympy.Expr or festim.Temperature",
):
my_model.T = value

0 comments on commit 2f3c60d

Please sign in to comment.