Skip to content

Commit a5ec807

Browse files
committed
Fix test_unit_xml_tests for new case.get_value call
The previous commit introduced an extra call to case.get_value to get SYSTEM_TESTS_DIR for component=allactive. This broke the mock get_value returns. To make these returns more robust, I have changed the way they're done to be based on a dictionary lookup rather than an ordered list. This kind of replacement should probably be done for other case.get_value mocks. Note that I identified the argument values that needed to be handled with this code: for i, call in enumerate(case.get_value.call_args_list): print(f" Call {i}: {call}")
1 parent 466f7bc commit a5ec807

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

CIME/tests/test_unit_xml_tests.py

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,27 @@ def test_support_single_exe(self, _setup_cases_if_not_yet_done):
3232

3333
case.get_compset_components.return_value = ()
3434

35-
case.get_value.side_effect = (
36-
"SMS",
37-
tdir,
38-
f"{caseroot}",
39-
"SMS.f19_g16.S",
40-
"cpl",
41-
"SMS.f19_g16.S",
42-
f"{caseroot}",
43-
"SMS.f19_g16.S",
44-
)
35+
def fake_get_value(item, attribute=None):
36+
simple_lookup = {
37+
"TESTCASE": "SMS",
38+
"CASEROOT": f"{caseroot}",
39+
"CASEBASEID": "SMS.f19_g16.S",
40+
"COMP_INTERFACE": "cpl",
41+
"DRV_RESTART_POINTER": None,
42+
}
43+
if item in simple_lookup:
44+
return simple_lookup[item]
45+
elif item == "SYSTEM_TESTS_DIR":
46+
if attribute["component"] == "any":
47+
return tdir
48+
else:
49+
return None
50+
51+
raise KeyError(
52+
f"Unmocked call: case.get_value({item}, attribute={attribute})"
53+
)
54+
55+
case.get_value.side_effect = fake_get_value
4556

4657
tests = Tests()
4758

@@ -65,17 +76,28 @@ def test_support_single_exe_error(self, _setup_cases_if_not_yet_done):
6576

6677
case.get_compset_components.return_value = ()
6778

68-
case.get_value.side_effect = (
69-
"ERP",
70-
tdir,
71-
f"{caseroot}",
72-
"ERP.f19_g16.S",
73-
"cpl",
74-
None,
75-
"ERP.f19_g16.S",
76-
f"{caseroot}",
77-
"ERP.f19_g16.S",
78-
)
79+
def fake_get_value(item, attribute=None):
80+
simple_lookup = {
81+
"TESTCASE": "ERP",
82+
"CASEROOT": f"{caseroot}",
83+
"CASEBASEID": "ERP.f19_g16.S",
84+
"CASE": "ERP.f19_g16.S",
85+
"COMP_INTERFACE": "cpl",
86+
"DRV_RESTART_POINTER": None,
87+
}
88+
if item in simple_lookup:
89+
return simple_lookup[item]
90+
elif item == "SYSTEM_TESTS_DIR":
91+
if attribute["component"] == "any":
92+
return tdir
93+
else:
94+
return None
95+
96+
raise KeyError(
97+
f"Unmocked call: case.get_value({item}, attribute={attribute})"
98+
)
99+
100+
case.get_value.side_effect = fake_get_value
79101

80102
tests = Tests()
81103

0 commit comments

Comments
 (0)