/[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 875 by elspeth, Tue Oct 17 12:42:47 2006 UTC revision 918 by gross, Wed Jan 3 06:30: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,DataSource  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
# Line 75  class SimulationTestCase(unittest.TestCa Line 75  class SimulationTestCase(unittest.TestCa
75                    
76      def testParseAndInstanceOfSimulation(self):      def testParseAndInstanceOfSimulation(self):
77                    
78          newSim = parse(self.xml)          xml = ESySXMLParser(self.xml)
79            newSim = xml.parse()[0]
80          assert (isinstance (newSim, Simulation))          assert (isinstance (newSim, Simulation))
81          newout = StringIO()          newout = StringIO()
82          newSim.writeXML(newout)          newSim.writeXML(newout)
# Line 141  class ParamaterSetTestCase(unittest.Test Line 142  class ParamaterSetTestCase(unittest.Test
142          assert ("gamma1" in xmlout)          assert ("gamma1" in xmlout)
143          assert ("gamma2" in xmlout)          assert ("gamma2" in xmlout)
144          assert ("gamma3" in xmlout)          assert ("gamma3" in xmlout)
145          parsable = parse(xmlout)          esysxml=ESySXMLParser(xmlout)
146            parsable = esysxml.parse()[0]
147          assert (isinstance (parsable, ParameterSet))          assert (isinstance (parsable, ParameterSet))
148          assert (self._dom(self.p).getElementsByTagName("ParameterSet"))          assert (self._dom(self.p).getElementsByTagName("ParameterSet"))
149    
150      def testParameterSetFromXML(self):      def testParameterSetFromXML(self):
151            s = StringIO()
152            self.p.writeXML(s)
153            s.reset()
154            xmlout = s.read()
155            esysxml=ESySXMLParser(xmlout)
156          doc = self._class(self.p)          doc = self._class(self.p)
157          pset = ParameterSet.fromDom(self._dom(self.p).getElementsByTagName("ParameterSet")[0])          pset = ParameterSet.fromDom(esysxml, self._dom(self.p).getElementsByTagName("ParameterSet")[0])
158          assert (isinstance(pset, ParameterSet))          assert (isinstance(pset, ParameterSet))
159          assert (isinstance(doc, ParameterSet))          assert (isinstance(doc, ParameterSet))
160          self.assertEqual(self.p.gamma1,doc.gamma1)          self.assertEqual(self.p.gamma1,doc.gamma1)
# Line 181  class ParamaterSetTestCase(unittest.Test Line 188  class ParamaterSetTestCase(unittest.Test
188          input.writeXML(s)          input.writeXML(s)
189          s.reset()          s.reset()
190          xmlout = s.read()          xmlout = s.read()
191          doc = parse(xmlout)          esysxml=ESySXMLParser(xmlout)
192            doc =esysxml.parse()[0]
193          return doc          return doc
194    
195      def testFromDomInt(self):      def testFromDomInt(self):
# Line 209  class ParamaterSetTestCase(unittest.Test Line 217  class ParamaterSetTestCase(unittest.Test
217          assert type(doc.numtest) == numarray.NumArray          assert type(doc.numtest) == numarray.NumArray
218    
219      def testLists(self):      def testLists(self):
220            import numarray
221          p4 = ParameterSet()          p4 = ParameterSet()
222          mylist = [True, False, False, True]          mylist = [True, False, False, True]
223          p4.declareParameter(listest=mylist)          p4.declareParameter(listest=mylist)
224          doc = self._class(p4)          doc = self._class(p4)
225          assert type(doc.listest) == list          assert doc.listest.type() == numarray.Bool
226          self.assertEquals(mylist, doc.listest)          assert type(doc.listest) == numarray.NumArray
227          assert type(doc.listest[0]) == bool          assert numarray.all(numarray.equal(mylist, doc.listest))
228                    
229      def testDatasource(self):      def testDatasource(self):
230          p5 = ParameterSet()          p5 = ParameterSet()
# Line 236  class ModeltoDomTestCase(unittest.TestCa Line 245  class ModeltoDomTestCase(unittest.TestCa
245          self.o1.writeXML(s)          self.o1.writeXML(s)
246          s.reset()          s.reset()
247          self.xmlout = s.read()          self.xmlout = s.read()
248          doc = parse(self.xmlout)          esysxml=ESySXMLParser(xmlout)
249            doc =esysxml.parse()[0]
250          return doc          return doc
251    
252      def _dom(self):      def _dom(self):
# Line 292  type="float"> <Name> tend </Name> <Value Line 302  type="float"> <Name> tend </Name> <Value
302    <Component rank="2"> <Model id="129" type="Messenger"> <Parameter    <Component rank="2"> <Model id="129" type="Messenger"> <Parameter
303    type="Link"> <Name> message </Name> <Value> <Link> <Target> 127 </Target>    type="Link"> <Name> message </Name> <Value> <Link> <Target> 127 </Target>
304    <Attribute> message </Attribute> </Link> </Value> </Parameter> </Model>    <Attribute> message </Attribute> </Link> </Value> </Parameter> </Model>
305    </Component> </Simulation> <Model id="128" type="ODETEST"> <Parameter    </Component> </Simulation> <Model id="150" type="ODETEST"> <Parameter
306    type="float"> <Name> a </Name> <Value>    type="float"> <Name> a </Name> <Value>
307  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>
308    <Link> <Target> 127 </Target> <Attribute> u </Attribute> </Link> </Value>    <Link> <Target> 127 </Target> <Attribute> u </Attribute> </Link> </Value>
# Line 302  type="float"> <Name> tend </Name> <Value Line 312  type="float"> <Name> tend </Name> <Value
312    <Value> 1e-08 </Value> </Parameter> <Parameter type="float"> <Name> dt    <Value> 1e-08 </Value> </Parameter> <Parameter type="float"> <Name> dt
313    </Name> <Value>    </Name> <Value>
314  0.1 </Value> </Parameter> <Parameter type="str"> <Name> message </Name> <Value>  0.1 </Value> </Parameter> <Parameter type="str"> <Name> message </Name> <Value>
315    current error = 1.904837e+01 </Value> </Parameter> </Model> <Model id="127"    current error = 1.904837e+01 </Value> </Parameter> </Model> <Model id="130"
316    type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>    type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>
317  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>
318    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>
# Line 313  type="float"> <Name> tend </Name> <Value Line 323  type="float"> <Name> tend </Name> <Value
323    <Value>    <Value>
324  0.01 </Value> </Parameter> <Parameter type="str"> <Name> message </Name>  0.01 </Value> </Parameter> <Parameter type="str"> <Name> message </Name>
325    <Value> current error = 9.516258e-01 </Value> </Parameter> </Model> <Model    <Value> current error = 9.516258e-01 </Value> </Parameter> </Model> <Model
326    id="127" type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>    id="170" type="ODETEST"> <Parameter type="float"> <Name> a </Name> <Value>
327  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>  0.9 </Value> </Parameter> <Parameter type="Link"> <Name> f </Name> <Value>
328    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>    <Link> <Target> 128 </Target> <Attribute> u </Attribute> </Link> </Value>
329    </Parameter> <Parameter type="float"> <Name> tend </Name> <Value>    </Parameter> <Parameter type="float"> <Name> tend </Name> <Value>
# Line 326  type="float"> <Name> tend </Name> <Value Line 336  type="float"> <Name> tend </Name> <Value
336  ''' % (modulename, modelname)  ''' % (modulename, modelname)
337    
338      def testModuleAttribute(self):      def testModuleAttribute(self):
339          modeldoc = parse(self._xml('run_xml', 'ODETEST'))          esysxml=ESySXMLParser(self._xml('run_xml', 'ODETEST'))
340            modeldoc=esysxml.parse()[0]
341    
342      def testModuleAttributeFails(self):      def testModuleAttributeFails(self):
343          try:          try:
344              modeldoc = parse(self._xml('a', 'b'))              esysxml=ESySXMLParser(self._xml('a', 'b'))
345                modeldoc=esysxml.parse()[0]
346          except ImportError:          except ImportError:
347              return # correct              return # correct
348    

Legend:
Removed from v.875  
changed lines
  Added in v.918

  ViewVC Help
Powered by ViewVC 1.1.26