Skip to content

Commit 68d33c5

Browse files
committed
fix override on root state, add check_func test
1 parent 3389753 commit 68d33c5

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

pythonwhat/check_funcs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ def override(solution, state=None):
216216
new_ast = node
217217
break
218218

219+
kwargs = state.messages[-1] if state.messages else {}
219220
child = state.to_child_state(
220221
solution_subtree = new_ast,
221222
student_subtree = state.student_tree,
222223
highlight = state.highlight,
223-
append_message = {'msg': "", 'kwargs': state.messages[-1]['kwargs']}
224+
append_message = {'msg': "", 'kwargs': kwargs}
224225
)
225226

226227
return child

tests/test_test_function.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,17 +757,26 @@ def test_pass_sig_false(self):
757757
sct_payload = helper.run(self.data)
758758
self.assertTrue(sct_payload['correct'])
759759

760-
@unittest.skip("TODO: implement override")
761760
def test_pass_sig_false_override(self):
762761
self.setup_color()
763-
self.data["DC_SCT"].replace('color', 'c')
762+
self.data["DC_CODE"] = self.data["DC_CODE"].replace('color', 'c')
764763
self.data['DC_SCT'] = """
765-
Ex().check_function('f', 0, signature=False).override("f(c = 'blue')").check_args('c').has_equal_ast()
764+
Ex().override("f(c = 'blue')").check_function('f', 0, signature=False).check_args('c').has_equal_ast()
766765
"""
767766

768767
sct_payload = helper.run(self.data)
769768
self.assertTrue(sct_payload['correct'])
770769

770+
@unittest.skip("TODO: override code isn't parsed, so can't get args part")
771+
def test_pass_sig_false_override_after_check(self):
772+
self.setup_color()
773+
self.data["DC_CODE"] = self.data["DC_CODE"].replace('color', 'c')
774+
self.data['DC_SCT'] = """
775+
Ex().check_function('f', 0, signature=False).override("f(c = 'blue')").check_args('c').has_equal_ast()
776+
"""
777+
sct_payload = helper.run(self.data)
778+
self.assertTrue(sct_payload['correct'])
779+
771780

772781
class TestFunctionComplexArgs(unittest.TestCase):
773782
def setUp(self):

0 commit comments

Comments
 (0)