Mercurial > hg > pyloader
annotate tests/test_factory.txt @ 24:ce8fa574324d
fix syntax error
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 06 Jun 2011 07:46:47 -0700 |
parents | 11039ffec62a |
children | b98cc94ffcfa |
rev | line source |
---|---|
11 | 1 Test pyloader's Factory |
2 ======================= | |
3 | |
4 Boilerplate:: | |
5 | |
6 >>> import os | |
7 >>> from pyloader.factory import PyFactory | |
15
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
8 >>> objects = os.path.join(here, 'objects.py') |
11 | 9 |
10 Construct a factory:: | |
11 | |
12 >>> factory = PyFactory() | |
13 | |
14 Make a configuration:: | |
15 | |
15
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
16 >>> config = {'': {'path': objects + ':stringsort', 'args': ['foo', 'bar']}} |
11 | 17 |
18 Load it:: | |
19 | |
20 >>> factory.configure(config) | |
21 | |
22 Get the thing:: | |
23 | |
24 >>> factory.load() | |
25 'abfoor' | |
15
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
26 |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
27 Now lets try something better!:: |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
28 |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
29 >>> config = {'': {'path': objects + ':StringMunge', 'kwargs': {'prefix': 'PRE', 'callback': '%(callback)s'}}, |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
30 ... 'callback': {'path': objects + ':stringsort'} } |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
31 >>> factory.configure(config) |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
32 >>> obj = factory.load() |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
33 >>> obj('foobar') |
0bea5297c156
introduce a more betterer test
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
34 'PRE:abfoor' |
17 | 35 |
36 Let's test the .ini factory:: | |
37 | |
38 >>> from pyloader.factory import IniFactory | |
39 >>> inifile = os.path.join(here, 'test.ini') | |
40 >>> inifactory = IniFactory(inifile) |