/[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 2551 by jonathan, Thu Jan 27 14:19:41 2005 UTC revision 2642 by bh, Fri Jul 1 20:49:04 2005 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002, 2003, 2004 by Intevation GmbH  # Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 25  support.initthuban() Line 25  support.initthuban()
25    
26  import dbflib  import dbflib
27    
28    from Thuban import internal_from_unicode
29  from Thuban.Lib.fileutil import relative_filename  from Thuban.Lib.fileutil import relative_filename
30  from Thuban.Model.save import XMLWriter, save_session, sort_data_stores  from Thuban.Model.save import XMLWriter, save_session, sort_data_stores
31  from Thuban.Model.session import Session  from Thuban.Model.session import Session
# Line 53  class XMLWriterTest(unittest.TestCase): Line 54  class XMLWriterTest(unittest.TestCase):
54          eq(writer.encode("hello world"), "hello world")          eq(writer.encode("hello world"), "hello world")
55          eq(writer.encode(unicode("hello world")), unicode("hello world"))          eq(writer.encode(unicode("hello world")), unicode("hello world"))
56    
57          eq(writer.encode("\x80\x90\xc2\x100"),          eq(writer.encode(internal_from_unicode(u"\x80\x90\xc2\x100")),
58                           "\xc2\x80\xc2\x90\xc3\x82\x100")                           "\xc2\x80\xc2\x90\xc3\x82\x100")
59          eq(writer.encode(u"\x80\x90\xc2\x100"),          eq(writer.encode(u"\x80\x90\xc2\x100"),
60                           "\xc2\x80\xc2\x90\xc3\x82\x100")                           "\xc2\x80\xc2\x90\xc3\x82\x100")
61          eq(writer.encode(u"\xFF5E"), "\xc3\xbf5E")          eq(writer.encode(u"\xFF5E"), "\xc3\xbf5E")
62    
# Line 234  class SaveSessionTest(unittest.TestCase, Line 235  class SaveSessionTest(unittest.TestCase,
235          self.validate_data(written_contents)          self.validate_data(written_contents)
236    
237      def testRasterLayer(self):      def testRasterLayer(self):
         # deliberately put an apersand in the title :)  
         session = Session("single map&layer")  
         map = Map("Test Map")  
         session.AddMap(map)  
         # use shapefile from the example data  
         imgfile = os.path.join(os.path.dirname(__file__),  
                                os.pardir, "Data", "iceland", "island.tif")  
         layer = RasterLayer("My RasterLayer", imgfile)  
         layer.SetUseMask(True)  
         map.AddLayer(layer)  
   
         filename = self.temp_file_name("%s.thuban" % self.id())  
         save_session(session, filename)  
         session.Destroy()  
238    
239          file = open(filename)          MASK_NONE = RasterLayer.MASK_NONE
240          written_contents = file.read()          MASK_BIT = RasterLayer.MASK_BIT
241          file.close()          MASK_ALPHA = RasterLayer.MASK_ALPHA
242          expected_contents = '''<?xml version="1.0" encoding="UTF-8"?>  
243          <!DOCTYPE session SYSTEM "thuban-1.1.dtd">          for opacity, masktype, opname, maskname in \
244          <session title="single map&amp;layer"              [(1,  MASK_BIT,   '', ''),
245             xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd">               (.2, MASK_BIT,   'opacity="0.2"', ''),
246              <map title="Test Map">               (1,  MASK_ALPHA, '',              'masktype="alpha"'),
247                  <rasterlayer title="My RasterLayer"               (.5, MASK_ALPHA, 'opacity="0.5"', 'masktype="alpha"'),
248                          filename="../../Data/iceland/island.tif"               (1,  MASK_NONE,  '',              'masktype="none"'),
249                          visible="true" use_mask="true">               (0,  MASK_NONE,  'opacity="0"',   'masktype="none"') ]:
250                  </rasterlayer>  
251              </map>  
252          </session>'''              # deliberately put an apersand in the title :)
253          #print written_contents              session = Session("single map&layer")
254          #print "********************************************"              map = Map("Test Map")
255          #print expected_contents              session.AddMap(map)
256          self.compare_xml(written_contents, expected_contents)              # use shapefile from the example data
257                imgfile = os.path.join(os.path.dirname(__file__),
258                                       os.pardir, "Data", "iceland", "island.tif")
259                layer = RasterLayer("My RasterLayer", imgfile)
260    
261                layer.SetOpacity(opacity)
262                layer.SetMaskType(masktype)
263    
264                map.AddLayer(layer)
265    
266                filename = self.temp_file_name("%s.thuban" % self.id())
267                save_session(session, filename)
268                session.Destroy()
269    
270                file = open(filename)
271                written_contents = file.read()
272                file.close()
273                expected_contents = '''<?xml version="1.0" encoding="UTF-8"?>
274                <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
275                <session title="single map&amp;layer"
276                   xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd">
277                    <map title="Test Map">
278                        <rasterlayer title="My RasterLayer"
279                                filename="../../Data/iceland/island.tif"
280                                visible="true" %s %s>
281                        </rasterlayer>
282                    </map>
283                </session>''' % (opname, maskname)
284                #print written_contents
285                #print "********************************************"
286                #print expected_contents
287                self.compare_xml(written_contents, expected_contents)
288    
289          self.validate_data(written_contents)              self.validate_data(written_contents)
290    
291      def testClassifiedLayer(self):      def testClassifiedLayer(self):
292          """Save a session with a single map with classifications"""          """Save a session with a single map with classifications"""
# Line 308  class SaveSessionTest(unittest.TestCase, Line 326  class SaveSessionTest(unittest.TestCase,
326          layer2.SetClassificationColumn("POPYCOUN")          layer2.SetClassificationColumn("POPYCOUN")
327    
328          # Classification with Latin 1 text          # Classification with Latin 1 text
329          clazz.AppendGroup(ClassGroupSingleton('\xe4\xf6\xfc', # ae, oe, ue          clazz.AppendGroup(ClassGroupSingleton(
330                                                ClassGroupProperties(),              internal_from_unicode(u'\xe4\xf6\xfc'), # ae, oe, ue
331                                                '\xdcml\xe4uts')) # Uemlaeuts              ClassGroupProperties(),
332                internal_from_unicode(u'\xdcml\xe4uts'))) # Uemlaeuts
333    
334    
335          filename = self.temp_file_name("%s.thuban" % self.id())          filename = self.temp_file_name("%s.thuban" % self.id())

Legend:
Removed from v.2551  
changed lines
  Added in v.2642

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26