Skip to content

Commit 24e053b

Browse files
committed
has_expr message template now may refer to extra_env and context_vals
1 parent 44195a3 commit 24e053b

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

pythonwhat/check_funcs.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def check_part(name, part_msg, state=None, missing_msg="", expand_msg=""):
3636
return part_to_child(stu_part, sol_part, append_message, state)
3737

3838
def check_part_index(name, index, part_msg,
39-
missing_msg="Define more {part}.",
39+
missing_msg="Have you defined a {part}.",
4040
state=None, expand_msg=""):
4141
"""Return child state with indexed name part as its ast tree"""
4242

@@ -92,6 +92,9 @@ def check_node(name, index, typestr, missing_msg=MSG_MISSING, expand_msg=MSG_PRE
9292

9393
return part_to_child(stu_part, sol_part, append_message, state)
9494

95+
96+
# Part tests ------------------------------------------------------------------
97+
9598
def has_part(name, msg, state=None, fmt_kwargs=None):
9699
rep = Reporter.active_reporter
97100
d = {'sol_part': state.solution_parts,
@@ -290,8 +293,8 @@ def call(args,
290293
test='value',
291294
incorrect_msg=MSG_CALL_INCORRECT,
292295
error_msg=MSG_CALL_ERROR,
293-
# TODO hardcoded lambda description for now
294-
argstr='the Xth lambda function',
296+
# TODO kept for backwards compatibility in test_function_definition/lambda
297+
argstr='',
295298
state=None, **kwargs):
296299
rep = Reporter.active_reporter
297300
test_type = ('value', 'output', 'error')
@@ -328,7 +331,7 @@ def call(args,
328331
from pythonwhat.tasks import ReprFail, UndefinedValue
329332
from pythonwhat.Test import EqualTest
330333
from pythonwhat import utils
331-
def has_expr(incorrect_msg,
334+
def has_expr(incorrect_msg="Unexpected expression: expected `{sol_eval}`, got `{stu_eval}` with values{extra_env}.",
332335
error_msg="Running an expression in the student process caused an issue",
333336
undefined_msg="Have you defined `{name}` without errors?",
334337
extra_env=None,
@@ -371,7 +374,8 @@ def has_expr(incorrect_msg,
371374
context = state.student_context)
372375

373376
# kwargs ---
374-
fmt_kwargs = {'stu_part': state.student_parts, 'sol_part': state.solution_parts, 'name': name}
377+
fmt_kwargs = {'stu_part': state.student_parts, 'sol_part': state.solution_parts, 'name': name,
378+
'extra_env': " "+str(extra_env or ""), 'context_vals': context_vals}
375379
fmt_kwargs['stu_eval'] = utils.shorten_str(str(eval_stu))
376380
fmt_kwargs['sol_eval'] = utils.shorten_str(str(eval_sol))
377381

pythonwhat/test_funcs/test_expression_result.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def test_expression_result(extra_env=None,
8080
else:
8181
# need to double bracket extra_env, so doesn't mess up str templating
8282
feedback_msg = (
83-
"Unexpected expression: expected `{sol_eval}`, got `{stu_eval}` with values"
84-
" " + str(extra_env).replace('{', '{{').replace('}','}}') if extra_env else "."
83+
"Unexpected expression: expected `{sol_eval}`, got `{stu_eval}` with values{extra_env}."
8584
)
8685

8786
has_equal_value(feedback_msg,

pythonwhat/test_funcs/test_lambda_function.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ def test_lambda_function(index,
8787
student_fun = state.student_lambda_functions[index-1]['node']
8888
solution_fun = state.solution_lambda_functions[index-1]['node']
8989

90-
fun_name = "the %s lambda function" % get_ord(index)
91-
9290
for el in results:
9391
argstr = el.replace('lam', '')
9492
call(el,

0 commit comments

Comments
 (0)