@@ -19,6 +19,7 @@ def test_function(name,
1919 args_not_specified_msg = None ,
2020 incorrect_msg = None ,
2121 add_more = False ,
22+ highlight = False ,
2223 state = None ):
2324 """Test if function calls match.
2425
@@ -66,6 +67,8 @@ def test_function(name,
6667 rep = Reporter .active_reporter
6768 rep .set_tag ("fun" , "test_function" )
6869
70+ if not highlight : state .highlight = None
71+
6972 index = index - 1
7073
7174 eq_map = {"equal" : EqualTest }
@@ -128,7 +131,7 @@ def test_function(name,
128131 if feedback is None :
129132 if not args_not_specified_msg :
130133 args_not_specified_msg = dflt
131- feedback = Feedback (args_not_specified_msg , student_call )
134+ feedback = Feedback (args_not_specified_msg , student_call if highlight else None )
132135 success = False
133136 continue
134137
@@ -148,7 +151,8 @@ def test_function(name,
148151
149152 test = build_test (arg_student , arg_solution ,
150153 state ,
151- do_eval , eq_fun , msg , add_more = add_more )
154+ do_eval , eq_fun , msg , add_more = add_more ,
155+ highlight = arg_student if highlight else None )
152156 test .test ()
153157
154158 if not test .result :
@@ -170,7 +174,8 @@ def test_function(name,
170174
171175 test = build_test (key_student , key_solution ,
172176 state ,
173- do_eval , eq_fun , msg , add_more = add_more )
177+ do_eval , eq_fun , msg , add_more = add_more ,
178+ highlight = key_student if highlight else None )
174179 test .test ()
175180
176181 if not test .result :
@@ -197,6 +202,7 @@ def test_print(index = 1,
197202 params_not_matched_msg = "Have you correctly called `print()`?" ,
198203 params_not_specified_msg = "Have you correctly called `print()`?" ,
199204 incorrect_msg = "Have you printed out the correct object?" ,
205+ highlight = True ,
200206 state = None ):
201207 test_function_v2 ("print" ,
202208 index = index ,
@@ -207,7 +213,8 @@ def test_print(index = 1,
207213 not_called_msg = not_called_msg ,
208214 params_not_matched_msg = params_not_matched_msg ,
209215 params_not_specified_msg = params_not_specified_msg ,
210- incorrect_msg = incorrect_msg , state = state )
216+ incorrect_msg = incorrect_msg ,
217+ highlight = highlight , state = state )
211218 """Test print() calls
212219
213220 Utility function to test the print() function. For arguments, check test_function_v2()
@@ -224,6 +231,7 @@ def test_function_v2(name,
224231 params_not_specified_msg = None ,
225232 incorrect_msg = None ,
226233 add_more = False ,
234+ highlight = False ,
227235 state = None ):
228236 """Test if function calls match (v2).
229237
@@ -255,6 +263,11 @@ def test_function_v2(name,
255263 rep = Reporter .active_reporter
256264 rep .set_tag ("fun" , "test_function" )
257265
266+ # Note that this mutates state, which is bad. The easiest way to avoid this
267+ # would be to make a copy of state, but that would break blacklisting here,
268+ # which also requires state mutation.
269+ if not highlight : state .highlight = None
270+
258271 index = index - 1
259272 eq_map = {"equal" : EqualTest }
260273
@@ -342,7 +355,7 @@ def test_function_v2(name,
342355 sub_tests = [partial (test_call , name , call_ind , signature , params , do_eval , solution_args ,
343356 eq_fun , add_more , index ,
344357 params_not_specified_msg , params_not_matched_msg , incorrect_msg ,
345- keywords , state = state )
358+ keywords , state = state , highlight = highlight )
346359 for call_ind in call_indices ]
347360 test_or (* sub_tests , state = state )
348361
@@ -356,7 +369,7 @@ def test_call(name, call_ind, signature, params, do_eval, solution_args,
356369 eq_fun , add_more , index ,
357370 params_not_specified_msg , params_not_matched_msg , incorrect_msg ,
358371 keywords , # pulled from solution process
359- state ):
372+ state , highlight ):
360373 #stud_name = get_mapped_name(name, state.student_mappings)
361374
362375 rep = Reporter .active_reporter
@@ -374,7 +387,7 @@ def test_call(name, call_ind, signature, params, do_eval, solution_args,
374387 params_not_matched_msg = ("Something went wrong in figuring out how you specified the " + \
375388 "arguments for `%s()`; have another look at your code and its output." ) % stud_name
376389 _msg = state .build_message (params_not_matched_msg )
377- feedback = Feedback (_msg , student_call )
390+ feedback = Feedback (_msg , student_call if highlight else None )
378391 # run subtest
379392 rep .do_test (Test (feedback )) # TODO: sub_call
380393
@@ -392,7 +405,7 @@ def test_call(name, call_ind, signature, params, do_eval, solution_args,
392405 else :
393406 msg = params_not_specified_msg [param_ind ]
394407 _msg = state .build_message (msg )
395- feedback = Feedback (_msg , student_call )
408+ feedback = Feedback (_msg , student_call if highlight else None )
396409 # run subtest
397410 rep .do_test (Test (feedback )) # TODO: sub_call
398411
@@ -405,15 +418,15 @@ def test_call(name, call_ind, signature, params, do_eval, solution_args,
405418 test_arg (param , do_eval [ind ],
406419 arg_student , arg_solution , param_kind , stud_name ,
407420 eq_fun , add_more ,
408- incorrect_msg [ind ], state = state )
421+ incorrect_msg [ind ], state = state , highlight = arg_student if highlight else None )
409422
410423 # If all is still good, we have a winner!
411424 state .set_used (name , call_ind , index )
412425
413426def test_arg (param , do_eval ,
414427 arg_student , arg_solution , param_kind , stud_name ,
415428 eq_fun , add_more ,
416- incorrect_msg , state = None ):
429+ incorrect_msg , state = None , highlight = None ):
417430 rep = Reporter .active_reporter
418431
419432 if incorrect_msg is None :
@@ -426,7 +439,7 @@ def test_arg(param, do_eval,
426439
427440 test = build_test (arg_student , arg_solution ,
428441 state ,
429- do_eval , eq_fun , msg , add_more = add_more )
442+ do_eval , eq_fun , msg , add_more = add_more , highlight = highlight )
430443 # TODO
431444 rep .do_test (test )
432445
@@ -443,7 +456,7 @@ def bind_args(signature, arguments, keyws):
443456 bound_args = signature .bind (* arguments , ** keyws )
444457 return (bound_args .arguments , signature .parameters )
445458
446- def build_test (stud , sol , state , do_eval , eq_fun , feedback_msg , add_more ):
459+ def build_test (stud , sol , state , do_eval , eq_fun , feedback_msg , add_more , highlight = False ):
447460 got_error = False
448461 if do_eval :
449462
@@ -472,8 +485,8 @@ def build_test(stud, sol, state, do_eval, eq_fun, feedback_msg, add_more):
472485 eval_solution = ast .dump (sol )
473486
474487 _msg = state .build_message (feedback_msg )
475- return (Test (Feedback (_msg , stud )) if got_error else
476- eq_fun (eval_student , eval_solution , Feedback (_msg , stud )))
488+ return (Test (Feedback (_msg , stud if highlight else None )) if got_error else
489+ eq_fun (eval_student , eval_solution , Feedback (_msg , stud if highlight else None )))
477490
478491
479492
0 commit comments