Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identical code option added #765

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion course/page/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ class CodeQuestion(PageBaseWithTitle, PageBaseWithValue):
example of a local build. The Docker image should already be loaded
on the system (RELATE does not pull the image automatically).

.. attribute:: exact_correct_code_okay
Optional. A Boolean that controls whether identical submissions to the
correct_code are allowed for code questions. If set to False, an error
is shown. Setting this to True will silence the error.

* ``data_files``: A dictionary mapping file names from :attr:`data_files`
to :class:`bytes` instances with that file's contents.

Expand Down Expand Up @@ -589,6 +594,9 @@ def __init__(self, vctx, location, page_desc, language_mode):
"While you're at it, consider adding "
"access_rules/add_permssions/see_correctness."))

self.exact_correct_code_okay = getattr(page_desc,
"exact_correct_code_okay", False)

def required_attrs(self):
return super().required_attrs() + (
("prompt", "markup"),
Expand All @@ -609,6 +617,7 @@ def allowed_attrs(self):
("docker_image", str),
("data_files", list),
("single_submission", bool),
("exact_correct_code_okay", bool),
)

def _initial_code(self):
Expand Down Expand Up @@ -886,7 +895,8 @@ def normalize_code(s):
.replace("\t", ""))

if (normalize_code(user_code)
== normalize_code(self.page_desc.correct_code)):
== normalize_code(self.page_desc.correct_code)
and not self.exact_correct_code_okay):
feedback_bits.append(
"<p><b>%s</b></p>"
% _("It looks like you submitted code that is identical to "
Expand Down Expand Up @@ -1234,6 +1244,11 @@ class PythonCodeQuestion(CodeQuestion):
based on its :attr:`access_rules` (not the ones of the flow), a warning
is shown. Setting this attribute to True will silence the warning.

.. attribute:: exact_correct_code_okay
Optional. A Boolean that controls whether identical submissions to the
correct_code are allowed for code questions. If set to False, an error
is shown. Setting this to True will silence the error.

The following symbols are available in :attr:`setup_code` and :attr:`test_code`:

* ``GradingComplete``: An exception class that can be raised to indicated
Expand Down