Pry - API

This page describes the API exposed from the libpry module.

AUTO = object()

Flag object for TestContainer

def raises(exc, obj, *args, **kwargs)

Assert that a callable raises a specified exception.

exc
An exception class or a string. If a class, assert that an exception of this type is raised. If a string, assert that the string occurs in the string representation of the exception, based on a case-insenstivie match.
obj
A callable object.
args
Arguments to be passsed to the callable.
kwargs
Arguments to be passed to the callable.

class TmpDirMixin()

A utility mixin that creates a temporary directory during setup, and removes it during teardown. The directory path is inserted into the test namespace as follows:

self["tmpdir"] = path

def setUp(self)
def tearDown(self)
class _TestBase(_tinytree.Tree)

Automatically turns methods or arbitrary callables of the form test_* into Tests.

name = None

The name of this node. Names should not contain periods or spaces.

def __init__(self, children=None, name=None)
children
A nested list of child nodes
name
The name of this node. Should not contain periods or spaces. Can optionally be set as a class variable in subclasses.
def __getitem__(self, key)

Retrieve an item from the tree namespace. Keys are looked up in this node, and on all nodes to the root.

def __setitem__(self, key, value)

Set an item in this node's namespace.

class TestContainer(_TestBase)

A container for tests.

def __init__(self, children=None, name=AUTO)
children
A nested list of subnodes.
name
The name of this node. Should not contain spaces or periods. If set to the special constant AUTO, the name is computed automatically from the class name of this instance.
def setUp(self)

Run before each child is run.

def setUpAll(self)

Run once before any children are run.

def tearDown(self)

Run after each child is run.

def tearDownAll(self)

Run after all children have run.

class AutoTree(TestContainer)

TestContainer that Automatically adds methods of the form test_* as child Tests.

def __init__(self, children=None, name=AUTO)
children

Optional nested list of subnodes.

name

The name of this node. Should not contain spaces or periods. If set to the special constant AUTO, the name is computed automatically from the class name of this instance.

Automatically adds methods of the form test_* as child Tests.

class Test(_TestBase)

A node representing a test.

def __init__(self, name)
name
The name of this node. Should not contain spaces or periods.
def __call__(self)

This method contains the actual test.

class CallableNode(Test)

A utility wrapper to create a Test from a callable.

def __init__(self, name, obj)
name
Name of this test.
obj
A callable object.

Copyright Nullcube 2008