gradescope_utils.autograder_utils package

Submodules

gradescope_utils.autograder_utils.decorators module

class gradescope_utils.autograder_utils.decorators.hide_errors(val='Test failed')[source]

Bases: object

Simple decorator to add a __hide_errors__ property to a function

Usage: @hide_errors(“Error message to be shown upon test failure”)

Used to hide the particular source of an error which caused a test to fail. Otherwise, a test’s particular assertions can be seen by students.

class gradescope_utils.autograder_utils.decorators.leaderboard(column_name, sort_order='desc')[source]

Bases: object

Decorator that indicates that a test corresponds to a leaderboard column

Usage: @leaderboard(“high_score”). The string parameter indicates the name of the column on the leaderboard

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_value=None):

set_leaderboard_value(42)

```

class gradescope_utils.autograder_utils.decorators.number(val)[source]

Bases: 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.

class gradescope_utils.autograder_utils.decorators.partial_credit(weight)[source]

Bases: object

Decorator that indicates that a test allows partial credit

Usage: @partial_credit(test_weight)

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

``` @partial_credit(10) def test_partial(set_score=None):

set_score(4.2)

```

class gradescope_utils.autograder_utils.decorators.tags(*args)[source]

Bases: object

Simple decorator to add a __tags__ property to a function

Usage: @tags(“concept1”, “concept2”)

class gradescope_utils.autograder_utils.decorators.visibility(val)[source]

Bases: object

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. If late submission is allowed, then test will be shown only after the late due date.
  • after_published: test case will be shown only when the assignment is explicitly published from the “Review Grades” page
  • visible (default): test case will always be shown
class gradescope_utils.autograder_utils.decorators.weight(val)[source]

Bases: object

Simple decorator to add a __weight__ property to a function

Usage: @weight(3.0)

gradescope_utils.autograder_utils.files module

gradescope_utils.autograder_utils.files.check_submitted_files(paths, base='/autograder/submission')[source]

Checks that the files in the given list exist in the student’s submission.

Returns a list of missing files.

eg. check_submitted_files([‘src/calculator.py’])

gradescope_utils.autograder_utils.json_test_runner module

Running tests

class gradescope_utils.autograder_utils.json_test_runner.JSONTestResult(stream, descriptions, verbosity, results, leaderboard, failure_prefix)[source]

Bases: unittest.result.TestResult

A test result class that can print formatted text results to a stream.

Used by JSONTestRunner.

addError(test, err)[source]

Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().

addFailure(test, err)[source]

Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().

addSuccess(test)[source]

Called when a test has completed successfully

buildLeaderboardEntry(test)[source]
buildResult(test, err=None)[source]
getDescription(test)[source]
getHideErrors(test)[source]
getLeaderboardData(test)[source]
getNumber(test)[source]
getOutput()[source]
getScore(test)[source]
getTags(test)[source]
getVisibility(test)[source]
getWeight(test)[source]
processResult(test, err=None)[source]
startTest(test)[source]

Called when the given test is about to be run

class gradescope_utils.autograder_utils.json_test_runner.JSONTestRunner(stream=<open file '<stdout>', mode 'w'>, descriptions=True, verbosity=1, failfast=False, buffer=True, visibility=None, stdout_visibility=None, post_processor=None, failure_prefix='Test Failed: ')[source]

Bases: object

A test runner class that displays results in JSON form.

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.

failure_prefix: prepended to the output of each test’s json

resultclass

alias of JSONTestResult

run(test)[source]

Run the given test case or test suite.

Module contents