/[escript]/trunk/escript/test/python/run_xml.py
ViewVC logotype

Diff of /trunk/escript/test/python/run_xml.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 874 by elspeth, Tue Oct 17 12:06:11 2006 UTC revision 957 by gross, Tue Feb 13 00:33:00 2007 UTC
# Line 8  __license__="""Licensed under the Open S Line 8  __license__="""Licensed under the Open S
8               http://www.opensource.org/licenses/osl-3.0.php"""               http://www.opensource.org/licenses/osl-3.0.php"""
9    
10  import unittest  import unittest
11  from esys.escript.modelframe import Model,Link,Simulation,ParameterSet,parse  from esys.escript.modelframe import Model,Link,Simulation,ParameterSet,ESySXMLParser,DataSource
12  import math  import math
13  from cStringIO import StringIO  from cStringIO import StringIO
14  from xml.dom import minidom  from xml.dom import minidom
15    import numarray
16    
17  class XMLDocumentTestCase(unittest.TestCase):  class XMLDocumentTestCase(unittest.TestCase):
18    
# Line 75  class SimulationTestCase(unittest.TestCa Line 76  class SimulationTestCase(unittest.TestCa
76                    
77      def testParseAndInstanceOfSimulation(self):      def testParseAndInstanceOfSimulation(self):
78                    
79          newSim = parse(self.xml)          xml = ESySXMLParser(self.xml)
80            newSim = xml.parse()[0]
81          assert (isinstance (newSim, Simulation))          assert (isinstance (newSim, Simulation))
82          newout = StringIO()          newout = StringIO()
83          newSim.writeXML(newout)          newSim.writeXML(newout)
# Line 141  class ParamaterSetTestCase(unittest.Test Line 143  class ParamaterSetTestCase(unittest.Test
143          assert ("gamma1" in xmlout)          assert ("gamma1" in xmlout)
144          assert ("gamma2" in xmlout)          assert ("gamma2" in xmlout)
145          assert ("gamma3" in xmlout)          assert ("gamma3" in xmlout)
146          parsable = parse(xmlout)          esysxml=ESySXMLParser(xmlout)
147            parsable = esysxml.parse()[0]
148          assert (isinstance (parsable, ParameterSet))          assert (isinstance (parsable, ParameterSet))
149          assert (self._dom(self.p).getElementsByTagName("ParameterSet"))          assert (self._dom(self.p).getElementsByTagName("ParameterSet"))
150    
151      def testParameterSetFromXML(self):      def testParameterSetFromXML(self):
152            s = StringIO()
153            self.p.writeXML(s)
154            s.reset()
155            xmlout = s.read()
156            esysxml=ESySXMLParser(xmlout)
157          doc = self._class(self.p)          doc = self._class(self.p)
158          pset = ParameterSet.fromDom(self._dom(self.p).getElementsByTagName("ParameterSet")[0])          pset = ParameterSet.fromDom(esysxml, self._dom(self.p).getElementsByTagName("ParameterSet")[0])
159          assert (isinstance(pset, ParameterSet))          assert (isinstance(pset, ParameterSet))
160          assert (isinstance(doc, ParameterSet))          assert (isinstance(doc, ParameterSet))
161          self.assertEqual(self.p.gamma1,doc.gamma1)          self.assertEqual(self.p.gamma1,doc.gamma1)
# Line 181  class ParamaterSetTestCase(unittest.Test Line 189  class ParamaterSetTestCase(unittest.Test
189          input.writeXML(s)          input.writeXML(s)
190          s.reset()          s.reset()
191          xmlout = s.read()          xmlout = s.read()
192          doc = parse(xmlout)          esysxml=ESySXMLParser(xmlout)
193            doc =esysxml.parse()[0]
194          return doc          return doc
195    
196      def testFromDomInt(self):      def testFromDomInt(self):
# Line 191  class ParamaterSetTestCase(unittest.Test Line 200  class ParamaterSetTestCase(unittest.Test
200          assert type(doc.inttest)==int          assert type(doc.inttest)==int
201    
202      def testFromDomNumarrayVector(self):      def testFromDomNumarrayVector(self):
         import numarray  
