Skip to content

Commit b0f1a4e

Browse files
Updated feedback message for student submissions which are too long.
1 parent f4ed055 commit b0f1a4e

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

pythonwhat/checks/has_funcs.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,19 @@ 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"])
355+
352356
# check if student or solution evaluations are too long or contain newlines
353357
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-
):
358-
fmt_kwargs["stu_eval"] = None
359-
fmt_kwargs["sol_eval"] = None
360-
incorrect_msg = "Expected something different."
358+
len(fmt_kwargs["sol_eval"]) > 50 or
359+
utils.has_newline(fmt_kwargs["stu_eval"]) or
360+
utils.has_newline(fmt_kwargs["sol_eval"]) or
361+
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."
361365

362366
# tests ---
363367
# error in process

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: 2 additions & 2 deletions
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_too_long():
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,7 +740,7 @@ 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 something different." # nopep8
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
744744

745745
## Check has no error ---------------------------------------------------------
746746

0 commit comments

Comments
 (0)