Skip to content

Commit 9e5ddc8

Browse files
committed
Add gauge check
1 parent 56e8421 commit 9e5ddc8

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/python/classic/test.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,56 @@ def check_frame(self, frame, indices=(0), regression_path=None, save=False, **kw
133133
# Compare data
134134
kwargs.setdefault('rtol', 1e-14)
135135
kwargs.setdefault('atol', 1e-8)
136-
np.testing.assert_allclose(sol_sums, regression_sum, **kwargs)
136+
np.testing.assert_allclose(sol_sums, regression_sum, **kwargs)
137+
138+
139+
def check_gauge(self, gauge_id, indices=(0), regression_path=None, save=False, **kwargs):
140+
r"""Basic test to assert gauge equality
141+
142+
:Input:
143+
- *save* (bool) - If *True* will save the output from this test to
144+
the file *regresion_data.txt*. Default is *False*.
145+
- *indices* (tuple) - Contains indices to compare in the gague
146+
comparison. Defaults to *(0)*.
147+
- *rtol* (float) - Relative tolerance used in the comparison, default
148+
is *1e-14*. Note that the old *tolerance* input is now synonymous
149+
with this parameter.
150+
- *atol* (float) - Absolute tolerance used in the comparison, default
151+
is *1e-08*.
152+
"""
153+
154+
if not(isinstance(indices, tuple) or isinstance(indices, list)):
155+
indices = tuple(indices)
156+
157+
if not regression_path:
158+
regression_path = self.test_path / "regression_data"
159+
160+
# Load test output data
161+
gauge = gauges.GaugeSolution(gauge_id, path=self.temp_path)
162+
163+
# Load regression data
164+
if save:
165+
shutil.copy(self.temp_path / f"gauge{str(gauge_id).zfill(5)}.txt",
166+
regression_path)
167+
claw_git_status.make_git_status_file(outdir=regression_path)
168+
regression_gauge = gauges.GaugeSolution(gauge_id, path=regression_path)
169+
170+
# Compare data
171+
kwargs.setdefault('rtol', 1e-14)
172+
kwargs.setdefault('atol', 1e-8)
173+
try:
174+
for n in indices:
175+
np.testing.assert_allclose(gauge.q[n, :],
176+
regression_gauge.q[n, :],
177+
**kwargs)
178+
except AssertionError as e:
179+
err_msg = "\n".join((e.args[0],
180+
"Gauge Match Failed for gauge = %s" % gauge_id))
181+
err_msg = "\n".join((err_msg, " failures in fields:"))
182+
failure_indices = []
183+
for n in indices:
184+
if ~np.allclose(gauge.q[n, :], regression_gauge.q[n, :],
185+
**kwargs):
186+
failure_indices.append(str(n))
187+
index_str = ", ".join(failure_indices)
188+
raise AssertionError(" ".join((err_msg, index_str)))

0 commit comments

Comments
 (0)