Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 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):
18 
19 
20  def tearDown(self):
21  pass
22 
23  def testFileLoad(self):
24  '''Test loading of previously written file.'''
25  self.control = Control.Environment(useAsWriter = True)
26  self.control.unset('varToUnset')
27 
28  self.control.declare('myVar', 'list', True)
29  self.control.set('myVar', 'setVal:$local')
30  self.control.append('myVar', 'appVal:appVal2')
31  self.control.prepend('myVar', 'prepVal:prepVal2')
32 
33  self.control.declare('myScalar', 'scalar', False)
34  self.control.set('myScalar', 'setValscal')
35  self.control.append('myScalar', 'appValscal')
36  self.control.prepend('myScalar', 'prepValscal')
37 
38  self.control.declare('myScalar2', 'scalar', True)
39 
40  self.control.finishXMLinput('testOutputFile.xml')
41 
42  loader = xmlModule.XMLFile()
43  variables = loader.variable('testOutputFile.xml')
44 
45  expected = [('declare', ('varToUnset', 'list', 'false')),
46  ('unset', ('varToUnset', '', None)),
47  ('declare', ('myVar', 'list', 'true')),
48  ('set', ('myVar', 'setVal:$local', None)),
49  ('append', ('myVar', 'appVal:appVal2', None)),
50  ('prepend', ('myVar', 'prepVal:prepVal2', None)),
51  ('declare', ('myScalar', 'scalar', 'false')),
52  ('set', ('myScalar', 'setValscal', None)),
53  ('append', ('myScalar', 'appValscal', None)),
54  ('prepend', ('myScalar', 'prepValscal', None)),
55  ('declare', ('myScalar2', 'scalar', 'true'))]
56 
57  self.assertEqual(variables, expected)
58 
59  os.remove('testOutputFile.xml')
60 
61  def testCheck(self):
62  '''Test if the XML file check works'''
63  self.control = Control.Environment(useAsWriter = True)
64  self.control.append('myVar', 'app1:app2')
65  self.control.prepend('myVar', 'app1:pre2')
66  self.control.unset('myVar')
67  self.control.set('myVar', 'set1:app2')
68 
69  self.control.finishXMLinput('testOutputFile.xml')
70  self.operations.check('testOutputFile.xml')
71 
72  self.assertEqual(self.operations.report.error(0)[1], 'myVar')
73  self.assertEqual(self.operations.report.error(0)[2], 'unset overwrite')
74  self.assertEqual(self.operations.report.error(1)[1], 'myVar')
75  self.assertEqual(self.operations.report.error(1)[2], 'set overwrite')
76 
77  os.remove('testOutputFile.xml')
78 
79  def testMerge(self):
80  self.control = Control.Environment(useAsWriter = True)
81 
82 
83  self.control.set('MY_PATH','delVal')
84  self.control.unset('MY_PATH')
85 
86  self.control.set('MY_PATH','setVal:multVal')
87  self.control.append('MY_PATH','appVal:multVal2')
88  self.control.prepend('MY_PATH','prepVal')
89 
90  self.control.finishXMLinput('testOutputFile.xml')
91 
92  self.control.startXMLinput()
93  self.control.append('MY_PATH','appVal2')
94  self.control.prepend('MY_PATH','prepVal2:multVal:multVal2')
95  self.control.remove('MY_PATH','multVal2')
96  self.control.finishXMLinput('testOutputFile2.xml')
97 
98  self.operations.merge('testOutputFile.xml', 'testOutputFile2.xml', 'testOutputFile.xml')
99 
101  self.control.loadXML('testOutputFile.xml')
102 
103  self.assertFalse('delVal' in self.control['MY_PATH'])
104 
105  self.assertTrue('appVal' in self.control['MY_PATH'])
106  self.assertTrue('appVal2' in self.control['MY_PATH'])
107  self.assertTrue('prepVal' in self.control['MY_PATH'])
108  self.assertTrue('prepVal' in self.control['MY_PATH'])
109  self.assertTrue('prepVal2' in self.control['MY_PATH'])
110  self.assertTrue('multVal' in self.control['MY_PATH'])
111  self.assertTrue('setVal' in self.control['MY_PATH'])
112 
113  self.assertFalse('multVal2' in self.control['MY_PATH'])
114 
115  os.remove('testOutputFile.xml')
116  os.remove('testOutputFile2.xml')
117 
118  def testParsing(self):
119  data = StringIO('''<?xml version="1.0" ?>
120 <env:config xmlns:env="EnvSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="EnvSchema ./EnvSchema.xsd ">
121 <env:declare local="false" type="list" variable="varToUnset"/>
122 <env:unset variable="varToUnset"/>
123 <env:declare local="true" type="list" variable="myVar"/>
124 <env:set variable="myVar">setVal:$local</env:set>
125 <env:append variable="myVar">appVal:appVal2</env:append>
126 <env:prepend variable="myVar">prepVal:prepVal2</env:prepend>
127 <env:declare local="false" type="scalar" variable="myScalar"/>
128 <env:set variable="myScalar">setValscal</env:set>
129 <env:append variable="myScalar">appValscal</env:append>
130 <env:prepend variable="myScalar">prepValscal</env:prepend>
131 <env:declare local="true" type="scalar" variable="myScalar2"/>
132 <env:include>some_file.xml</env:include>
133 <env:include hints="some:place">another_file.xml</env:include>
134 </env:config>''')
135 
136  loader = xmlModule.XMLFile()
137  variables = loader.variable(data)
138 
139  expected = [('declare', ('varToUnset', 'list', 'false')),
140  ('unset', ('varToUnset', '', None)),
141  ('declare', ('myVar', 'list', 'true')),
142  ('set', ('myVar', 'setVal:$local', None)),
143  ('append', ('myVar', 'appVal:appVal2', None)),
144  ('prepend', ('myVar', 'prepVal:prepVal2', None)),
145  ('declare', ('myScalar', 'scalar', 'false')),
146  ('set', ('myScalar', 'setValscal', None)),
147  ('append', ('myScalar', 'appValscal', None)),
148  ('prepend', ('myScalar', 'prepValscal', None)),
149  ('declare', ('myScalar2', 'scalar', 'true')),
150  ('include', ('some_file.xml', None, '')),
151  ('include', ('another_file.xml', None, 'some:place'))]
152 
153  self.assertEqual(variables, expected)
154 
155 if __name__ == "__main__":
156  #import sys;sys.argv = ['', 'Test.testName']
157  unittest.main()

Generated at Wed Nov 28 2012 12:17:09 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004