MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / check_call

Function check_call

pythonwhat/checks/check_funcs.py:287–329  ·  view source on GitHub ↗

When checking a function definition of lambda function, prepare has_equal_x for checking the call of a user-defined function. Args: callstr (str): call string that specifies how the function should be called, e.g. `f(1, a = 2)`. ``check_call()`` will replace ``f`` with th

(state, callstr, argstr=None, expand_msg=None)

Source from the content-addressed store, hash-verified

285
286
287def check_call(state, callstr, argstr=None, expand_msg=None):
288 """When checking a function definition of lambda function,
289 prepare has_equal_x for checking the call of a user-defined function.
290
291 Args:
292 callstr (str): call string that specifies how the function should be called, e.g. `f(1, a = 2)`.
293 ``check_call()`` will replace ``f`` with the function/lambda you're targeting.
294 argstr (str): If specified, this overrides the way the function call is refered to in the expand message.
295 expand_msg (str): If specified, this overrides any messages that are prepended by previous SCT chains.
296 state (State): state object that is chained from.
297
298 :Example:
299
300 Student and solution code::
301
302 def my_power(x):
303 print("calculating sqrt...")
304 return(x * x)
305
306 SCT::
307
308 Ex().check_function_def('my_power').multi(
309 check_call("f(3)").has_equal_value()
310 check_call("f(3)").has_equal_output()
311 )
312 """
313
314 state.assert_is(
315 ["function_defs", "lambda_functions"],
316 "check_call",
317 ["check_function_def", "check_lambda_function"],
318 )
319
320 if expand_msg is None:
321 expand_msg = "To verify it, we reran {{argstr}}. "
322
323 stu_part, _argstr = build_call(callstr, state.student_parts["node"])
324 sol_part, _ = build_call(callstr, state.solution_parts["node"])
325
326 append_message = FeedbackComponent(expand_msg, {"argstr": argstr or _argstr})
327 child = part_to_child(stu_part, sol_part, append_message, state)
328
329 return child

Callers 2

test_check_callFunction · 0.85
test_check_call_lambdaFunction · 0.85

Calls 3

build_callFunction · 0.85
part_to_childFunction · 0.85
assert_isMethod · 0.80

Tested by 2

test_check_callFunction · 0.68
test_check_call_lambdaFunction · 0.68