Abstract classes for fixture.base.Fixture descendants that load / unload data

See Using LoadableFixture for examples.

class fixture.loadable.LoadableFixture(style=None, medium=None, **kw)

Bases: fixture.base.Fixture

knows how to load data into something useful.

This is an abstract class and cannot be used directly. You can use a LoadableFixture that already knows how to load into a specific medium, such as SQLAlchemyFixture, or create your own to build your own to load DataSet objects into custom storage media.

Keyword Arguments:

class to instantiate with datasets (defaults to that of Fixture)
a Style object to translate names with (defaults to NamedDataStyle)
optional LoadableFixture.StorageMediumAdapter to store DataSet objects with
begin loading
commit load transaction
load data
load_dataset(ds, level=1)

load this dataset and all its dependent datasets.

level is essentially the order of processing (going from dataset to dependent datasets). Child datasets are always loaded before the parent. The level is important for visualizing the chain of dependencies : 0 is the bottom, and thus should be the first set of objects unloaded

resolve_row_references(current_dataset, row)
resolve this DataRow object’s referenced values.
rollback load transaction
called in a finally block after load transaction has begun
unload data
unload data stored for this dataset
wrap_in_transaction(routine, unloading=False)
call routine in a load transaction
class fixture.loadable.loadable.EnvLoadableFixture(env=None, **kw)

Bases: fixture.loadable.loadable.LoadableFixture

An abstract fixture that can resolve DataSet objects from an env.

Keyword “env” should be a dict or a module if not None. According to the style rules, the env will be used to find objects by name.


Lookup a storage medium in the env and attach it to a DataSet.

A storage medium is looked up by name. If a specific name has not been declared in the DataSet then it will be guessed using the Style.guess_storable_name method.

Once a name is found (typically the name of a DataSet class, say, EmployeeData) then it is looked up in the env which is expected to be a dict or module like object.

The method first tries env.get('EmployeeData') then getattr(env, 'EmployeeData').

The return value is the storage medium (i.e. a data mapper for the Employees table)

Note that a style might translate a name to maintain a consistent naming scheme between DataSet classes and data mappers.

class fixture.loadable.loadable.DBLoadableFixture(dsn=None, **kw)

Bases: fixture.loadable.loadable.EnvLoadableFixture

An abstract fixture that can load a DataSet into a database like thing.

More specifically, one that forces its implementation to run atomically (within a begin / commit / rollback block).

begin loading data
call transaction.commit() on transaction returned by DBLoadableFixture.create_transaction()

must return a transaction object that implements commit() and rollback()


transaction.begin() will not be called. If that is necessary then call begin before returning the object.

call transaction.rollback() on transaction returned by DBLoadableFixture.create_transaction()
class fixture.loadable.loadable.StorageMediumAdapter(medium, dataset)

common interface for working with storable objects.

Must clear the stored object.
Must clear all stored objects.
save(row, column_vals)

Given a DataRow, must save it somehow.

column_vals is an iterable of (column_name, column_value)


A chance to visit the LoadableFixture object.

By default it does nothing.

Previous topic

Next topic