File: test_manager.py

package info (click to toggle)
python-setoptconf 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: python: 1,427; sh: 7; makefile: 5
file content (44 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os

import setoptconf as soc


class Blah(object):
    foo = 'a'

os.environ['TESTME_BAR'] = '123'

mgr = soc.ConfigurationManager('testme')
mgr.add(soc.StringSetting('foo'))
mgr.add(soc.IntegerSetting('bar', required=True))
mgr.add(soc.BooleanSetting('baz', default=True))

config = mgr.retrieve(
    soc.EnvironmentVariableSource,
    soc.ObjectSource(Blah),
    soc.MappingSource({'baz': False}),
)

assert config.foo == 'a'
assert config.bar == 123
assert config.baz is False


try:
    mgr.add('blah')
except TypeError:
    pass
else:
    assert False, 'Expected TypeError for bogus Setting'


try:
    config = mgr.retrieve(
        soc.EnvironmentVariableSource,
        'foo',
    )
except TypeError:
    pass
else:
    assert False, 'Expected TypeError for bogus Source'