Mercurial > hg > pyloader
annotate tests/test_ini.txt @ 89:7fdd934855bf
needs a bit more thought
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 21 Mar 2014 23:04:01 -0700 |
parents | 122e3eddcdeb |
children |
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] | |
54
f724db086125
houston, we have a pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
35 |
59
6b48dee5b92b
add a failing test for wrapper of type [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
36 Now let's test a simple wrapper, [readable-fibonacci:@:%(here)s/objects.py:fib]:: |
54
f724db086125
houston, we have a pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
37 |
f724db086125
houston, we have a pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
38 >>> fib = inifactory.load('readable-fibonacci') |
f724db086125
houston, we have a pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
39 >>> [fib(i) for i in range(5)] |
f724db086125
houston, we have a pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
40 ['one', 'one', 'two', 'three', 5] |
59
6b48dee5b92b
add a failing test for wrapper of type [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
41 |
64
f0f3525486db
test calling the section wrapper, [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
42 A different kind of wrapper, wrapping a section, [foo:@:fibonacci]:: |
59
6b48dee5b92b
add a failing test for wrapper of type [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
43 |
6b48dee5b92b
add a failing test for wrapper of type [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
44 >>> fib = inifactory.load('foo') |
61
926caecf385d
check in a passing test for a change
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
45 >>> 'objects.py.Wrapper' in repr(fib) |
926caecf385d
check in a passing test for a change
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
46 True |
926caecf385d
check in a passing test for a change
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
47 >>> inifactory.config['foo']['kwargs']['app'] |
926caecf385d
check in a passing test for a change
Jeff Hammel <jhammel@mozilla.com>
parents:
59
diff
changeset
|
48 '%(fibonacci)s' |
64
f0f3525486db
test calling the section wrapper, [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
49 >>> [fib(i) for i in range(6)] |
f0f3525486db
test calling the section wrapper, [foo:@:fibonacci]
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
50 ['one', 'one', 'two', 'three', 5, 8] |
69
b9d9a94bfa19
override section now works
Jeff Hammel <jhammel@mozilla.com>
parents:
64
diff
changeset
|
51 |
b9d9a94bfa19
override section now works
Jeff Hammel <jhammel@mozilla.com>
parents:
64
diff
changeset
|
52 Override a section with additional arguments, [bar:fibonacci], n=5:: |
b9d9a94bfa19
override section now works
Jeff Hammel <jhammel@mozilla.com>
parents:
64
diff
changeset
|
53 |
b9d9a94bfa19
override section now works
Jeff Hammel <jhammel@mozilla.com>
parents:
64
diff
changeset
|
54 >>> bar = inifactory.load('bar') |
b9d9a94bfa19
override section now works
Jeff Hammel <jhammel@mozilla.com>
parents:
64
diff
changeset
|
55 >>> bar # [1,1,2,3,5,8][5] |
b9d9a94bfa19
override section now works
Jeff Hammel <jhammel@mozilla.com>
parents:
64
diff
changeset
|
56 8 |
75
20bdb8125817
inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents:
69
diff
changeset
|
57 |
20bdb8125817
inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents:
69
diff
changeset
|
58 Test inline wrapper arguments, [extended-fibonacci:@:four=4,five=5:fibonacci]:: |
20bdb8125817
inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents:
69
diff
changeset
|
59 |
20bdb8125817
inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents:
69
diff
changeset
|
60 >>> extended = inifactory.load('extended-fibonacci') |
20bdb8125817
inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents:
69
diff
changeset
|
61 >>> [extended(i) for i in range(6)] |
20bdb8125817
inline wrapper arguments now seem to work....thats....uncanny
Jeff Hammel <jhammel@mozilla.com>
parents:
69
diff
changeset
|
62 ['one', 'one', 'two', 'three', 'five', 8] |
76 | 63 >>> extended2 = inifactory.load('extended-fibonacci-2') |
64 >>> [extended2(i) for i in range(6)] | |
65 ['one', 'one', 'two', 'three', 'five', 'eight'] | |
79
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
66 |
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
67 You can do arguments more verbosely too. extended-fibonacci-3 |
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
68 should be identical to extended-fibonacci but more broken up:: |
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
69 |
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
70 >>> extended3 = inifactory.load('extended-fibonacci-3') |
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
71 >>> [extended3(i) for i in range(6)] |
122e3eddcdeb
test for verbose decorators
Jeff Hammel <jhammel@mozilla.com>
parents:
76
diff
changeset
|
72 ['one', 'one', 'two', 'three', 'five', 8] |