/[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

trunk/thuban/test/test_load.py revision 2458 by frank, Wed Dec 15 09:58:30 2004 UTC branches/WIP-pyshapelib-bramz/test/test_load.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 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
47  from Thuban.Model.color import Transparent  from Thuban.Model.color import Transparent
48  from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\  from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\
49      ClassGroupSingleton, ClassGroupDefault      ClassGroupSingleton, ClassGroupPattern, ClassGroupDefault
50  from Thuban.Model.postgisdb import ConnectionError  from Thuban.Model.postgisdb import ConnectionError
51  from Thuban.Model.table import DBFTable, MemoryTable, \  from Thuban.Model.table import DBFTable, MemoryTable, \
52       FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \       FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \
# 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 174  class ClassificationTest(LoadSessionTest Line 175  class ClassificationTest(LoadSessionTest
175                  elif data[CLASSES][i][GROUP_TYPE] == "single":                  elif data[CLASSES][i][GROUP_TYPE] == "single":
176                      g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA],                      g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA],
177                                            props, data[CLASSES][i][GROUP_LABEL])                                            props, data[CLASSES][i][GROUP_LABEL])
178                    elif data[CLASSES][i][GROUP_TYPE] == "pattern":
179                        g = ClassGroupPattern(data[CLASSES][i][GROUP_DATA],
180                                              props, data[CLASSES][i][GROUP_LABEL])
181    
182                  eq(group, g)                  eq(group, g)
183    
# Line 200  class TestSingleLayer(LoadSessionTest): Line 204  class TestSingleLayer(LoadSessionTest):
204              <parameter value="units=m"/>              <parameter value="units=m"/>
205              <parameter value="zone=27"/>              <parameter value="zone=27"/>
206          </projection>          </projection>
207          <layer shapestore="D1" visible="true"          <layer shapestore="D1" visible="true" title="K\xc3\xbcste">
208                  stroke="#000000" title="K\xc3\xbcste" stroke_width="1"              <classification>
209                  fill="None"/>                  <clnull label="">
210                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
211                    </clnull>
212                </classification>
213            </layer>
214      </map>      </map>
215  </session>  </session>
216  '''  '''
# Line 214  class TestSingleLayer(LoadSessionTest): Line 222  class TestSingleLayer(LoadSessionTest):
222          self.session = session          self.session = session
223    
224          # Check the title          # Check the title
225          eq(session.Title(), "Stra\xdfen & Landmarken")          eq(session.Title(), internal_from_unicode(u"Stra\xdfen & Landmarken"))
226    
227          # the session has one map.          # the session has one map.
228          maps = session.Maps()          maps = session.Maps()
# Line 222  class TestSingleLayer(LoadSessionTest): Line 230  class TestSingleLayer(LoadSessionTest):
230    
231          # Check the map's attributes          # Check the map's attributes
232          map = maps[0]          map = maps[0]
233          eq(map.Title(), "\xdcbersicht")          eq(map.Title(), internal_from_unicode(u"\xdcbersicht"))
234          proj = map.GetProjection()          proj = map.GetProjection()
235          eq(proj.GetName(), "WGS 84 / UTM zone 27N")          eq(proj.GetName(), "WGS 84 / UTM zone 27N")
236          eq(proj.EPSGCode(), "32627")          eq(proj.EPSGCode(), "32627")
# Line 237  class TestSingleLayer(LoadSessionTest): Line 245  class TestSingleLayer(LoadSessionTest):
245    
246          # Check the layer attributes          # Check the layer attributes
247          layer = layers[0]          layer = layers[0]
248          eq(layer.Title(), "K\xfcste")          eq(layer.Title(), internal_from_unicode(u"K\xfcste"))
249          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),
250                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
251                                                       os.pardir, os.pardir,                                                       os.pardir, os.pardir,
# Line 292  class TestNonAsciiColumnName(LoadSession Line 300  class TestNonAsciiColumnName(LoadSession
300              <parameter value="units=m"/>              <parameter value="units=m"/>
301              <parameter value="zone=27"/>              <parameter value="zone=27"/>
302          </projection>          </projection>
303          <layer shapestore="D1" visible="true"          <layer shapestore="D1" visible="true" title="layer">
                 stroke="#000000" title="layer" stroke_width="1"  
                 fill="None">  
