Skip to content

Commit

Permalink
Merge pull request #15 from gradescope/ibrahim/ch24858/instructors-ca…
Browse files Browse the repository at this point in the history
…n-number-test-cases-with-a

Instructors can number test cases with a decorator
  • Loading branch information
ibrahima committed Jan 14, 2020
2 parents a7e1d36 + 4d79af6 commit 028aa5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gradescope_utils/autograder_utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ def __call__(self, func):
return func


class number(object):
"""Simple decorator to add a __number__ property to a function
Usage: @number("1.1")
This field will then be used to sort the test results on Gradescope.
"""

def __init__(self, val):
self.val = val

def __call__(self, func):
func.__number__ = self.val
return func

class visibility(object):
"""Simple decorator to add a __visibility__ property to a function
Expand Down
6 changes: 6 additions & 0 deletions gradescope_utils/autograder_utils/json_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def getWeight(self, test):
def getScore(self, test):
return getattr(getattr(test, test._testMethodName), '__score__', None)

def getNumber(self, test):
return getattr(getattr(test, test._testMethodName), '__number__', None)

def getVisibility(self, test):
return getattr(getattr(test, test._testMethodName), '__visibility__', None)

Expand Down Expand Up @@ -63,6 +66,7 @@ def buildResult(self, test, err=None):

weight = self.getWeight(test)
tags = self.getTags(test)
number = self.getNumber(test)
visibility = self.getVisibility(test)
score = self.getScore(test)
if score is None:
Expand All @@ -82,6 +86,8 @@ def buildResult(self, test, err=None):
result["output"] = output
if visibility:
result["visibility"] = visibility
if number:
result["number"] = number
return result

def buildLeaderboardEntry(self, test):
Expand Down

0 comments on commit 028aa5f

Please sign in to comment.