view tests/test_ini.txt @ 61:926caecf385d

check in a passing test for a change
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 09 Jun 2011 09:09:48 -0700
parents 6b48dee5b92b
children 97800b02f636
line wrap: on
line source

Test IniFactory
===============

Let's test the .ini factory::

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

Load it up::

    >>> object = inifactory.load()
    >>> 'objects.py.StringMunge' in repr(object.__class__)
    True

Call it::

    >>> object('foobar')
    'PRE!!!abfoor'

You can also just load the callback::

    >>> callback = inifactory.load('callback')
    >>> callback('foo', 'bar')
    'abfoor'

Lets test the Fibonnaci sequence::

    >>> fib = inifactory.load('fibonacci')
    >>> fib(0) == fib(1) == 1
    True
    >>> [fib(i) for i in range(5)]
    [1, 1, 2, 3, 5]

Now let's test a simple wrapper, [readable-fibonacci:@:%(here)s/objects.py:fib]::

    >>> fib = inifactory.load('readable-fibonacci')
    >>> [fib(i) for i in range(5)]
    ['one', 'one', 'two', 'three', 5]

A different kind of wrapper, [foo:@:fibonacci]::

    >>> fib = inifactory.load('foo')
    >>> 'objects.py.Wrapper' in repr(fib)
    True
    >>> inifactory.config['foo']['kwargs']['app']
    '%(fibonacci)s'