Skip to content

Commit

Permalink
Merge pull request #16 from gradescope/ibrahim/ch24859/instructors-ca…
Browse files Browse the repository at this point in the history
…n-set-late-penalties-in-an

Instructors can override results (e.g. set late penalties) in a post-processor function
  • Loading branch information
mDibyo committed Jun 11, 2020
2 parents 5e8cd69 + bd55e1e commit dd58c10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,6 @@
}

source_suffix = ['.rst', '.md']

# Document constructors as well as class doc strings
autoclass_content = 'both'
12 changes: 11 additions & 1 deletion gradescope_utils/autograder_utils/json_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,22 @@ class JSONTestRunner(object):

def __init__(self, stream=sys.stdout, descriptions=True, verbosity=1,
failfast=False, buffer=True, visibility=None,
stdout_visibility=None):
stdout_visibility=None, post_processor=None):
"""
Set buffer to True to include test output in JSON
post_processor: if supplied, will be called with the final JSON
data before it is written, allowing the caller to overwrite the
test results (e.g. add a late penalty) by editing the results
dict in the first argument.
"""
self.stream = stream
self.descriptions = descriptions
self.verbosity = verbosity
self.failfast = failfast
self.buffer = buffer
self.post_processor = post_processor
self.json_data = {}
self.json_data["tests"] = []
self.json_data["leaderboard"] = []
Expand Down Expand Up @@ -174,6 +181,9 @@ def run(self, test):
total_score += test["score"]
self.json_data["score"] = total_score

if self.post_processor is not None:
self.post_processor(self.json_data)

json.dump(self.json_data, self.stream, indent=4)
self.stream.write('\n')
return result

0 comments on commit dd58c10

Please sign in to comment.