1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from twisted.trial import unittest
17 from elisa.core.tests.elisa_test_case import ElisaTestCase
18
19 import new, os, sys
20 import platform
21 from elisa.core import component
22 from elisa.core import config
23 from elisa.core import common
24
26
27 default_config = {'str_option': 'default str',
28 'list_option': ['default','list'],
29 'another_option': 'bar'
30
31 }
32
33 config_doc = {'str_option': 'a string option quoi',
34 'list_option': 'gimme a list'
35 }
36
37
38 dependencies = ['site','foo']
39
41 """
42 For test purpose this component depends explicitely on stdlib's modules
43 """
44
45 dependencies = ['site','sys', 'os.path']
46
50
51
55
59
61
63 """ Check the component correctly loads its config
64 """
65
66 comp = FooComponent()
67 conf = config.Config('test.conf')
68
69 section = {'str_option':'some string',
70 'list_option':['some','list'],
71 }
72 conf.set_section('foo', section)
73
74 comp.name = 'foo'
75 comp.id = 0
76 comp.load_config(conf)
77
78 keys = comp.config.keys()
79 self.failUnless('str_option' in keys)
80 self.failUnless('list_option' in keys)
81 self.failUnless('another_option' in keys)
82
83 self.assertEqual(comp.config['str_option'], 'some string')
84 self.assertEqual(comp.config['list_option'], ['some', 'list'])
85 self.assertEqual(comp.config['another_option'], 'bar')
86
99
101 """ Check we can use multiple instances of the same component
102
103 But with different configurations
104 """
105 conf = config.Config('test.conf')
106
107 section0 = {'str_option':'some string',
108 'list_option':['some','list'],
109 }
110 conf.set_section('foo:0', section0)
111
112
113 comp0 = FooComponent()
114 comp0.name = 'foo'
115 comp0.id = 0
116 comp0.load_config(conf)
117
118
119 comp1 = FooComponent()
120 comp1.name = 'foo'
121 comp1.id = 1
122 comp1.load_config(conf)
123
124 keys = comp0.config.keys()
125 self.failUnless('str_option' in keys)
126 self.failUnless('list_option' in keys)
127 self.failUnless('another_option' in keys)
128
129 self.assertEqual(comp0.config['str_option'], 'some string')
130 self.assertEqual(comp0.config['list_option'], ['some', 'list'])
131 self.assertEqual(comp0.config['another_option'], 'bar')
132
133 self.assertEqual(comp1.config, comp1.default_config)
134
159
173 dep = component.parse_dependency("pgm")
174 self.assertEqual(dep, ("pgm", "", ""))
175
176 for sign in ("=", "==", ">=", ">", "<=", "<"):
177 dep = component.parse_dependency("pgm %s 0.3" % sign)
178 self.assertEqual(dep, ("pgm", sign, "0.3"))
179
181
182 mod = new.module('test_module')
183 mod.__version__ = '0.1'
184
185 for sign in ("=", "==", ">=", "<="):
186 self.failUnless(component._check_version('test_component',
187 'test_module', mod,
188 sign, '0.1'))
189 self.assertRaises(component.UnMetDependency,
190 component._check_version,'test_component',
191 'test_module', mod, '>',
192 '0.2')
193
194 del mod.__version__
195 self.failIf(component._check_version('test_component', 'test_module',
196 mod, '==', '0.1'))
197
198 def version():
199 return (0, 1)
200
201 mod.version = version
202 self.failUnless(component._check_version('test_component', 'test_module',
203 mod, '==', '0.1'))
204
215