storable

Storable Fixture objects.

In other words : Fixture descendants to work with specific Stor objects.


Functions

f find_so_from_data(meta, fixture_class) ...

finder method for SOFixture that transforms SomeFixtureData into the name SomeFixture.

f find_so_from_fixture(meta, fixture_class) ...

finder method for SOFixture that passes through your fixture name (no transformation).

This is the default.

f find_so_from_table(meta, fixture_class) ...

finder method for SOFixture that transforms your fixture class as if it were a table name.

It assumes your fixture class is named exactly like your database table name and its SQLObject should be translated like it would in SQLObject land.

i.e. fixture class products_to_offers becomes ProductsToOffers

Classes

C CsvFixture(...) ...

Fixture storable as a CSV file.

The following are attributes you can set as keywords or meta attributes (see Fixture for examples on configuring a class using meta)

  • addfields -- if True first row in the CSV file will contain a field list

  • data -- dataset(s) to load (see Fixture for format)

  • encoding -- string encoding to use when writing to file

  • fields -- field list (if None, fields will be keys of the first data item)

  • filename -- name of file or filelike object

  • mknewfile -- factory method for file objects. if not None and filename is not None and no filename is passed to the constructor then this is expected to return an open file handle. It will be called with its first argument the instance of the Fixture class. Note that any meta method needs to be wrapped in

    testtools.fixtures.metamethod ; see example of this below...

  • dialect -- csv dialect to use (default: excel)

Here is an example of declaring a mknewfile factory method:

>>> from testtools.fixtures import CsvFixture, metamethod
>>> from os import path
>>> @metamethod
... def mk_new_bookfile(fxt):
...     print fxt
...     return open('/tmp/testtools_example.csv', 'w')
...
>>> class MyBooks(CsvFixture):
...     class meta:
...         mknewfile = mk_new_bookfile
...         data = (('Yann Martel', {'title': 'Life of Pi'}),)
...
>>> fxt = MyBooks()
<class 'MyBooks' keys=() from module testtools.fixtures.storable>
>>> fxt.close()
>>> assert path.exists('/tmp/testtools_example.csv')

NOTE: at the time the fixture instance is passed into the factory method, it obviously will contain no data. Its use would be primarily for making decisions on what file to return.

This class contains 2 members.

C SOFixture(...) ...

Fixture storable by an SQLObject.

The following are attributes you can set as keywords or meta attributes (see Fixture for examples on configuring a class using meta)

  • data -- datasets to load (see Fixture for format)
  • so_class -- default SQLObject class to use (if missing, SOFixture.find_so_class will be consulted)
  • env -- dict or something with attributes
  • finder -- callable to get so_class from self.__class__ (default is find_so_from_fixture )
  • clean -- if True, object is cleanable (defaults to False)
  • autocommit -- if False (default) storage is performed in a transaction. see SOStor .

This class contains 3 members.

See the source for more information.