Skip to content
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='xqueue_watcher',
version='0.2',
version='0.2.2',
description='XQueue Pull Grader',
packages=[
'grader_support',
Expand Down
33 changes: 28 additions & 5 deletions xqueue_watcher/jailedgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ def grade(self, grader_path, grader_config, submission):

self._enable_i18n(grader_config.get("lang", LANGUAGE))

answer_path = Path(grader_path).dirname() / 'answer.py'
# *** MINOR TEMP FIX TO ACCOMMODATE MULTIPLE ANSWER FILES ***
# ===========================================================
answer_path = ((parent_dir_path := Path(grader_path).parent) / # noqa: W504
next(file_name
for file_name in os.listdir(path=parent_dir_path)
if file_name.lower().startswith('answer')
and file_name.endswith('.py'))) # noqa: W503
# -----------------------------------------------------------
with open(answer_path, 'rb') as f:
answer = f.read().decode('utf-8')

Expand All @@ -132,6 +139,13 @@ def grade(self, grader_path, grader_config, submission):
# Don't run tests if there were errors
return results

# *** IF THERE'RE ONLY INPUT CHECKS & NO TESTS, THEN RETURN CORRECT ***
# =====================================================================
elif not grader._tests: # pylint: disable=protected-access
results['correct'] = True
return results
# ---------------------------------------------------------------------

# Add a unicode encoding declaration.
processed_answer = prepend_coding(grader.preprocess(answer))
processed_submission = prepend_coding(grader.preprocess(submission))
Expand Down Expand Up @@ -243,14 +257,23 @@ def grade(self, grader_path, grader_config, submission):

# If there were no tests run, then there was probably an error, so it's incorrect
n = len(corrects)
results['correct'] = all(corrects) and n > 0

# *** ALLOW GRADERS WITH ONLY INPUT CHECKS & NO TESTS ***
# =======================================================
_n = len(grader._input_checks) # pylint: disable=protected-access
results['correct'] = all(corrects) and ((n > 0) or (_n > 0))
# -------------------------------------------------------

results['score'] = float(sum(corrects))/n if n > 0 else 0

if n == 0 and len(results['errors']) == 0:
# *** ALLOW GRADERS WITH ONLY INPUT CHECKS & NO TESTS ***
# =======================================================
if not (n or results['errors'] or _n):
results['errors'] = [
_("There was a problem while running your code (Staff debug: L450). "
"Please contact the course staff for assistance.")
]
# -------------------------------------------------------

return results

Expand All @@ -275,10 +298,10 @@ def main(args): # pragma: no cover
(grader_path, submission_path) = args

with open(submission_path) as f:
submission = f.read().decode('utf-8')
submission = f.read() # .decode('utf-8')

grader_config = {"lang": "eo"}
grader_path = path(grader_path).abspath()
grader_path = Path(grader_path).abspath()
g = JailedGrader(grader_root=grader_path.dirname().parent.parent)
pprint(g.grade(grader_path, grader_config, submission))

Expand Down