Skip to content

Commit 36e43b6

Browse files
Updated has_expr feedback logic and added test
1 parent 59e209f commit 36e43b6

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

pythonwhat/checks/has_funcs.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,18 @@ def has_expr(
349349
if isinstance(eval_sol, str):
350350
fmt_kwargs["sol_eval"] = '\'{}\''.format(fmt_kwargs["sol_eval"])
351351

352-
# reformat student evaluation string if it is too long or contains newlines
353-
if incorrect_msg == DEFAULT_INCORRECT_MSG:
354-
fmt_kwargs["stu_eval"] = utils.shorten_string(fmt_kwargs["stu_eval"])
352+
# reformat student evaluation string if it is too long
353+
fmt_kwargs["stu_eval"] = utils.shorten_string(fmt_kwargs["stu_eval"])
355354

356355
# check if student or solution evaluations are too long or contain newlines
357356
if incorrect_msg == DEFAULT_INCORRECT_MSG and (
358357
len(fmt_kwargs["sol_eval"]) > 50 or
359358
utils.has_newline(fmt_kwargs["stu_eval"]) or
360359
utils.has_newline(fmt_kwargs["sol_eval"]) or
361360
fmt_kwargs["stu_eval"] == fmt_kwargs["sol_eval"]):
362-
fmt_kwargs["stu_eval"] = None
363-
fmt_kwargs["sol_eval"] = None
364-
incorrect_msg = "Expected something different."
361+
fmt_kwargs["stu_eval"] = None
362+
fmt_kwargs["sol_eval"] = None
363+
incorrect_msg = "Expected something different."
365364

366365
# tests ---
367366
# error in process

tests/test_messaging.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def test_has_equal_value_dont_wrap_newline():
728728
assert output["message"] == "Check your call of <code>print()</code>. Did you correctly specify the first argument? Expected something different." # nopep8
729729

730730

731-
def test_has_equal_value_shorten_too_long():
731+
def test_has_equal_value_shorten_submission():
732732
sol = """print('short text')"""
733733
stu = """print('This text is longer than 50 characters if I copy it 3 times. This text is longer than 50 characters if I copy it 3 times. This text is longer than 50 characters if I copy it 3 times.')""" # nopep8
734734
sct = """Ex().check_function('print', index=0, signature=False).check_args(0).has_equal_value()"""
@@ -742,6 +742,21 @@ def test_has_equal_value_shorten_too_long():
742742
assert not output["correct"]
743743
assert output["message"] == "Check your call of <code>print()</code>. Did you correctly specify the first argument? Expected <code>'short text'</code>, but got <code>'This text is longer than 50 characters if I ...</code>." # nopep8
744744

745+
746+
def test_has_equal_value_dont_shorten_solution():
747+
sol = """print('This solution is really really really really really really really really long!')"""
748+
stu = """print('short text')""" # nopep8
749+
sct = """Ex().check_function('print', index=0, signature=False).check_args(0).has_equal_value()"""
750+
output = helper.run(
751+
{
752+
"DC_CODE": stu,
753+
"DC_SOLUTION": sol,
754+
"DC_SCT": sct,
755+
}
756+
)
757+
assert not output["correct"]
758+
assert output["message"] == "Check your call of <code>print()</code>. Did you correctly specify the first argument? Expected something different." # nopep8
759+
745760
## Check has no error ---------------------------------------------------------
746761

747762

0 commit comments

Comments
 (0)