/[thuban]/trunk/thuban/test/test_save.py
ViewVC logotype

Diff of /trunk/thuban/test/test_save.py

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

revision 1200 by jonathan, Fri Jun 13 15:04:44 2003 UTC revision 1259 by bh, Fri Jun 20 12:31:48 2003 UTC
# Line 21  import xml.sax Line 21  import xml.sax
21  import xml.sax.handler  import xml.sax.handler
22  from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException  from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException
23    
24    import xmlsupport
25    
26  import support  import support
27  support.initthuban()  support.initthuban()
28    
# Line 36  from Thuban.Model.classification import Line 38  from Thuban.Model.classification import
38  from Thuban.Model.range import Range  from Thuban.Model.range import Range
39    
40    
 class SaxEventLister(xml.sax.handler.ContentHandler):  
   
     def __init__(self):  
         self.eventlist = []  
   
     def startElementNS(self, name, qname, attrs):  
         items = attrs.items()  
         items.sort()  
         self.eventlist.append(("start", name, qname, items))  
   
     def endElementNS(self, name, qname):  
         self.eventlist.append(("end", name, qname))  
   
   
 def sax_eventlist(data):  
     """Return a list of SAX event generated for the XML data.  
     """  
     handler = SaxEventLister()  
     parser = make_parser()  
     parser.setContentHandler(handler)  
     parser.setErrorHandler(ErrorHandler())  
     parser.setFeature(xml.sax.handler.feature_namespaces, 1)  
   
     #  
     # see comment at the end of Thuban/Model/load.py  
     #  
     try:  
         parser.setFeature(xml.sax.handler.feature_validation, 0)  
         parser.setFeature(xml.sax.handler.feature_external_ges, 0)  
         parser.setFeature(xml.sax.handler.feature_external_pes, 0)  
     except SAXNotRecognizedException:  
         pass  
   
     inpsrc = xml.sax.InputSource()  
     inpsrc.setByteStream(StringIO(data))  
     parser.parse(inpsrc)  
   
     return handler.eventlist  
   
41  class XMLWriterTest(unittest.TestCase):  class XMLWriterTest(unittest.TestCase):
42    
43      def testEncode(self):      def testEncode(self):
# Line 94  class XMLWriterTest(unittest.TestCase): Line 57  class XMLWriterTest(unittest.TestCase):
57          eq(writer.encode('&"\'<>'), "&amp;&quot;&apos;&lt;&gt;")          eq(writer.encode('&"\'<>'), "&amp;&quot;&apos;&lt;&gt;")
58          eq(writer.encode(unicode('&"\'<>')), "&amp;&quot;&apos;&lt;&gt;")          eq(writer.encode(unicode('&"\'<>')), "&amp;&quot;&apos;&lt;&gt;")
59    
60  class SaveSessionTest(unittest.TestCase, support.FileTestMixin):  class SaveSessionTest(unittest.TestCase, support.FileTestMixin,
61                          xmlsupport.ValidationTest):
62    
63      def compare_xml(self, xml1, xml2):      def compare_xml(self, xml1, xml2):
64          self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2))          self.assertEquals(xmlsupport.sax_eventlist(xml1),
65                              xmlsupport.sax_eventlist(xml2))
66    
67      def testEmptySession(self):      def testEmptySession(self):
68          """Save an empty session"""          """Save an empty session"""
# Line 114  class SaveSessionTest(unittest.TestCase, Line 79  class SaveSessionTest(unittest.TestCase,
79                           '<!DOCTYPE session SYSTEM "thuban.dtd">\n'                           '<!DOCTYPE session SYSTEM "thuban.dtd">\n'
80                           '<session title="empty session">\n</session>\n')                           '<session title="empty session">\n</session>\n')
81    
82            self.validate_data(written_contents)
83    
84      def testSingleLayer(self):      def testSingleLayer(self):
85          """Save a session with a single map with a single layer"""          """Save a session with a single map with a single layer"""
86          # deliberately put an apersand in the title :)          # deliberately put an apersand in the title :)
# Line 156  class SaveSessionTest(unittest.TestCase, Line 123  class SaveSessionTest(unittest.TestCase,
123          #print expected_contents          #print expected_contents
124          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
125    
126            self.validate_data(written_contents)
127    
128          layer.SetVisible(False)          layer.SetVisible(False)
129          save_session(session, filename)          save_session(session, filename)
130    
# Line 170  class SaveSessionTest(unittest.TestCase, Line 139  class SaveSessionTest(unittest.TestCase,
139          #print "********************************************"          #print "********************************************"
140          #print expected_contents          #print expected_contents
141          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
142            self.validate_data(written_contents)
143    
144          session.Destroy()          session.Destroy()
145    
# Line 218  class SaveSessionTest(unittest.TestCase, Line 188  class SaveSessionTest(unittest.TestCase,
188          #print expected_contents          #print expected_contents
189          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
190    
191                    self.validate_data(written_contents)
192    
193      def testRasterLayer(self):      def testRasterLayer(self):
194          # deliberately put an apersand in the title :)          # deliberately put an apersand in the title :)
195          session = Session("single map&layer")          session = Session("single map&layer")
# Line 229  class SaveSessionTest(unittest.TestCase, Line 200  class SaveSessionTest(unittest.TestCase,
200                                 os.pardir, "Data", "iceland", "island.tif")                                 os.pardir, "Data", "iceland", "island.tif")
201          layer = RasterLayer("My RasterLayer", imgfile)          layer = RasterLayer("My RasterLayer", imgfile)
202          map.AddLayer(layer)          map.AddLayer(layer)
203                                                                                    
204          filename = self.temp_file_name("save_singlemap.thuban")          filename = self.temp_file_name("save_singlemap.thuban")
205          save_session(session, filename)          save_session(session, filename)
206          session.Destroy()          session.Destroy()
207                                                                                    
208          file = open(filename)          file = open(filename)
209          written_contents = file.read()          written_contents = file.read()
210          file.close()          file.close()
# Line 253  class SaveSessionTest(unittest.TestCase, Line 224  class SaveSessionTest(unittest.TestCase,
224          #print expected_contents          #print expected_contents
225          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
226    
227            self.validate_data(written_contents)
228    
229      def testClassifiedLayer(self):      def testClassifiedLayer(self):
230          """Save a session with a single map with a single layer          """Save a session with a single map with a single layer
231             with a classificaton.             with a classificaton.
# Line 324  class SaveSessionTest(unittest.TestCase, Line 297  class SaveSessionTest(unittest.TestCase,
297                      </classification>                      </classification>
298                  </layer>                  </layer>
299              </map>              </map>
300          </session>'''          </session>'''
301            
302          expected_contents = expected_template % \          expected_contents = expected_template % \
303              (os.path.join("..", "..", "Data", "iceland", "political.shp"),              (os.path.join("..", "..", "Data", "iceland", "political.shp"),
304               "true")               "true")
# Line 335  class SaveSessionTest(unittest.TestCase, Line 308  class SaveSessionTest(unittest.TestCase,
308          #print expected_contents          #print expected_contents
309          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
310    
311            self.validate_data(written_contents)
312    
313          session.Destroy()          session.Destroy()
314    
315    

Legend:
Removed from v.1200  
changed lines
  Added in v.1259

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26