Skip to content

Commit

Permalink
Add test for get_form output
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Dec 5, 2023
1 parent 38e4a1c commit 3216fde
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions goalie/go_mesh_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def indicate_errors(
forms = mesh_seq_e.form(i, mapping)
if not isinstance(forms, dict):
raise TypeError(
"The function defined by get_form should return a dictionary, not a"
f" {type(forms)}."
"The function defined by get_form should return a dictionary"
f", not type '{type(forms)}'."
)

# Loop over each strongly coupled field
Expand Down
26 changes: 26 additions & 0 deletions test_adjoint/test_mesh_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,29 @@ def test_enrichment_transfer(
target = Function(mesh_seq_e.function_spaces["field"][0])
transfer(source, target)
self.assertAlmostEqual(norm(source), norm(target))


class TestErrorIndication(TrivalGoalOrientedBaseClass):
"""
Unit tests for :meth:`indicate_errors`.
"""

@staticmethod
def constant_qoi(mesh_seq, solutions, index):
R = FunctionSpace(mesh_seq[index], "R", 0)
return lambda: Function(R).assign(1) * dx

def test_form_error(self):
mesh_seq = GoalOrientedMeshSeq(
TimeInstant([]),
UnitTriangleMesh(),
get_qoi=self.constant_qoi,
qoi_type="steady",
)
mesh_seq._get_function_spaces = lambda _: {}
mesh_seq._get_form = lambda _: lambda *_: 0
mesh_seq._get_solver = lambda _: lambda *_: {}
with self.assertRaises(TypeError) as cm:
mesh_seq.fixed_point_iteration(lambda *_: [False])
msg = "The function defined by get_form should return a dictionary, not type '<class 'int'>'."
self.assertEqual(str(cm.exception), msg)

0 comments on commit 3216fde

Please sign in to comment.