Skip to content

Commit 4724e1e

Browse files
committed
temporary commit
1 parent 8689abe commit 4724e1e

4 files changed

Lines changed: 48 additions & 25 deletions

File tree

pythonwhat/check_funcs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def check_node(name, index, typestr, missing_msg=MSG_MISSING, expand_msg=MSG_PRE
7474

7575
# check if there are enough nodes for index
7676
fmt_kwargs = {'ordinal': get_ord(index+1) if isinstance(index, int) else "",
77-
'index': index}
77+
'index': index,
78+
'name': name}
7879
fmt_kwargs['typestr'] = typestr.format(**fmt_kwargs)
7980

8081
# test if node can be indexed succesfully

pythonwhat/check_function.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
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
34
from pythonwhat.tasks import getSignatureInProcess
45
from functools import partial
56

67
def check_function(name, index=0,
7-
missing_msg = "Did you define {sol_part[name]}?",
8+
missing_msg = "Did you define {typestr}?",
89
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.",
912
state=None):
1013
rep = Reporter.active_reporter
1114
stu_out = state.student_function_calls
1215
sol_out = state.solution_function_calls
1316

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()
1818
# 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())
2927

30-
# TODO if can't parse, raise warnings
28+
try:
3129
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))
3335

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)))
3743

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

pythonwhat/check_wrappers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pythonwhat.check_funcs import check_part, check_part_index, check_node, has_equal_part
22
from pythonwhat import check_funcs, check_object
3+
from pythonwhat.check_function import check_function
34
from pythonwhat.test_funcs.test_data_frame import check_df
45
from pythonwhat.test_funcs.test_dictionary import check_dict
56
from pythonwhat import test_funcs
@@ -53,6 +54,7 @@
5354

5455
for k, v in __NODE_WRAPPERS__.items():
5556
scts['check_'+k] = partial(check_node, k+'s', typestr=v)
57+
scts['check_function'] = check_function
5658

5759
for k in ['set_context',
5860
'has_equal_value', 'has_equal_output', 'has_equal_error', 'call',

tests/test_test_function_v2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,20 +669,34 @@ def setUp(self):
669669
'''
670670
}
671671

672+
self.SPEC2_SCT = """
673+
Ex().check_function('pandas.DataFrame', missing_msg = "notcalledmsg")\
674+
.check_args('data', missing_msg='paramsnotmatchedmsg')
675+
"""
676+
672677
def test_step1(self):
673678
self.data["DC_CODE"] = ""
674679
sct_payload = helper.run(self.data)
675680
self.assertFalse(sct_payload['correct'])
676681
self.assertEqual('notcalledmsg', sct_payload['message'])
677682
helper.test_absent_lines(self, sct_payload)
678683

684+
def test_step1_spec2(self):
685+
self.data["DC_SCT"] = self.SPEC2_SCT
686+
self.test_step1()
687+
679688
def test_step2(self):
680689
self.data["DC_CODE"] = "df = pd.DataFrame(x=[1, 2, 3])"
681690
sct_payload = helper.run(self.data)
682691
self.assertFalse(sct_payload['correct'])
683692
self.assertEqual('paramsnotmatchedmsg', sct_payload['message'])
684693
helper.test_lines(self, sct_payload, 1, 1, 6, 30)
685694

695+
def test_step2_spec2(self):
696+
self.data["DC_SCT"] = self.SPEC2_SCT
697+
self.test_step2()
698+
699+
686700
def test_step3(self):
687701
self.data["DC_CODE"] = "df = pd.DataFrame(data=[1, 2, 3])"
688702
sct_payload = helper.run(self.data)

0 commit comments

Comments
 (0)