304              <classification field="Fl\xc3\xa4che" field_type="double">              <classification field="Fl\xc3\xa4che" field_type="double">
305                  <clnull label="">                  <clnull label="">
306                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
# Line 367  class TestLayerVisibility(LoadSessionTes Line 373  class TestLayerVisibility(LoadSessionTes
373              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
374              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
375          </projection>          </projection>
376          <layer shapestore="D1" visible="false" stroke="#000000"          <layer shapestore="D1" visible="false" title="My Layer">
377                  title="My Layer" stroke_width="1" fill="None"/>              <classification>
378                    <clnull label="">
379                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
380                    </clnull>
381                </classification>
382            </layer>
383      </map>      </map>
384  </session>  </session>
385  '''  '''
# Line 398  class TestSymbolSize(ClassificationTest) Line 409  class TestSymbolSize(ClassificationTest)
409  <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="Thuban sample session">
410      <fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/>      <fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/>
411      <map title="Iceland map">      <map title="Iceland map">
412          <layer title="cultural_landmark-point" stroke_width="1" shapestore="D813968480" visible="true" stroke="#000000" fill="#000000">          <layer title="cultural_landmark-point" shapestore="D813968480" visible="true">
413              <classification field="CLPTLABEL" field_type="string">              <classification field="CLPTLABEL" field_type="string">
414                  <clnull label="">                  <clnull label="">
415                      <cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/>                      <cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/>
# Line 448  class TestClassification(ClassificationT Line 459  class TestClassification(ClassificationT
459          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
460      <fileshapesource filetype="shapefile" id="D138504492"      <fileshapesource filetype="shapefile" id="D138504492"
461          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
462        <fileshapesource filetype="shapefile" id="D123456789"
463            filename="../../Data/iceland/cultural_landmark-point.shp"/>
464      <map title="Test Map">      <map title="Test Map">
465          <projection name="">          <projection name="">
466              <parameter value="zone=26"/>              <parameter value="zone=26"/>
467              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
468              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
469          </projection>          </projection>
470          <layer shapestore="D138389860" visible="true" stroke="#000000"          <layer shapestore="D138389860" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
471              <classification field="POPYREG" field_type="string">              <classification field="POPYREG" field_type="string">
472                  <clnull label="">                  <clnull label="">
473                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
# Line 472  class TestClassification(ClassificationT Line 484  class TestClassification(ClassificationT
484                  </clpoint>                  </clpoint>
485              </classification>              </classification>
486          </layer>          </layer>
487          <layer shapestore="D138504492" visible="true" stroke="#000000"          <layer shapestore="D138504492" visible="true" title="My Layer 2">
                 title="My Layer 2" stroke_width="2" fill="None">  
