Decorators

Decorators.

Inspired by Gradescope-utils. https://github.com/gradescope/gradescope-utils

grade.decorators.leaderboard(name=None, order='desc')

Decorator that indicates that a test corresponds to a leaderboard column

Usage: @leaderboard(column title, ordering) By default, column title and ordering are function.__name__ and ‘desc’ respectively.

You may pass in any column title you’d like, however ordering must be either ‘asc’ or ‘desc’

Then, within the test, set the value by calling kwargs[‘set_leaderboard_value’] with a value. You can make this convenient by explicitly declaring a set_leaderboard_value keyword argument, eg.

def test_highscore(set_leaderboard_score=None):
    set_leaderboard_score(42)

You can also use the ScoringMixin, which provides a setter for leaderboardScore.

grade.decorators.static(name, value)

Sets name to value.

grade.decorators.visibility(value)

Simple decorator to add a __visibility__ property to a function

Usage: @visibility(“hidden”)

Options for the visibility field are as follows: - hidden: test case will never be shown to students - after_due_date: test case will be shown after the assignment’s due date has passed - after_published: test case will be shown only when the assignment is explicitly published - visible (default): test case will always be shown

grade.decorators.weight(value)

Simple decorator to add a __weight__ property to a function

Usage: @weight(3.0)