Mercurial > hg > pyloader
view 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 |
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, wrapping a section, [foo:@:fibonacci]:: >>> fib = inifactory.load('foo') >>> 'objects.py.Wrapper' in repr(fib) True >>> inifactory.config['foo']['kwargs']['app'] '%(fibonacci)s' >>> [fib(i) for i in range(6)] ['one', 'one', 'two', 'three', 5, 8] Override a section with additional arguments, [bar:fibonacci], n=5:: >>> bar = inifactory.load('bar') >>> bar # [1,1,2,3,5,8][5] 8 Test inline wrapper arguments, [extended-fibonacci:@:four=4,five=5:fibonacci]:: >>> extended = inifactory.load('extended-fibonacci') >>> [extended(i) for i in range(6)] ['one', 'one', 'two', 'three', 'five', 8] >>> extended2 = inifactory.load('extended-fibonacci-2') >>> [extended2(i) for i in range(6)] ['one', 'one', 'two', 'three', 'five', 'eight'] You can do arguments more verbosely too. extended-fibonacci-3 should be identical to extended-fibonacci but more broken up:: >>> extended3 = inifactory.load('extended-fibonacci-3') >>> [extended3(i) for i in range(6)] ['one', 'one', 'two', 'three', 'five', 8]