Skip to content

Commit

Permalink
better test
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Nov 2, 2023
1 parent 93704ef commit 1f7bcd0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions festim/boundary_conditions/dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def create_value(

if "t" in arguments and "x" not in arguments and "T" not in arguments:
# only t is an argument
if isinstance(self.value(t=float(t)), Operator):
raise ValueError("wrong type for temperature")
if not isinstance(self.value(t=float(t)), (float, int)):
raise ValueError(
f"self.value should return a float or an int, not {type(self.value(t=float(t)))} "
)
self.value_fenics = F.as_fenics_constant(
mesh=mesh, value=self.value(t=float(t))
)
Expand Down
6 changes: 4 additions & 2 deletions festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ def define_temperature(self):
elif callable(self.temperature):
arguments = self.temperature.__code__.co_varnames
if "t" in arguments and "x" not in arguments and "T" not in arguments:
if isinstance(self.temperature(t=float(self.t)), Operator):
raise ValueError("wrong type for temperature")
if not isinstance(self.temperature(t=float(self.t)), (float, int)):
raise ValueError(
f"self.temperature should return a float or an int, not {type(self.temperature(t=float(self.t)))} "
)
# only t is an argument
self.temperature_fenics = F.as_fenics_constant(
mesh=self.mesh.mesh, value=self.temperature(t=float(self.t))
Expand Down
4 changes: 3 additions & 1 deletion test/test_dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ def test_define_value_error_if_ufl_conditional_t_only(value):

t = fem.Constant(mesh, 0.0)

with pytest.raises(ValueError, match="wrong type for temperature"):
with pytest.raises(
ValueError, match="self.value should return a float or an int, not "
):
bc.create_value(mesh=mesh, function_space=None, temperature=None, t=t)


Expand Down
4 changes: 3 additions & 1 deletion test/test_h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def test_define_temperature_error_if_ufl_conditional_t_only(input):

my_model.temperature = input

with pytest.raises(ValueError, match="wrong type for temperature"):
with pytest.raises(
ValueError, match="self.temperature should return a float or an int, not "
):
my_model.define_temperature()


Expand Down

0 comments on commit 1f7bcd0

Please sign in to comment.