203          p3 = ParameterSet()          p3 = ParameterSet()
204          mynumarray = numarray.array([3., 4., 5.], type=numarray.Float64)          mynumarray = numarray.array([3., 4., 5.], type=numarray.Float64)
205          p3.declareParameter(numtest=mynumarray)          p3.declareParameter(numtest=mynumarray)
# Line 200  class ParamaterSetTestCase(unittest.Test Line 208  class ParamaterSetTestCase(unittest.Test
208          assert type(doc.numtest) == numarray.NumArray          assert type(doc.numtest) == numarray.NumArray
209    
210      def testFromDomNumarrayMulti(self):      def testFromDomNumarrayMulti(self):
         import numarray  
211          p3 = ParameterSet()          p3 = ParameterSet()
212          mynumarray = numarray.array([[1., 2., 3.], [3., 4., 5.]], type=numarray.Float64)          mynumarray = numarray.array([[1., 2., 3.], [3., 4., 5.]], type=numarray.Float64)
213          p3.declareParameter(numtest=mynumarray)          p3.declareParameter(numtest=mynumarray)
# Line 208  class ParamaterSetTestCase(unittest.Test Line 215  class ParamaterSetTestCase(unittest.Test
215          assert doc.numtest.type() == numarray.Float64          assert doc.numtest.type() == numarray.Float64
216          assert type(doc.numtest) == numarray.NumArray          assert type(doc.numtest) == numarray.NumArray
217    
218      def testLists(self):      def testBoolLists(self):
219          p4 = ParameterSet()          p4 = ParameterSet()
220          mylist = [True, False, False, True]          mylist = [True, False, False, True]
221          p4.declareParameter(listest=mylist)          p4.declareParameter(listest=mylist)
222          doc = self._class(p4)          doc = self._class(p4)
223            assert type(doc.listest) == numarray.NumArray
224            assert doc.listest.type() == numarray.Bool
225            assert len(doc.listest) == len(mylist)
226            assert min([ mylist[i] == doc.listest[i] for i in range(len( doc.listest)) ])
227    
228        def testIntLists(self):
229            p4 = ParameterSet()
230            mylist = [1,2,4]
231            p4.declareParameter(listest=mylist)
232            doc = self._class(p4)
233            assert type(doc.listest) == numarray.NumArray
234            assert doc.listest.type() == numarray.Int
235            assert len(doc.listest) == len(mylist)
236            assert min([ mylist[i] == doc.listest[i] for i in range(len( doc.listest)) ])
237    
238        def testFloatLists(self):
239            p4 = ParameterSet()
240            mylist = [1.,2.,4.]
241            p4.declareParameter(listest=mylist)
242            doc = self._class(p4)
243            assert type(doc.listest) == numarray.NumArray
244            assert doc.listest.type() == numarray.Float
245            assert len(doc.listest) == len(mylist)
246            assert min([ mylist[i] == doc.listest[i] for i in range(len( doc.listest)) ])
247    
248        def testStringLists(self):
249            p4 = ParameterSet()
250            mylist = ["a", "b", "c"]
251            p4.declareParameter(listest=mylist)
252            doc = self._class(p4)
253          assert type(doc.listest) == list          assert type(doc.listest) == list
254          self.assertEquals(mylist, doc.listest)          assert len(doc.listest) == len(mylist)
255          assert type(doc.listest[0]) == bool          assert min([ mylist[i] == doc.listest[i] for i in range(len( doc.listest)) ])
256                    
257        def testDatasource(self):
258            p5 = ParameterSet()
259            myURI = DataSource("somelocalfile.txt", "text")
260            p5.declareParameter(uritest=myURI)
261            doc = self._class(p5)
262            self.assertEquals(myURI.uri, doc.uritest.uri)
263            self.assertEquals(myURI.fileformat, doc.uritest.fileformat)
264            assert type(doc.uritest) == DataSource
265                    
266    
267          
268  class ModeltoDomTestCase(unittest.TestCase):  class ModeltoDomTestCase(unittest.TestCase):
269            
270      def _class(self):      def _class(self):
# Line 226  class ModeltoDomTestCase(unittest.TestCa Line 273  class ModeltoDomTestCase(unittest.TestCa
273          self.o1.writeXML(s)          self.o1.writeXML(s)
274          s.reset()          s.reset()
275          self.xmlout = s.read()          self.xmlout = s.read()
276          doc = parse(self.xmlout)          esysxml=ESySXMLParser(xmlout)
277            doc =esysxml.parse()[0]
278          return doc          return doc
279    
280      def _dom(self):      def _dom(self):
# Line 282  type="float"> <Name> tend </Name> <Value Line 330  type="float"> <Name> tend </Name> <Value
330    <Component rank="2"> <Model id="129" type="Messenger"> <Parameter    <Component rank="2"> <Model id="129" type="Messenger"> <Parameter
331    type="Link"> <Name> message </Name> <Value> <Link> <Target> 127 </Target>    type="Link"> <Name> message </Name> <Value> <Link> <Target> 127 </Target>
332    <Attribute> message </Attribute> </Link> </Value> </Parameter> </Model>    <Attribute> message </Attribute> </Link> </Value> </Parameter> </Model>
333    </Component> </Simulation> <Model id="128" type="ODETEST"> <Parameter    </Component> </Simulation> <Model id="150" type="ODETEST"> <Parameter
334    type="float"> <Name> a </Name> <Value>    type="float"> <Name> a </Name> <Value>
335  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>
336    <Link> <Target> 127 </Target> <Attribute> u </Attribute> </Link> </Value>    <Link> <Target> 127 </Target> <Attribute> u </Attribute> </Link> </Value>
# Line 292  type="float"> <Name> tend </Name> <Value Line 340  type="float"> <Name> tend </Name> <Value
340    <Value> 1e-08 </Value> </Parameter> <Parameter type="float"> <Name> dt    <Value> 1e-08 </Value> </Parameter> <Parameter type="float"> <Name> dt
341    </Name> <Value>    </Name> <Value>
342  0.1 </Value> </Parameter> <Parameter type="str"> <Name> message </Name> <Value>  0.1 </Value> </Parameter> <Parameter type="str"> <Name> message </Name> <Value>
343    current error = 1.904837e+01 </Value> </Parameter> </Model> <Model id="127"    current error = 1.904837e+01 </Value> </Parameter> </Model> <Model id="130"
344    type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>    type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>
345  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>
346    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>
# Line 303  type="float"> <Name> tend </Name> <Value Line 351  type="float"> <Name> tend </Name> <Value
351    <Value>    <Value>
352  0.01 </Value> </Parameter> <Parameter type="str"> <Name> message </Name>  0.01 </Value> </Parameter> <Parameter type="str"> <Name> message </Name>
353    <Value> current error = 9.516258e-01 </Value> </Parameter> </Model> <Model    <Value> current error = 9.516258e-01 </Value> </Parameter> </Model> <Model
354    id="127" type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>    id="170" type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>
355  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>
356    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>
357    </Parameter> <Parameter type="float"> <Name> tend </Name> <Value>    </Parameter> <Parameter type="float"> <Name> tend </Name> <Value>
# Line 316  type="float"> <Name> tend </Name> <Value Line 364  type="float"> <Name> tend </Name> <Value
364  ''' % (modulename, modelname)  ''' % (modulename, modelname)
365    
366      def testModuleAttribute(self):      def testModuleAttribute(self):
367          modeldoc = parse(self._xml('run_xml', 'ODETEST'))          esysxml=ESySXMLParser(self._xml('run_xml', 'ODETEST'))
368            modeldoc=esysxml.parse()[0]
369    
370      def testModuleAttributeFails(self):      def testModuleAttributeFails(self):
371          try:          try:
372              modeldoc = parse(self._xml('a', 'b'))              esysxml=ESySXMLParser(self._xml('a', 'b'))
373                modeldoc=esysxml.parse()[0]
374          except ImportError:          except ImportError:
375              return # correct              return # correct
376    

Legend:
Removed from v.874  
changed lines
  Added in v.957

  ViewVC Help
Powered by ViewVC 1.1.26