488              <classification field="AREA" field_type="double">              <classification field="AREA" field_type="double">
489                  <clnull label="">                  <clnull label="">
490                      <cldata stroke="#000000" stroke_width="2" fill="None"/>                      <cldata stroke="#000000" stroke_width="2" fill="None"/>
# Line 492  class TestClassification(ClassificationT Line 503  class TestClassification(ClassificationT
503                  </clpoint>                  </clpoint>
504              </classification>              </classification>
505          </layer>          </layer>
506            <layer shapestore="D123456789" visible="true" title="My Layer 3">
507                <classification field="CLPTLABEL" field_type="string">
508                    <clnull label="">
509                        <cldata stroke="#000000" size="5" stroke_width="2" fill="None"/>
510                    </clnull>
511                    <clpoint label="" value="FARM">
512                        <cldata stroke="#111111" size="5" stroke_width="1" fill="None"/>
513                    </clpoint>
514                    <clpattern label="" pattern="BUI">
515                        <cldata stroke="#000000" size="5" stroke_width="1" fill="None"/>
516                    </clpattern>
517                </classification>
518            </layer>
519      </map>      </map>
520  </session>  </session>
521  '''  '''
# Line 510  class TestClassification(ClassificationT Line 534  class TestClassification(ClassificationT
534                              ("#000000", 2, "None")),                              ("#000000", 2, "None")),
535                           ("single", "1", "",                           ("single", "1", "",
536                              ("#000000", 10, "None")),                              ("#000000", 10, "None")),
537                           ("single", "\xe4\xf6\xfc", "\xdcml\xe4uts",                           ("single", internal_from_unicode(u"\xe4\xf6\xfc"),
538                              internal_from_unicode(u"\xdcml\xe4uts"),
539                              ("#000000", 1, "None"))]),                              ("#000000", 1, "None"))]),
540                       ("My Layer 2", 4,                       ("My Layer 2", 4,
541                           [("default", (), "",                           [("default", (), "",
# Line 522  class TestClassification(ClassificationT Line 547  class TestClassification(ClassificationT
547                            ("range", (-1, 0), "",                            ("range", (-1, 0), "",
548                              ("#000000", 1, "None")),                              ("#000000", 1, "None")),
549                            ("single", -.5, "",                            ("single", -.5, "",
550                              ("#000000", 1, "None"))])]                              ("#000000", 1, "None"))]),
551                         ("My Layer 3", 2,
552                             [("default", (), "",
553                                ("#000000", 2, "None")),
554                              ("single", "FARM", "",
555                                ("#111111", 1, "None")),
556                              ("pattern", "BUI", "",
557                                ("#000000", 1, "None"))]),
558                        ]
559    
560          self.TestLayers(map.Layers(), expected)          self.TestLayers(map.Layers(), expected)
561    
# Line 544  class TestLabels(ClassificationTest): Line 577  class TestLabels(ClassificationTest):
577              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
578              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
579          </projection>          </projection>
580          <layer shapestore="D1" visible="true" stroke="#000000"          <layer shapestore="D1" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
581              <classification field="POPYREG" field_type="string">              <classification field="POPYREG" field_type="string">
582                  <clnull label="hallo">                  <clnull label="hallo">
583                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
# Line 594  class TestLayerProjection(LoadSessionTes Line 626  class TestLayerProjection(LoadSessionTes
626              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
627              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
628          </projection>          </projection>
629          <layer shapestore="D4" visible="true" stroke="#000000"          <layer shapestore="D4" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
630              <projection name="hello">              <projection name="hello">
631                  <parameter value="zone=13"/>                  <parameter value="zone=13"/>
632                  <parameter value="proj=tmerc"/>                  <parameter value="proj=tmerc"/>
# Line 610  class TestLayerProjection(LoadSessionTes Line 641  class TestLayerProjection(LoadSessionTes
641                  </clpoint>                  </clpoint>
642              </classification>              </classification>
643          </layer>          </layer>
644          <layer shapestore="D2" visible="true" stroke="#000000"          <layer shapestore="D2" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
645              <projection name="Unknown">              <projection name="Unknown">
646                  <parameter value="proj=lcc"/>                  <parameter value="proj=lcc"/>
647                  <parameter value="lat_1=10"/>                  <parameter value="lat_1=10"/>
648                  <parameter value="lat_2=20"/>                  <parameter value="lat_2=20"/>
649                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
650              </projection>              </projection>
651                <classification>
652                    <clnull label="">
653                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
654                    </clnull>
655                </classification>
656          </layer>          </layer>
657      </map>      </map>
658  </session>  </session>
# Line 664  class TestRasterLayer(LoadSessionTest): Line 699  class TestRasterLayer(LoadSessionTest):
699          title="single map&amp;layer">          title="single map&amp;layer">
700      <map title="Test Map">      <map title="Test Map">
701          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"
702                  title="My RasterLayer"/>                  title="My RasterLayer" opacity="0.4" masktype="alpha"/>
703      </map>      </map>
704  </session>  </session>
705  '''  '''
# Line 681  class TestRasterLayer(LoadSessionTest): Line 716  class TestRasterLayer(LoadSessionTest):
716          layer = map.Layers()[0] # one layer in the sample          layer = map.Layers()[0] # one layer in the sample
717    
718          eq(layer.Title(), "My RasterLayer")          eq(layer.Title(), "My RasterLayer")
719            eq(layer.Opacity(), 0.4)
720            eq(layer.MaskType(), layer.MASK_ALPHA)
721    
722          self.failIf(layer.Visible())          self.failIf(layer.Visible())
723          self.failUnless(filenames_equal(layer.GetImageFilename(),          self.failUnless(filenames_equal(layer.GetImageFilename(),
724                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
# Line 706  class TestJoinedTable(LoadSessionTest): Line 744  class TestJoinedTable(LoadSessionTest):
744      <derivedshapesource table="D136169900" shapesource="D137227612"      <derivedshapesource table="D136169900" shapesource="D137227612"
745          id="D136170932"/>          id="D136170932"/>
746      <map title="Test Map">      <map title="Test Map">
747          <layer shapestore="D136170932" visible="true" stroke="#000000"          <layer shapestore="D136170932" visible="true" title="My Layer">
748                  title="My Layer" stroke_width="1" fill="None"/>              <classification>
749                    <clnull label="">
750                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
751                    </clnull>
752                </classification>
753            </layer>
754      </map>      </map>
755  </session>  </session>
756  '''  '''
# Line 756  class TestLabelLayer(LoadSessionTest): Line 799  class TestLabelLayer(LoadSessionTest):
799              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
800              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
801          </projection>          </projection>
802          <layer shapestore="D145265052" visible="true" stroke="#000000"          <layer shapestore="D145265052" visible="true" title="political">
                 title="political" stroke_width="1" fill="#c0c0c0">  
803              <projection name="Geographic">              <projection name="Geographic">
804                  <parameter value="proj=latlong"/>                  <parameter value="proj=latlong"/>
805                  <parameter value="to_meter=0.017453"/>                  <parameter value="to_meter=0.017453"/>
806                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
807              </projection>              </projection>
808                <classification>
809                    <clnull label="">
810                        <cldata stroke="#000000" stroke_width="1" fill="#c0c0c0"/>
811                    </clnull>
812                </classification>
813          </layer>          </layer>
814          <layer shapestore="D145412868" visible="true" stroke="#000000"          <layer shapestore="D145412868" visible="true" title="landmarks">
                 title="landmarks" stroke_width="1" fill="#ffff00">  
815              <projection name="Geographic">              <projection name="Geographic">
816                  <parameter value="proj=latlong"/>                  <parameter value="proj=latlong"/>
817                  <parameter value="to_meter=0.017453"/>                  <parameter value="to_meter=0.017453"/>
818                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
819              </projection>              </projection>
820                <classification>
821                    <clnull label="">
822                        <cldata size="5" stroke="#000000" stroke_width="1" fill="#ffff00"/>
823                    </clnull>
824                </classification>
825          </layer>          </layer>
826          <labellayer>          <labellayer>
827              <label x="-21.5" y="64.25" text="RUINS"              <label x="-21.5" y="64.25" text="RUINS"
# Line 789  class TestLabelLayer(LoadSessionTest): Line 840  class TestLabelLayer(LoadSessionTest):
840    
841          label_layer = self.session.Maps()[0].LabelLayer()          label_layer = self.session.Maps()[0].LabelLayer()
842          expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),          expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),
843                             (-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP),                             (-15.125, 64.75, internal_from_unicode(u"H\xfctte"),
844                                ALIGN_RIGHT, ALIGN_TOP),
845                             ]                             ]
846          for label, values in zip(label_layer.Labels(), expected_labels):          for label, values in zip(label_layer.Labels(), expected_labels):
847              self.assertEquals((label.x, label.y, label.text, label.halign,              self.assertEquals((label.x, label.y, label.text, label.halign,

Legend:
Removed from v.2458  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26