Skip to content

Commit c6cd747

Browse files
author
Filip Schouwenaars
authored
Merge pull request #184 from datacamp/test-check-function
set check_function to get signature by default, fix a highlight, tests
2 parents 0d40ad3 + 3df8f66 commit c6cd747

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

pythonwhat/check_function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def check_function(name, index,
2424
params_not_matched_msg = "FMT:Something went wrong in figuring out how you specified the "
2525
"arguments for `{name}`; have another look at your code and its output.",
2626
expand_msg = MSG_PREPEND,
27-
signature=None,
27+
signature=True,
2828
typestr = "{ordinal} function call",
2929
state=None):
3030
rep = Reporter.active_reporter
@@ -64,7 +64,7 @@ def check_function(name, index,
6464
stu_parts['args'], _ = bind_args(stu_sig, stu_parts['args'])
6565
except Exception as e:
6666
_msg = state.build_message(params_not_matched_msg, fmt_kwargs)
67-
rep.do_test(Test(Feedback(_msg, state.highlight)))
67+
rep.do_test(Test(Feedback(_msg, stu_parts['node'])))
6868

6969
# three types of parts: pos_args, keywords, args (e.g. these are bound to sig)
7070
append_message = {'msg': expand_msg, 'kwargs': fmt_kwargs}

tests/test_signatures.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ def test_array(self):
243243
sct_payload = helper.run(self.data)
244244
self.assertTrue(sct_payload['correct'])
245245

246+
def test_array_spec2(self):
247+
self.data = {
248+
"DC_PEC": "import numpy as np",
249+
"DC_SOLUTION": "x = np.array([1,2,3,4])",
250+
"DC_CODE": "x = np.array([1,2,3,4])",
251+
"DC_SCT": "Ex().check_function('numpy.array', 0).check_args('object')"}
252+
sct_payload = helper.run(self.data)
253+
self.assertTrue(sct_payload['correct'])
254+
246255
def test_random_seed(self):
247256
self.data = {
248257
"DC_PEC": "import numpy as np",

tests/test_test_function_v2.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,10 @@ def setUp(self):
670670
}
671671

672672
self.SPEC2_SCT = """
673-
Ex().check_function('pandas.DataFrame', 0, missing_msg = "notcalledmsg", expand_msg="")\
674-
.check_args('data', missing_msg='paramsnotmatchedmsg')
673+
Ex().check_function('pandas.DataFrame', 0, missing_msg = "notcalledmsg", expand_msg="", params_not_matched_msg='paramsnotmatchedmsg')\
674+
.multi(
675+
check_args('data', missing_msg='paramsnotspecifiedmsg'),
676+
check_args('columns', missing_msg='paramsnotspecifiedmsg'))
675677
"""
676678

677679
def test_step1(self):
@@ -696,14 +698,17 @@ def test_step2_spec2(self):
696698
self.data["DC_SCT"] = self.SPEC2_SCT
697699
self.test_step2()
698700

699-
700701
def test_step3(self):
701702
self.data["DC_CODE"] = "df = pd.DataFrame(data=[1, 2, 3])"
702703
sct_payload = helper.run(self.data)
703704
self.assertFalse(sct_payload['correct'])
704705
self.assertEqual('paramsnotspecifiedmsg', sct_payload['message'])
705706
helper.test_lines(self, sct_payload, 1, 1, 6, 33)
706707

708+
def test_step3_spec2(self):
709+
self.data["DC_SCT"] = self.SPEC2_SCT
710+
self.test_step3()
711+
707712
def test_step4(self):
708713
self.data["DC_CODE"] = "df = pd.DataFrame(data=[1, 2, 3], columns=['b'])"
709714
sct_payload = helper.run(self.data)

0 commit comments

Comments
 (0)