view tests/test_factory.txt @ 62:97800b02f636

shouldnt need to go through the whole sequence when youre wrapping a known section
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 09 Jun 2011 09:11:47 -0700
parents b98cc94ffcfa
children 418289c0fe3c
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'