Mercurial > hg > pyloader
annotate tests/test_ini.txt @ 41:2c228e3cd6d8
split reading and interpreting the .ini into different functions
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 08 Jun 2011 17:50:05 -0700 |
parents | f6616a5f468f |
children | f724db086125 |
rev | line source |
---|---|
32
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 Test IniFactory |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 =============== |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 Let's test the .ini factory:: |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 >>> import os |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 >>> from pyloader.factory import IniFactory |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 >>> inifile = os.path.join(here, 'test.ini') |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 >>> inifactory = IniFactory(inifile) |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 Load it up:: |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 >>> object = inifactory.load() |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 >>> 'objects.py.StringMunge' in repr(object.__class__) |
b98cc94ffcfa
split IniFactory tests to their own file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 True |
33 | 16 |
17 Call it:: | |
18 | |
19 >>> object('foobar') | |
20 'PRE!!!abfoor' | |
34
a9eaf65d82c6
test loading a different section
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
21 |
a9eaf65d82c6
test loading a different section
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
22 You can also just load the callback:: |
a9eaf65d82c6
test loading a different section
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
23 |
a9eaf65d82c6
test loading a different section
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
24 >>> callback = inifactory.load('callback') |
a9eaf65d82c6
test loading a different section
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
25 >>> callback('foo', 'bar') |
a9eaf65d82c6
test loading a different section
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
26 'abfoor' |
38 | 27 |
28 Lets test the Fibonnaci sequence:: | |
29 | |
30 >>> fib = inifactory.load('fibonacci') | |
31 >>> fib(0) == fib(1) == 1 | |
32 True | |
33 >>> [fib(i) for i in range(5)] | |
34 [1, 1, 2, 3, 5] |