view tests/test_factory.txt @ 20:057ccfe310b2

finish basic form of .ini factory - that was easy
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 06 Jun 2011 07:33:37 -0700
parents 11039ffec62a
children b98cc94ffcfa
line wrap: on
line source

Test pyloader's Factory
=======================

Boilerplate::

    >>> import os
    >>> from pyloader.factory import PyFactory
    >>> objects = os.path.join(here, 'objects.py')

Construct a factory::

    >>> factory = PyFactory()

Make a configuration::

    >>> config = {'': {'path': objects + ':stringsort', 'args': ['foo', 'bar']}} 

Load it::

    >>> factory.configure(config)

Get the thing::

    >>> factory.load()
    'abfoor'

Now lets try something better!::

    >>> config = {'': {'path': objects + ':StringMunge', 'kwargs': {'prefix': 'PRE', 'callback': '%(callback)s'}},
    ...           'callback': {'path': objects + ':stringsort'} }
    >>> factory.configure(config)
    >>> obj = factory.load()
    >>> obj('foobar')
    'PRE:abfoor'

Let's test the .ini factory::

    >>> from pyloader.factory import IniFactory
    >>> inifile = os.path.join(here, 'test.ini')
    >>> inifactory = IniFactory(inifile)