()
| 80 | |
| 81 | |
| 82 | def 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"]]) |
nothing calls this directly
no test coverage detected