Skip to content

Commit

Permalink
Merge pull request #27 from isaacl/addStatus
Browse files Browse the repository at this point in the history
Use "status" prop and other misc improvements
  • Loading branch information
ibrahima committed Sep 28, 2022
2 parents 9e3ef92 + 964305a commit cc6b1ce
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions gradescope_utils/autograder_utils/json_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def getTags(self, test):
return getattr(getattr(test, test._testMethodName), '__tags__', None)

def getWeight(self, test):
return getattr(getattr(test, test._testMethodName), '__weight__', 0.0)
return getattr(getattr(test, test._testMethodName), '__weight__', None)

def getScore(self, test):
return getattr(getattr(test, test._testMethodName), '__score__', None)
Expand Down Expand Up @@ -65,31 +65,43 @@ def getOutput(self):
return out

def buildResult(self, test, err=None):
passed = (err == None)

failed = err is not None
weight = self.getWeight(test)
tags = self.getTags(test)
number = self.getNumber(test)
visibility = self.getVisibility(test)
hide_errors_message = self.getHideErrors(test)
score = self.getScore(test)
if score is None:
score = weight if passed else 0.0

output = self.getOutput()
output = self.getOutput() or ""
if err:
if hide_errors_message:
output += hide_errors_message
else:
if output:
# Create a double newline if output is not empty
if output.endswith('\n'):
output += '\n'
else:
output += '\n\n'
output += "Test Failed: {0}\n".format(err[1])
result = {
"name": self.getDescription(test),
"score": score,
"max_score": weight,
}
if score is not None or weight is not None:
if weight is None:
weight = 0.0
if score is None:
score = 0.0 if failed else weight
result["score"] = score
result["max_score"] = weight
# Also mark failure if points are lost
failed |= score < weight

result["status"] = "failed" if failed else "passed"

if tags:
result["tags"] = tags
if output and len(output) > 0:
if output:
result["output"] = output
if visibility:
result["visibility"] = visibility
Expand Down Expand Up @@ -185,7 +197,7 @@ def run(self, test):

total_score = 0
for test in self.json_data["tests"]:
total_score += test["score"]
total_score += test.get("score", 0.0)
self.json_data["score"] = total_score

if self.post_processor is not None:
Expand Down

0 comments on commit cc6b1ce

Please sign in to comment.