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

Function test_bind_args

tests/test_check_function.py:82–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80
81
82def test_bind_args():
83 from pythonwhat.test_exercise import setup_state
84 from inspect import signature
85 from pythonwhat.checks.check_function import bind_args
86
87 def my_fun(a, b, *args, **kwargs): pass
88 pec = getsource(my_fun).strip()
89 s = setup_state(pec=pec, stu_code="my_fun(1, 2, 3, 4, c = 5)")
90 args = s._state.ast_dispatcher.find("function_calls", s._state.student_ast)[
91 "my_fun"
92 ][0]["args"]
93 sig = signature(my_fun)
94 bound_args = bind_args(sig, args)
95 assert bound_args["a"]["node"].value == 1
96 assert bound_args["b"]["node"].value == 2
97 assert bound_args["args"][0]["node"].value == 3
98 assert bound_args["args"][1]["node"].value == 4
99 assert bound_args["kwargs"]["c"]["node"].value == 5
100
101
102@pytest.mark.parametrize("argspec", [["args", 0], ["args", 1], ["kwargs", "c"]])

Callers

nothing calls this directly

Calls 3

bind_argsFunction · 0.90
setup_stateFunction · 0.85
findMethod · 0.80

Tested by

no test coverage detected