| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TestXMLOps.py
Go to the documentation of this file.
1 '''
2 Created on Jul 15, 2011
3
4 @author: mplajner
5 '''
6 import unittest
7 import os
8 from StringIO import StringIO
9
10 from EnvConfig import Control
11 from EnvConfig import xmlModule
12
13 class Test(unittest.TestCase):
14
15
16 def setUp(self):
17 pass
18
19 def tearDown(self):
20 pass
21
22 def testFileLoad(self):
23 '''Test loading of previously written file.'''
24 self.control = Control.Environment(useAsWriter = True)
25 self.control.unset('varToUnset')
26
27 self.control.declare('myVar', 'list', True)
28 self.control.set('myVar', 'setVal:$local')
29 self.control.append('myVar', 'appVal:appVal2')
30 self.control.prepend('myVar', 'prepVal:prepVal2')
31
32 self.control.declare('myScalar', 'scalar', False)
33 self.control.set('myScalar', 'setValscal')
34 self.control.append('myScalar', 'appValscal')
35 self.control.prepend('myScalar', 'prepValscal')
36
37 self.control.declare('myScalar2', 'scalar', True)
38
39 self.control.finishXMLinput('testOutputFile.xml')
40
41 loader = xmlModule.XMLFile()
42 variables = loader.variable('testOutputFile.xml')
43
44 expected = [('declare', ('varToUnset', 'list', 'false')),
45 ('unset', ('varToUnset', '', None)),
46 ('declare', ('myVar', 'list', 'true')),
47 ('set', ('myVar', 'setVal:$local', None)),
48 ('append', ('myVar', 'appVal:appVal2', None)),
49 ('prepend', ('myVar', 'prepVal:prepVal2', None)),
50 ('declare', ('myScalar', 'scalar', 'false')),
51 ('set', ('myScalar', 'setValscal', None)),
52 ('append', ('myScalar', 'appValscal', None)),
53 ('prepend', ('myScalar', 'prepValscal', None)),
54 ('declare', ('myScalar2', 'scalar', 'true'))]
55
56 self.assertEqual(variables, expected)
57
58 os.remove('testOutputFile.xml')
59
60 def testParsing(self):
61 data = StringIO('''<?xml version="1.0" ?>
62 <env:config xmlns:env="EnvSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="EnvSchema ./EnvSchema.xsd ">
63 <env:declare local="false" type="list" variable="varToUnset"/>
64 <env:unset variable="varToUnset"/>
65 <env:declare local="true" type="list" variable="myVar"/>
66 <env:set variable="myVar">setVal:$local</env:set>
67 <env:append variable="myVar">appVal:appVal2</env:append>
68 <env:prepend variable="myVar">prepVal:prepVal2</env:prepend>
69 <env:declare local="false" type="scalar" variable="myScalar"/>
70 <env:set variable="myScalar">setValscal</env:set>
71 <env:append variable="myScalar">appValscal</env:append>
72 <env:prepend variable="myScalar">prepValscal</env:prepend>
73 <env:declare local="true" type="scalar" variable="myScalar2"/>
74 <env:include>some_file.xml</env:include>
75 <env:include hints="some:place">another_file.xml</env:include>
76 </env:config>''')
77
78 loader = xmlModule.XMLFile()
79 variables = loader.variable(data)
80
81 expected = [('declare', ('varToUnset', 'list', 'false')),
82 ('unset', ('varToUnset', '', None)),
83 ('declare', ('myVar', 'list', 'true')),
84 ('set', ('myVar', 'setVal:$local', None)),
85 ('append', ('myVar', 'appVal:appVal2', None)),
86 ('prepend', ('myVar', 'prepVal:prepVal2', None)),
87 ('declare', ('myScalar', 'scalar', 'false')),
88 ('set', ('myScalar', 'setValscal', None)),
89 ('append', ('myScalar', 'appValscal', None)),
90 ('prepend', ('myScalar', 'prepValscal', None)),
91 ('declare', ('myScalar2', 'scalar', 'true')),
92 ('include', ('some_file.xml', None, '')),
93 ('include', ('another_file.xml', None, 'some:place'))]
94
95 self.assertEqual(variables, expected)
96
97 if __name__ == "__main__":
98 #import sys;sys.argv = ['', 'Test.testName']
99 unittest.main()