Skip to content

Commit 91ed457

Browse files
Merge pull request #396 from datacamp/feat/update_has_expr_feedback
[LO-1231] Feat/update_has_expr_feedback
2 parents f4ed055 + 36e43b6 commit 91ed457

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the pythonwhat project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
44

5+
## 2.23.2
6+
7+
- Update behaviour of has_expr() default feedback message. If the student's evaluation is too long, it is now shortened and an ellipsis is added.
8+
59
## 2.23.1
610

711
- Fix string formatting in has_expr(). Strings will now have quotes in error messages. Leading and trailing whitespace is no longer removed.

pythonwhat/checks/has_funcs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,15 @@ 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
353+
fmt_kwargs["stu_eval"] = utils.shorten_string(fmt_kwargs["stu_eval"])
354+
352355
# check if student or solution evaluations are too long or contain newlines
353356
if incorrect_msg == DEFAULT_INCORRECT_MSG and (
354-
utils.unshowable_string(fmt_kwargs["stu_eval"])
355-
or utils.unshowable_string(fmt_kwargs["sol_eval"])
356-
or fmt_kwargs["stu_eval"] == fmt_kwargs["sol_eval"]
357-
):
357+
len(fmt_kwargs["sol_eval"]) > 50 or
358+
utils.has_newline(fmt_kwargs["stu_eval"]) or
359+
utils.has_newline(fmt_kwargs["sol_eval"]) or
360+
fmt_kwargs["stu_eval"] == fmt_kwargs["sol_eval"]):
358361
fmt_kwargs["stu_eval"] = None
359362
fmt_kwargs["sol_eval"] = None
360363
incorrect_msg = "Expected something different."

pythonwhat/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ def include_v1():
1010
def v2_only():
1111
return not include_v1()
1212

13+
def shorten_string(text):
14+
if len(text) > 50:
15+
text = text[0:45] + "..."
16+
return text
1317

14-
def unshowable_string(text):
15-
return "\n" in text or len(text) > 50
18+
def has_newline(text):
19+
return "\n" in text
1620

1721

1822
def copy_env(env):

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_dont_wrap_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()"""
@@ -740,6 +740,21 @@ def test_has_equal_value_dont_wrap_too_long():
740740
}
741741
)
742742
assert not output["correct"]
743+
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
744+
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"]
743758
assert output["message"] == "Check your call of <code>print()</code>. Did you correctly specify the first argument? Expected something different." # nopep8
744759

745760
## Check has no error ---------------------------------------------------------

0 commit comments

Comments
 (0)