/[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 1646 by bh, Mon Aug 25 13:43:56 2003 UTC revision 1848 by bh, Tue Oct 21 11:06:56 2003 UTC
# Line 82  class LoadSessionTest(support.FileLoadTe Line 82  class LoadSessionTest(support.FileLoadTe
82          self.session = None          self.session = None
83    
84    
85      dtd = "http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"      dtd = "http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
86      thubanids = [((dtd, n), (None, "id")) for n in      thubanids = [((dtd, n), (None, "id")) for n in
87                   ["fileshapesource", "filetable", "jointable",                   ["fileshapesource", "filetable", "jointable",
88                    "derivedshapesource"]]                    "derivedshapesource"]]
# Line 92  class LoadSessionTest(support.FileLoadTe Line 92  class LoadSessionTest(support.FileLoadTe
92                       ("jointable", "right"),                       ("jointable", "right"),
93                       ("derivedshapesource", "table"),                       ("derivedshapesource", "table"),
94                       ("derivedshapesource", "shapesource")]]                       ("derivedshapesource", "shapesource")]]
95        filenames = [((dtd, n), (None, m)) for n, m in
96                     [("fileshapesource", "filename"),
97                      ("rasterlayer", "filename"),
98                      ("filetable", "filename")]]
99      del n, m, dtd      del n, m, dtd
100    
101      def check_format(self):      def check_format(self):
# Line 102  class LoadSessionTest(support.FileLoadTe Line 106  class LoadSessionTest(support.FileLoadTe
106          filename = self.temp_file_name(self.id() + ".roundtrip.thuban")          filename = self.temp_file_name(self.id() + ".roundtrip.thuban")
107          save_session(self.session, filename)          save_session(self.session, filename)
108          el1 = sax_eventlist(filename = filename, ids = self.thubanids,          el1 = sax_eventlist(filename = filename, ids = self.thubanids,
109                              idrefs = self.thubanidrefs)                              idrefs = self.thubanidrefs,
110                                filenames = self.filenames)
111          el2 = sax_eventlist(filename = self.filename(), ids = self.thubanids,          el2 = sax_eventlist(filename = self.filename(), ids = self.thubanids,
112                              idrefs = self.thubanidrefs)                              idrefs = self.thubanidrefs,
113                                filenames = self.filenames)
114          if 0:          if 0:
115              for a, b in zip(el1, el2):              for a, b in zip(el1, el2):
116                  print a != b and "***************" or ""                  print a != b and "***************" or ""
# Line 167  class ClassificationTest(LoadSessionTest Line 173  class ClassificationTest(LoadSessionTest
173    
174  class TestSingleLayer(LoadSessionTest):  class TestSingleLayer(LoadSessionTest):
175    
176        # Note: The use of & and non-ascii characters is deliberate. We
177        # want to test whether the loading code handles that correctly.
178      file_contents = '''\      file_contents = '''\
179  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
180  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
181  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
182          title="single map&amp;layer">          title="Stra\xc3\x9fen &amp; Landmarken">
183      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
184          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
185      <map title="Test Map">      <map title="\xc3\x9cbersicht">
186          <projection name="Unknown">          <projection epsg="32627" name="WGS 84 / UTM zone 27N">
187              <parameter value="zone=26"/>              <parameter value="datum=WGS84"/>
188                <parameter value="ellps=WGS84"/>
189              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
190              <parameter value="ellps=clrk66"/>              <parameter value="units=m"/>
191                <parameter value="zone=27"/>
192          </projection>          </projection>
193          <layer shapestore="D1" visible="true"          <layer shapestore="D1" visible="true"
194                  stroke="#000000" title="My Layer" stroke_width="1"                  stroke="#000000" title="K\xc3\xbcste" stroke_width="1"
195                  fill="None"/>                  fill="None"/>
196      </map>      </map>
197  </session>  </session>
# Line 194  class TestSingleLayer(LoadSessionTest): Line 204  class TestSingleLayer(LoadSessionTest):
204          self.session = session          self.session = session
205    
206          # Check the title          # Check the title
207          eq(session.Title(), "single map&layer")          eq(session.Title(), "Stra\xdfen & Landmarken")
208    
209          # the session has one map.          # the session has one map.
210          maps = session.Maps()          maps = session.Maps()
# Line 202  class TestSingleLayer(LoadSessionTest): Line 212  class TestSingleLayer(LoadSessionTest):
212    
213          # Check the map's attributes          # Check the map's attributes
214          map = maps[0]          map = maps[0]
215          eq(map.Title(), "Test Map")          eq(map.Title(), "\xdcbersicht")
216            proj = map.GetProjection()
217            eq(proj.GetName(), "WGS 84 / UTM zone 27N")
218            eq(proj.EPSGCode(), "32627")
219            params = proj.GetAllParameters()
220            params.sort()
221            eq(params, ["datum=WGS84", "ellps=WGS84", "proj=utm", "units=m",
222                        "zone=27"])
223    
224          # the map has a single layer          # the map has a single layer
225          layers = map.Layers()          layers = map.Layers()
# Line 210  class TestSingleLayer(LoadSessionTest): Line 227  class TestSingleLayer(LoadSessionTest):
227    
228          # Check the layer attributes          # Check the layer attributes
229          layer = layers[0]          layer = layers[0]
230          eq(layer.Title(), "My Layer")          eq(layer.Title(), "K\xfcste")
231          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),
232                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
233                                                       os.pardir, os.pardir,                                                       os.pardir, os.pardir,
# Line 230  class TestLayerVisibility(LoadSessionTes Line 247  class TestLayerVisibility(LoadSessionTes
247    
248      file_contents = '''\      file_contents = '''\
249  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
250  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
251  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
252          title="single map&amp;layer">          title="single map&amp;layer">
253      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
254          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 355  class TestLabels(ClassificationTest): Line 372  class TestLabels(ClassificationTest):
372    
373      file_contents = '''\      file_contents = '''\
374  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
375  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
376  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
377          title="single map&amp;layer">          title="single map&amp;layer">
378      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
379          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 403  class TestLayerProjection(LoadSessionTes Line 420  class TestLayerProjection(LoadSessionTes
420    
421      file_contents = '''\      file_contents = '''\
422  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
423  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
424  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
425          title="single map&amp;layer">          title="single map&amp;layer">
426      <fileshapesource filetype="shapefile" id="D2"      <fileshapesource filetype="shapefile" id="D2"
427          filename="../../Data/iceland/roads-line.shp"/>          filename="../../Data/iceland/roads-line.shp"/>
# Line 436  class TestLayerProjection(LoadSessionTes Line 453  class TestLayerProjection(LoadSessionTes
453                  title="My Layer" stroke_width="1" fill="None">                  title="My Layer" stroke_width="1" fill="None">
454              <projection name="Unknown">              <projection name="Unknown">
455                  <parameter value="proj=lcc"/>                  <parameter value="proj=lcc"/>
456                    <parameter value="lat_1=10"/>
457                    <parameter value="lat_2=20"/>
458                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
459              </projection>              </projection>
460          </layer>          </layer>
# Line 468  class TestLayerProjection(LoadSessionTes Line 487  class TestLayerProjection(LoadSessionTes
487          neq(proj, None)          neq(proj, None)
488          eq(proj.GetName(), "Unknown")          eq(proj.GetName(), "Unknown")
489          eq(proj.GetParameter("proj"), "lcc")          eq(proj.GetParameter("proj"), "lcc")
490            eq(proj.GetParameter("lat_1"), "10")
491            eq(proj.GetParameter("lat_2"), "20")
492          eq(proj.GetParameter("ellps"), "clrk66")          eq(proj.GetParameter("ellps"), "clrk66")
493    
494          self.check_format()          self.check_format()
# Line 477  class TestRasterLayer(LoadSessionTest): Line 498  class TestRasterLayer(LoadSessionTest):
498    
499      file_contents = '''\      file_contents = '''\
500  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
501  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
502  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
503          title="single map&amp;layer">          title="single map&amp;layer">
504      <map title="Test Map">      <map title="Test Map">
505          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"
# Line 511  class TestRasterLayer(LoadSessionTest): Line 532  class TestRasterLayer(LoadSessionTest):
532  class TestJoinedTable(LoadSessionTest):  class TestJoinedTable(LoadSessionTest):
533    
534      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
535  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
536  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" title="A Joined Table session">  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" title="A Joined Table session">
537      <fileshapesource filetype="shapefile" id="D137227612"      <fileshapesource filetype="shapefile" id="D137227612"
538          filename="../../Data/iceland/roads-line.shp"/>          filename="../../Data/iceland/roads-line.shp"/>
539      <filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140"      <filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140"
# Line 560  class TestJoinedTable(LoadSessionTest): Line 581  class TestJoinedTable(LoadSessionTest):
581  class TestPostGISLayer(LoadSessionTest):  class TestPostGISLayer(LoadSessionTest):
582    
583      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
584  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
585  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
586          title="unnamed session">          title="unnamed session">
587      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"
588          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>
# Line 609  class TestPostGISLayer(LoadSessionTest): Line 630  class TestPostGISLayer(LoadSessionTest):
630  class TestPostGISLayerPassword(LoadSessionTest):  class TestPostGISLayerPassword(LoadSessionTest):
631    
632      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
633  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
634  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
635          title="unnamed session">          title="unnamed session">
636      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"
637          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>
# Line 704  class TestLoadError(LoadSessionTest): Line 725  class TestLoadError(LoadSessionTest):
725    
726      file_contents = '''\      file_contents = '''\
727  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
728  <!DOCTYPE session SYSTEM "thuban-0.9.dtd">  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">
729  <session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"
730          title="single map&amp;layer">          title="single map&amp;layer">
731      <fileshapesource id="D1" filename="../../Data/iceland/political.shp"/>      <fileshapesource id="D1" filename="../../Data/iceland/political.shp"/>
732      <map title="Test Map">      <map title="Test Map">
# Line 732  class TestLoadError(LoadSessionTest): Line 753  class TestLoadError(LoadSessionTest):
753              # LoadError really was about the missing attribute              # LoadError really was about the missing attribute
754              self.assertEquals(str(value),              self.assertEquals(str(value),
755                "Element "                "Element "
756                "(u'http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd',"                "(u'http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd',"
757                " u'fileshapesource') requires an attribute 'filetype'")                " u'fileshapesource') requires an attribute 'filetype'")
758          else:          else:
759              self.fail("Missing filetype attribute doesn't raise LoadError")              self.fail("Missing filetype attribute doesn't raise LoadError")
760    
761  if __name__ == "__main__":  if __name__ == "__main__":
762      unittest.main()      support.run_tests()

Legend:
Removed from v.1646  
changed lines
  Added in v.1848

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26