comparison tests/test_factory.txt @ 15:0bea5297c156

introduce a more betterer test
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 May 2011 18:56:00 -0700
parents ff272dcd5cd8
children 11039ffec62a
comparison
equal deleted inserted replaced
14:30979d82c95d 15:0bea5297c156
3 3
4 Boilerplate:: 4 Boilerplate::
5 5
6 >>> import os 6 >>> import os
7 >>> from pyloader.factory import PyFactory 7 >>> from pyloader.factory import PyFactory
8 >>> objects = os.path.join(here, 'objects.py')
8 9
9 Construct a factory:: 10 Construct a factory::
10 11
11 >>> factory = PyFactory() 12 >>> factory = PyFactory()
12 13
13 Make a configuration:: 14 Make a configuration::
14 15
15 >>> config = {'': {'path': os.path.join(here, 'objects.py:stringsort'), 'args': ['foo', 'bar']}} 16 >>> config = {'': {'path': objects + ':stringsort', 'args': ['foo', 'bar']}}
16 17
17 Load it:: 18 Load it::
18 19
19 >>> factory.configure(config) 20 >>> factory.configure(config)
20 21
21 Get the thing:: 22 Get the thing::
22 23
23 >>> factory.load() 24 >>> factory.load()
24 'abfoor' 25 'abfoor'
26
27 Now lets try something better!::
28
29 >>> config = {'': {'path': objects + ':StringMunge', 'kwargs': {'prefix': 'PRE', 'callback': '%(callback)s'}},
30 ... 'callback': {'path': objects + ':stringsort'} }
31 >>> factory.configure(config)
32 >>> obj = factory.load()
33 >>> obj('foobar')
34 'PRE:abfoor'