/[thuban]/branches/WIP-pyshapelib-bramz/test/test_save.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/test_save.py

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

revision 1173 by jonathan, Thu Jun 12 13:37:18 2003 UTC revision 1245 by bh, Thu Jun 19 19:29:23 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 80  class XMLWriterTest(unittest.TestCase): Line 82  class XMLWriterTest(unittest.TestCase):
82      def testEncode(self):      def testEncode(self):
83          """Test XMLWriter.encode"""          """Test XMLWriter.encode"""
84          writer = XMLWriter()          writer = XMLWriter()
85            eq = self.assertEquals
86    
87            eq(writer.encode("hello world"), "hello world")
88            eq(writer.encode(unicode("hello world")), unicode("hello world"))
89    
90          writer.encode("hello world")          eq(writer.encode("\x80\x90\xc2\x100"),
91          writer.encode(unicode("hello world"))                           "\xc2\x80\xc2\x90\xc3\x82\x100")
92            eq(writer.encode(u"\x80\x90\xc2\x100"),
93                             "\xc2\x80\xc2\x90\xc3\x82\x100")
94            eq(writer.encode(u"\xFF5E"), "\xc3\xbf5E")
95    
96          writer.encode("\x80\x90\xc2\x100")          eq(writer.encode('&"\'<>'), "&amp;&quot;&apos;&lt;&gt;")
97          writer.encode(u"\x80\x90\xc2\x100")          eq(writer.encode(unicode('&"\'<>')), "&amp;&quot;&apos;&lt;&gt;")
         writer.encode(u"\xFF5E")  
   
         self.assertEquals(writer.encode('&"\'<>'),  
                           "&amp;&quot;&apos;&lt;&gt;")  
         self.assertEquals(writer.encode(unicode('&"\'<>')),  
                           "&amp;&quot;&apos;&lt;&gt;")  
98    
99  class SaveSessionTest(unittest.TestCase, support.FileTestMixin):  class SaveSessionTest(unittest.TestCase, support.FileTestMixin,
100                          xmlsupport.ValidationTest):
101    
102      def compare_xml(self, xml1, xml2):      def compare_xml(self, xml1, xml2):
103          self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2))          self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2))
# Line 113  class SaveSessionTest(unittest.TestCase, Line 117  class SaveSessionTest(unittest.TestCase,
117                           '<!DOCTYPE session SYSTEM "thuban.dtd">\n'                           '<!DOCTYPE session SYSTEM "thuban.dtd">\n'
118                           '<session title="empty session">\n</session>\n')                           '<session title="empty session">\n</session>\n')
119    
120            self.validate_data(written_contents)
121    
122      def testSingleLayer(self):      def testSingleLayer(self):
123          """Save a session with a single map with a single layer"""          """Save a session with a single map with a single layer"""
124          # deliberately put an apersand in the title :)          # deliberately put an apersand in the title :)
# Line 155  class SaveSessionTest(unittest.TestCase, Line 161  class SaveSessionTest(unittest.TestCase,
161          #print expected_contents          #print expected_contents
162          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
163    
164            self.validate_data(written_contents)
165    
166          layer.SetVisible(False)          layer.SetVisible(False)
167          save_session(session, filename)          save_session(session, filename)
168    
# Line 169  class SaveSessionTest(unittest.TestCase, Line 177  class SaveSessionTest(unittest.TestCase,
177          #print "********************************************"          #print "********************************************"
178          #print expected_contents          #print expected_contents
179          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
180            self.validate_data(written_contents)
181    
182          session.Destroy()          session.Destroy()
183    
# Line 217  class SaveSessionTest(unittest.TestCase, Line 226  class SaveSessionTest(unittest.TestCase,
226          #print expected_contents          #print expected_contents
227          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
228    
229                    self.validate_data(written_contents)
230    
231      def testRasterLayer(self):      def testRasterLayer(self):
232          # deliberately put an apersand in the title :)          # deliberately put an apersand in the title :)
233          session = Session("single map&layer")          session = Session("single map&layer")
# Line 228  class SaveSessionTest(unittest.TestCase, Line 238  class SaveSessionTest(unittest.TestCase,
238                                 os.pardir, "Data", "iceland", "island.tif")                                 os.pardir, "Data", "iceland", "island.tif")
239          layer = RasterLayer("My RasterLayer", imgfile)          layer = RasterLayer("My RasterLayer", imgfile)
240          map.AddLayer(layer)          map.AddLayer(layer)
241                                                                                    
242          filename = self.temp_file_name("save_singlemap.thuban")          filename = self.temp_file_name("save_singlemap.thuban")
243          save_session(session, filename)          save_session(session, filename)
244          session.Destroy()          session.Destroy()
245                                                                                    
246          file = open(filename)          file = open(filename)
247          written_contents = file.read()          written_contents = file.read()
248          file.close()          file.close()
# Line 252  class SaveSessionTest(unittest.TestCase, Line 262  class SaveSessionTest(unittest.TestCase,
262          #print expected_contents          #print expected_contents
263          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
264    
265            self.validate_data(written_contents)
266    
267      def testClassifiedLayer(self):      def testClassifiedLayer(self):
268          """Save a session with a single map with a single layer          """Save a session with a single map with a single layer
269             with a classificaton.             with a classificaton.
# Line 323  class SaveSessionTest(unittest.TestCase, Line 335  class SaveSessionTest(unittest.TestCase,
335                      </classification>                      </classification>
336                  </layer>                  </layer>
337              </map>              </map>
338          </session>'''          </session>'''
339            
340          expected_contents = expected_template % \          expected_contents = expected_template % \
341              (os.path.join("..", "..", "Data", "iceland", "political.shp"),              (os.path.join("..", "..", "Data", "iceland", "political.shp"),
342               "true")               "true")
# Line 334  class SaveSessionTest(unittest.TestCase, Line 346  class SaveSessionTest(unittest.TestCase,
346          #print expected_contents          #print expected_contents
347          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
348    
349            self.validate_data(written_contents)
350    
351          session.Destroy()          session.Destroy()
352    
353    

Legend:
Removed from v.1173  
changed lines
  Added in v.1245

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26