fixture.loadable

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:

dataclass
class to instantiate with datasets (defaults to that of Fixture)
style
a Style object to translate names with (defaults to NamedDataStyle)
medium
optional LoadableFixture.StorageMediumAdapter to store DataSet objects with
begin(unloading=False)
begin loading
commit()
commit load transaction
load(data)
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()
rollback load transaction
then_finally(unloading=False)
called in a finally block after load transaction has begun
unload()
unload data
unload_dataset(dataset)
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.

attach_storage_medium(ds)

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(unloading=False)
begin loading data
commit()
call transaction.commit() on transaction returned by DBLoadableFixture.create_transaction()
create_transaction()

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

Note

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

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

common interface for working with storable objects.

clear(obj)
Must clear the stored object.
clearall()
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)

visit_loader(loader)

A chance to visit the LoadableFixture object.

By default it does nothing.

Previous topic

fixture.io

Next topic

fixture.loadable.django_loadable