COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-python-options.py
Go to the documentation of this file.
1 import coolfluid as cf
2 import sys
3 
4 root = cf.Core.root()
5 
6 cf.Core.environment().options().set('log_level', 4)
7 
8 def check_option(comp, optname, value):
9  print 'option', optname, 'for component', comp.uri(), 'has value', comp.options()[optname], 'and should be', value
10  if comp.options()[optname] != value:
11  raise Exception('Bad option value')
12 
13 def test_option(comp, optname, value):
14  comp.options().set(optname, value)
15  check_option(comp, optname, value)
16 
17 opts01 = root.create_component('opts01', 'cf3.python.TestAllOptions')
18 
19 test_option(opts01, 'string', 'teststring')
20 test_option(opts01, 'real', 2.)
21 test_option(opts01, 'real', 2)
22 test_option(opts01, 'int', 3)
23 test_option(opts01, 'uint', 4)
24 test_option(opts01, 'bool', True)
25 test_option(opts01, 'uri', opts01.uri())
26 test_option(opts01, 'generic_component', opts01)
27 test_option(opts01, 'group_component', root)
28 test_option(opts01, 'string_vector', ['a', 'b', 'c'])
29 test_option(opts01, 'int_vector', [0, 1, 2])
30 test_option(opts01, 'uint_vector', [0, 1, 2])
31 test_option(opts01, 'real_vector', [0, 1.2, 2.9])
32 test_option(opts01, 'real_vector', [0, 1, 2])
33 test_option(opts01, 'bool_vector', [False, True, False])
34 test_option(opts01, 'generic_component_vector', [opts01, root])
35 test_option(opts01, 'group_component_vector', [root, root])
36 
37 print '########################### Testing global config ##########################'
38 
39 # test configure signal
40 testgrp = opts01.create_component('testgrp', 'cf3.common.Group')
41 testgen = opts01.create_component('testgen', 'cf3.common.Component')
42 opts01.configure(string = 'global_config', real = 4, int = 5, uint = 6, bool = False, uri = testgen.uri(), generic_component = testgen, group_component = testgrp, string_vector = ['d', 'e'], int_vector = [3, 4, 5], uint_vector = [3, 4, 5], real_vector = [6, 7.2, 8.3], bool_vector = [True, False, True], generic_component_vector = [opts01, testgen], group_component_vector = [testgrp, root])
43 check_option(opts01, 'string', 'global_config')
44 check_option(opts01, 'real', 4.)
45 check_option(opts01, 'int', 5)
46 check_option(opts01, 'uint', 6)
47 check_option(opts01, 'bool', False)
48 check_option(opts01, 'uri', testgen.uri())
49 check_option(opts01, 'generic_component', testgen)
50 check_option(opts01, 'group_component', testgrp)
51 check_option(opts01, 'string_vector', ['d', 'e'])
52 check_option(opts01, 'int_vector', [3, 4, 5])
53 check_option(opts01, 'uint_vector', [3, 4, 5])
54 check_option(opts01, 'real_vector', [6, 7.2, 8.3])
55 check_option(opts01, 'bool_vector', [True, False, True])
56 check_option(opts01, 'generic_component_vector', [opts01, testgen])
57 check_option(opts01, 'group_component_vector', [testgrp, root])
58 
59 print '########################### Checking basic access ##########################'
60 
61 if opts01.string != 'global_config':
62  raise Exception('Bad option value')
63 
64 opts01.string = 'easy_set'
65 check_option(opts01, 'string', 'easy_set')
66 if opts01.string != 'easy_set':
67  raise Exception('Bad option value')
68 
69 opts01.const_component = root
70 check_option(opts01, 'const_component', root)
71 
72 print '########################### Checking access through options attribute ##########################'
73 
74 opts01.options.generic_component_vector = [testgen, opts01]
75 opts01.options['string_vector'] = ['f', 'g']
76 check_option(opts01, 'generic_component_vector', [testgen, opts01])
77 check_option(opts01, 'string_vector', ['f', 'g'])
78 
79 print '############## Access methods demo #############'
80 
81 print opts01.string # Only valid for basic options
82 print opts01.options.string
83 print opts01.options['string']
84 print opts01.options().string
85 print opts01.options()['string']
def check_option(comp, optname, value)
def test_option(comp, optname, value)
Send comments to:
COOLFluiD Web Admin