Skip to content

Commit f748a81

Browse files
fix doc errors
1 parent 1afccd0 commit f748a81

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

idaes/core/util/testing.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -534,19 +534,17 @@ def assert_solution_equivalent(blk, expected_results):
534534
535535
Args:
536536
blk: Pyomo block on which variables/expressions being tested are located
537-
expected_results: Dictionary of the form:
538-
{
539-
indexed_var_name: {
540-
index_1: (value, rel_tol, abs_tol),
541-
index_2: (value, rel_tol, abs_tol),
542-
...
537+
expected_results: Dictionary of the form::
538+
539+
expected_results = {
540+
"indexed_var_name": {
541+
"index_1": (value, rel_tol, abs_tol),
542+
"index_2": (value, rel_tol, abs_tol),
543+
}
544+
"unindexed_var_name": {
545+
None: (value, rel_tol, abs_tol)
546+
}
543547
}
544-
unindexed_var_name: {
545-
# Unindexed vars pass None as the index
546-
None: (value, rel_tol, abs_tol)
547-
}
548-
...
549-
}
550548
"""
551549

552550
n_failures = 0
@@ -575,38 +573,39 @@ def assert_solution_equivalent(blk, expected_results):
575573
failures.append(failure_msg)
576574
continue
577575

578-
for index, (expected_value, rel, abs) in expected_values_dict.items():
579-
absent_index = False
576+
for index, (expected_value, rel_tol, abs_tol) in expected_values_dict.items():
580577
is_close = False
581578
if index is None:
582579
component_to_test = obj
583580
else:
584581
if index in obj:
585582
component_to_test = obj[index]
586583
else:
587-
absent_index = True
588-
if not absent_index:
584+
component_to_test = None
585+
if component_to_test is not None:
589586
actual_value = value(component_to_test)
590587

591588
# Determine if the values are approximately equal
592-
if actual_value == pytest.approx(expected_value, rel=rel, abs=abs):
589+
if actual_value == pytest.approx(
590+
expected_value, rel=rel_tol, abs=abs_tol
591+
):
593592
is_close = True
594-
if (absent_index or not is_close) and not recorded_var:
593+
if (component_to_test is None or not is_close) and not recorded_var:
595594
failures.append(f" - {obj_type}: {name}")
596595
recorded_var = True
597-
if absent_index:
596+
if component_to_test is None:
598597
failure_msg = f" Index: {index} is absent"
599598
failures.append(failure_msg)
600599
n_failures += 1
601600
continue
602601

603602
# If the comparison fails, record the details
604603
if not is_close:
605-
if rel is not None:
606-
n_sig_figs = ceil(-log10(rel)) + 1
604+
if rel_tol is not None:
605+
n_sig_figs = ceil(-log10(rel_tol)) + 1
607606
format_spec = "." + str(n_sig_figs) + "e"
608-
elif abs is not None:
609-
n_sig_figs = ceil(-log10(abs)) + 1
607+
elif abs_tol is not None:
608+
n_sig_figs = ceil(-log10(abs_tol)) + 1
610609
format_spec = "." + str(n_sig_figs) + "f"
611610
else:
612611
format_spec = ".7e"

0 commit comments

Comments
 (0)