Extensions API

This page contains API reference for various extensions of the grader module.

grader.extensions.adv_functions module

grader.extensions.adv_functions.check_function(sample_function, arguments, expected_result=None, description=None, check_print=True, n_calls=3, check_globals=True)[source]

grader.extensions.ast module

Module for testing fill-in-the-blanks task type.

Tester for the example task.

from grader import *
from grader.extensions import ast

template = """
number = int(input("Input a number: "))
if number > _____: # fill in the blank here...
    print("Non-negative!")
else:
    ... # and here! Can be several lines
"""

ast.template_test(template)

Note that additional tests are also needed to verify the behaviour of the program.

grader.extensions.ast.template_test(template_file=None, template_code=None, description='Program should match the template.')[source]
grader.extensions.ast.compare_trees(original_tree, compared_tree)[source]

Compares two AST trees with each other. Returns a list of differences, pairs of (expected, got).

In addition to doing straight-forward comparison, it allows for two kinds of wildcard expressions:

  1. ____ expressions which can be filled with a single expression/statement.

  2. ... expressions which can be filled with any number of

    valid expressions/statements. Used in bodies.

grader.extensions.ast.is_underscore(node)[source]

Function matching a ____ expression. Used to allow to be filled with any expression.

grader.extensions.ast.is_wildcard(node)[source]

Function matching a ... expression (used as a wildcard expression)

grader.extensions.ast.pprint_ast(tree)[source]
grader.extensions.ast.dump(T)[source]

maps nested list of asts to strings

Table Of Contents

Previous topic

API reference

Next topic

Internal API reference

This Page