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

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

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

revision 2451 by bh, Mon Dec 13 17:51:11 2004 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 40  from xmlsupport import sax_eventlist Line 40  from xmlsupport import sax_eventlist
40  import dbflib  import dbflib
41  import shapelib  import shapelib
42    
43    from Thuban import internal_from_unicode
44  from Thuban.Model.save import save_session  from Thuban.Model.save import save_session
45  from Thuban.Model.load import load_session, parse_color, LoadError, \  from Thuban.Model.load import load_session, parse_color, LoadError, \
46       LoadCancelled       LoadCancelled
# Line 53  from Thuban.Model.table import DBFTable, Line 54  from Thuban.Model.table import DBFTable,
54  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
55       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
56    
   
57  def filenames_equal(name1, name2):  def filenames_equal(name1, name2):
58      """Return true if the filenames name1 and name2 are equal.      """Return true if the filenames name1 and name2 are equal.
59    
# Line 124  class LoadSessionTest(support.FileLoadTe Line 124  class LoadSessionTest(support.FileLoadTe
124                  print a != b and "***************" or ""                  print a != b and "***************" or ""
125                  print a                  print a
126                  print b                  print b
127    
128          self.assertEquals(el1, el2,          self.assertEquals(el1, el2,
129                            "loaded file not equivalent to the saved file")                            "loaded file not equivalent to the saved file")
130    
# Line 214  class TestSingleLayer(LoadSessionTest): Line 215  class TestSingleLayer(LoadSessionTest):
215          self.session = session          self.session = session
216    
217          # Check the title          # Check the title
218          eq(session.Title(), "Stra\xdfen & Landmarken")          eq(session.Title(), internal_from_unicode(u"Stra\xdfen & Landmarken"))
219    
220          # the session has one map.          # the session has one map.
221          maps = session.Maps()          maps = session.Maps()
# Line 222  class TestSingleLayer(LoadSessionTest): Line 223  class TestSingleLayer(LoadSessionTest):
223    
224          # Check the map's attributes          # Check the map's attributes
225          map = maps[0]          map = maps[0]
226          eq(map.Title(), "\xdcbersicht")          eq(map.Title(), internal_from_unicode(u"\xdcbersicht"))
227          proj = map.GetProjection()          proj = map.GetProjection()
228          eq(proj.GetName(), "WGS 84 / UTM zone 27N")          eq(proj.GetName(), "WGS 84 / UTM zone 27N")
229          eq(proj.EPSGCode(), "32627")          eq(proj.EPSGCode(), "32627")
# Line 237  class TestSingleLayer(LoadSessionTest): Line 238  class TestSingleLayer(LoadSessionTest):
238    
239          # Check the layer attributes          # Check the layer attributes
240          layer = layers[0]          layer = layers[0]
241          eq(layer.Title(), "K\xfcste")          eq(layer.Title(), internal_from_unicode(u"K\xfcste"))
242          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),
243                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
244                                                       os.pardir, os.pardir,                                                       os.pardir, os.pardir,
# Line 510  class TestClassification(ClassificationT Line 511  class TestClassification(ClassificationT
511                              ("#000000", 2, "None")),                              ("#000000", 2, "None")),
512                           ("single", "1", "",                           ("single", "1", "",
513                              ("#000000", 10, "None")),                              ("#000000", 10, "None")),
514                           ("single", "\xe4\xf6\xfc", "\xdcml\xe4uts",                           ("single", internal_from_unicode(u"\xe4\xf6\xfc"),
515                              internal_from_unicode(u"\xdcml\xe4uts"),
516                              ("#000000", 1, "None"))]),                              ("#000000", 1, "None"))]),
517                       ("My Layer 2", 4,                       ("My Layer 2", 4,
518                           [("default", (), "",                           [("default", (), "",
# Line 664  class TestRasterLayer(LoadSessionTest): Line 666  class TestRasterLayer(LoadSessionTest):
666          title="single map&amp;layer">          title="single map&amp;layer">
667      <map title="Test Map">      <map title="Test Map">
668          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"
669                  title="My RasterLayer"/>                  title="My RasterLayer" opacity="0.4" masktype="alpha"/>
670      </map>      </map>
671  </session>  </session>
672  '''  '''
# Line 681  class TestRasterLayer(LoadSessionTest): Line 683  class TestRasterLayer(LoadSessionTest):
683          layer = map.Layers()[0] # one layer in the sample          layer = map.Layers()[0] # one layer in the sample
684    
685          eq(layer.Title(), "My RasterLayer")          eq(layer.Title(), "My RasterLayer")
686            eq(layer.Opacity(), 0.4)
687            eq(layer.MaskType(), layer.MASK_ALPHA)
688    
689          self.failIf(layer.Visible())          self.failIf(layer.Visible())
690          self.failUnless(filenames_equal(layer.GetImageFilename(),          self.failUnless(filenames_equal(layer.GetImageFilename(),
691                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
# Line 789  class TestLabelLayer(LoadSessionTest): Line 794  class TestLabelLayer(LoadSessionTest):
794    
795          label_layer = self.session.Maps()[0].LabelLayer()          label_layer = self.session.Maps()[0].LabelLayer()
796          expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),          expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),
797                             (-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP),                             (-15.125, 64.75, internal_from_unicode(u"H\xfctte"),
798                                ALIGN_RIGHT, ALIGN_TOP),
799                             ]                             ]
800          for label, values in zip(label_layer.Labels(), expected_labels):          for label, values in zip(label_layer.Labels(), expected_labels):
801              self.assertEquals((label.x, label.y, label.text, label.halign,              self.assertEquals((label.x, label.y, label.text, label.halign,
# Line 1016  class TestAltPath(LoadSessionTest): Line 1022  class TestAltPath(LoadSessionTest):
1022      file_contents = '''\      file_contents = '''\
1023  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
1024  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
1025  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session">  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="AltPath Test session">
1026      <fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/>      <fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/>
1027      <fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/>      <fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/>
1028      <fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/>      <fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/>
# Line 1028  class TestAltPath(LoadSessionTest): Line 1034  class TestAltPath(LoadSessionTest):
1034  </session>  </session>
1035  '''  '''
1036    
1037        def checkSession(self, session):
1038            """Check if session has been loaded successfully."""
1039            
1040            eq = self.assertEquals
1041    
1042            map = session.Maps()[0]
1043            layers = map.Layers()
1044    
1045            eq("AltPath Test session", session.Title())
1046            eq("not the iceland map", map.Title())
1047            eq(3,len(layers))
1048            eq("political",layers[0].Title())
1049            eq("roads-line",layers[1].Title())
1050            eq("something else",layers[2].Title())
1051    
1052      def test_01_single_path_error_fix(self):      def test_01_single_path_error_fix(self):
1053          """Test single file path error fix."""          """Test single file path error fix."""
1054          # The usual initial case          # The usual initial case
# Line 1036  class TestAltPath(LoadSessionTest): Line 1057  class TestAltPath(LoadSessionTest):
1057                      "check": [(None, None)]})                      "check": [(None, None)]})
1058          self.session = load_session(self.filename(),          self.session = load_session(self.filename(),
1059                                      shapefile_callback =s_cb.s_cb)                                      shapefile_callback =s_cb.s_cb)
1060            self.checkSession(self.session)
1061            
1062      def test_02_path_error_fix_from_list(self):      def test_02_path_error_fix_from_list(self):
1063          """Test single file path error fix."""          """Test single file path error fix."""
1064          # This represents the usual case for "from_list"          # This represents the usual case for "from_list"
# Line 1046  class TestAltPath(LoadSessionTest): Line 1068  class TestAltPath(LoadSessionTest):
1068                 })                 })
1069          self.session = load_session(self.filename(),          self.session = load_session(self.filename(),
1070                                      shapefile_callback =s_cb.s_cb)                                      shapefile_callback =s_cb.s_cb)
1071            self.checkSession(self.session)
1072    
1073      def test_03_single_path_error_cancelled(self):      def test_03_single_path_error_cancelled(self):
1074          """Test alternative path cancelled."""          """Test alternative path cancelled."""
# Line 1072  class TestAltPath(LoadSessionTest): Line 1095  class TestAltPath(LoadSessionTest):
1095                 })                 })
1096          self.session = load_session(self.filename(),          self.session = load_session(self.filename(),
1097                                      shapefile_callback =s_cb.s_cb)                                      shapefile_callback =s_cb.s_cb)
1098            self.checkSession(self.session)
1099    
1100      def test_06_path_error_fix_from_list_fails(self):      def test_06_path_error_fix_from_list_fails(self):
1101          """Test alternative path recovery from list."""          """Test alternative path recovery from list."""

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26