|
1 | | -from pythonwhat.check_funcs import check_node |
2 | | -from pythonwhat.test_funcs.test_function import mapped_name |
| 1 | +from pythonwhat.Reporter import Reporter |
| 2 | +from pythonwhat.check_funcs import check_node, check_part_index |
| 3 | +from pythonwhat.test_funcs.test_function import bind_args |
3 | 4 | from pythonwhat.tasks import getSignatureInProcess |
4 | 5 | from functools import partial |
5 | 6 |
|
6 | 7 | def check_function(name, index=0, |
7 | | - missing_msg = "Did you define {sol_part[name]}?", |
| 8 | + missing_msg = "Did you define {typestr}?", |
8 | 9 | expand_msg = "In your definition of {sol_part[name]}, ", |
| 10 | + params_not_matched_msg = "Something went wrong in figuring out how you specified the " |
| 11 | + "arguments for `{sol_part[name]}`; have another look at your code and its output.", |
9 | 12 | state=None): |
10 | 13 | rep = Reporter.active_reporter |
11 | 14 | stu_out = state.student_function_calls |
12 | 15 | sol_out = state.solution_function_calls |
13 | 16 |
|
14 | | - # test if function exists |
15 | | - stud_name = get_mapped_name(name, state.student_mappings) |
16 | | - |
17 | | - func_list = check_node('function_calls', name, 'function call', missing_msg, expand_msg, state) |
| 17 | + import pdb; pdb.set_trace() |
18 | 18 | # get function state |
19 | | - if index is None: |
20 | | - return func_list |
21 | | - else: |
22 | | - # TODO make has_part more robust |
23 | | - # grab specific function call |
24 | | - child_func = check_part(index, "FUNCTION MSG", func_list, "not enough func calls") |
25 | | - stu_parts, sol_parts = child_func.student_parts, child_func.solution_parts |
26 | | - # Signatures |
27 | | - get_sig = partial(getSignatureInProcess, name=name, signature=signature, |
28 | | - manual_sigs = state.get_manual_sigs()) |
| 19 | + func_list = check_node('function_calls', name, '{ordinal} function call to {name}', missing_msg, expand_msg, state) |
| 20 | + # grab specific function call |
| 21 | + # TODO NoneType not subscriptable, alter parsing so func part is dict |
| 22 | + child_func = check_part_index(None, index, "", func_list, state=func_list) |
| 23 | + stu_parts, sol_parts = child_func.student_parts, child_func.solution_parts |
| 24 | + # Signatures |
| 25 | + get_sig = partial(getSignatureInProcess, name=name, signature=signature, |
| 26 | + manual_sigs = state.get_manual_sigs()) |
29 | 27 |
|
30 | | - # TODO if can't parse, raise warnings |
| 28 | + try: |
31 | 29 | sol_sig = get_sig(mapped_name=sol_parts['name'], process=solution_process) |
32 | | - sol_parts['args'], _ = bind_ards(sol_sig, sol_parts['pos_args'], sol_parts['keywords']) |
| 30 | + sol_parts['args'], _ = bind_args(sol_sig, sol_parts['pos_args'], sol_parts['keywords']) |
| 31 | + except: |
| 32 | + raise ValueError("Something went wrong in matching call index {index} of {name} to its signature. " |
| 33 | + "You might have to manually specify or correct the signature." |
| 34 | + .format(index=index, name=name)) |
33 | 35 |
|
34 | | - # TODO if can't parse sig, send failed test msg |
35 | | - stu_sig = get_sig(mapped_name=stu_parts['name'], process=student_process) |
36 | | - stu_parts['args'], _ = bind_ards(stu_sig, stu_parts['pos_args'], stu_parts['keywords']) |
| 36 | + # TODO if can't parse sig, send failed test msg |
| 37 | + try: |
| 38 | + stu_sig = get_sig(mapped_name=stu_parts['name'], process=child_func.student_process) |
| 39 | + stu_parts['args'], _ = bind_args(stu_sig, stu_parts['pos_args'], stu_parts['keywords']) |
| 40 | + except: |
| 41 | + _msg = state.build_message(params_not_matched_msg) |
| 42 | + rep.do_test(Test(Feedback(_msg, state.highlight))) |
37 | 43 |
|
38 | | - # three types of parts: pos_args, keywords, args (e.g. these are bound to sig) |
39 | | - return child_func |
| 44 | + # three types of parts: pos_args, keywords, args (e.g. these are bound to sig) |
| 45 | + return child_func |
0 commit comments