/[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 1268 by bh, Fri Jun 20 16:10:12 2003 UTC revision 1599 by bh, Mon Aug 18 12:45:28 2003 UTC
# Line 66  class XMLWriterTest(unittest.TestCase): Line 66  class XMLWriterTest(unittest.TestCase):
66  class SaveSessionTest(unittest.TestCase, support.FileTestMixin,  class SaveSessionTest(unittest.TestCase, support.FileTestMixin,
67                        xmlsupport.ValidationTest):                        xmlsupport.ValidationTest):
68    
69      dtd = "http://thuban.intevation.org/dtds/thuban-0.8.dtd"      dtd = "http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"
70      thubanids = [((dtd, n), (None, "id")) for n in      thubanids = [((dtd, n), (None, "id")) for n in
71                   ["fileshapesource", "filetable", "jointable",                   ["fileshapesource", "filetable", "jointable",
72                    "derivedshapesource"]]                    "derivedshapesource"]]
# Line 79  class SaveSessionTest(unittest.TestCase, Line 79  class SaveSessionTest(unittest.TestCase,
79      del n, m, dtd      del n, m, dtd
80    
81      def compare_xml(self, xml1, xml2):      def compare_xml(self, xml1, xml2):
82          if 0:          list1 = xmlsupport.sax_eventlist(xml1, ids = self.thubanids,
83              for a, b in zip(sax_eventlist(xml1, self.thubanids,                                           idrefs = self.thubanidrefs)
84                                          self.thubanidrefs),          list2 = xmlsupport.sax_eventlist(xml2, ids = self.thubanids,
85                            sax_eventlist(xml2, self.thubanids,                                           idrefs = self.thubanidrefs)
86                                          self.thubanidrefs)):          if list1 != list2:
87                print a == b and ' ' or '*****'              for a, b in zip(list1, list2):
88                print a                  if a != b:
89                print b                      self.fail("%r != %r" % (a, b))
90          self.assertEquals(xmlsupport.sax_eventlist(xml1, ids = self.thubanids,  
                                                    idrefs = self.thubanidrefs),  
                           xmlsupport.sax_eventlist(xml2, ids = self.thubanids,  
                                                    idrefs = self.thubanidrefs))  
91    
92      def testEmptySession(self):      def testEmptySession(self):
93          """Save an empty session"""          """Save an empty session"""
# Line 104  class SaveSessionTest(unittest.TestCase, Line 101  class SaveSessionTest(unittest.TestCase,
101          file.close()          file.close()
102          self.compare_xml(written_contents,          self.compare_xml(written_contents,
103                           '<?xml version="1.0" encoding="UTF-8"?>\n'                           '<?xml version="1.0" encoding="UTF-8"?>\n'
104                           '<!DOCTYPE session SYSTEM "thuban-0.8.dtd">\n'                           '<!DOCTYPE session SYSTEM "thuban-0.9.dtd">\n'
105                           '<session title="empty session" '                           '<session title="empty session" '
106           'xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">'           'xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">'
107                           '\n</session>\n')                           '\n</session>\n')
108    
109          self.validate_data(written_contents)          self.validate_data(written_contents)
# Line 131  class SaveSessionTest(unittest.TestCase, Line 128  class SaveSessionTest(unittest.TestCase,
128          written_contents = file.read()          written_contents = file.read()
129          file.close()          file.close()
130          expected_template = '''<?xml version="1.0" encoding="UTF-8"?>          expected_template = '''<?xml version="1.0" encoding="UTF-8"?>
131          <!DOCTYPE session SYSTEM "thuban-0.8.dtd">          <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
132          <session title="single map&amp;layer"          <session title="single map&amp;layer"
133             xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">             xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
134              <fileshapesource id="D1" filename="%s" filetype="shapefile"/>              <fileshapesource id="D1" filename="%s" filetype="shapefile"/>
135              <map title="Test Map">              <map title="Test Map">
136                  <projection name="Unknown">                  <projection name="Unknown">
# Line 191  class SaveSessionTest(unittest.TestCase, Line 188  class SaveSessionTest(unittest.TestCase,
188          written_contents = file.read()          written_contents = file.read()
189          file.close()          file.close()
190          expected_contents = '''<?xml version="1.0" encoding="UTF-8"?>          expected_contents = '''<?xml version="1.0" encoding="UTF-8"?>
191          <!DOCTYPE session SYSTEM "thuban-0.8.dtd">          <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
192          <session title="single map&amp;layer"          <session title="single map&amp;layer"
193             xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">             xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
194              <fileshapesource id="D1" filename="%s" filetype="shapefile"/>              <fileshapesource id="D1" filename="%s" filetype="shapefile"/>
195              <map title="Test Map">              <map title="Test Map">
196                  <projection name="Unknown">                  <projection name="Unknown">
# Line 229  class SaveSessionTest(unittest.TestCase, Line 226  class SaveSessionTest(unittest.TestCase,
226          layer = RasterLayer("My RasterLayer", imgfile)          layer = RasterLayer("My RasterLayer", imgfile)
227          map.AddLayer(layer)          map.AddLayer(layer)
228    
229          filename = self.temp_file_name("save_singlemap.thuban")          filename = self.temp_file_name("%s.thuban" % self.id())
230          save_session(session, filename)          save_session(session, filename)
231          session.Destroy()          session.Destroy()
232    
# Line 237  class SaveSessionTest(unittest.TestCase, Line 234  class SaveSessionTest(unittest.TestCase,
234          written_contents = file.read()          written_contents = file.read()
235          file.close()          file.close()
236          expected_contents = '''<?xml version="1.0" encoding="UTF-8"?>          expected_contents = '''<?xml version="1.0" encoding="UTF-8"?>
237          <!DOCTYPE session SYSTEM "thuban-0.8.dtd">          <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
238          <session title="single map&amp;layer"          <session title="single map&amp;layer"
239             xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">             xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
240              <map title="Test Map">              <map title="Test Map">
241                  <rasterlayer title="My RasterLayer" filename="%s"                  <rasterlayer title="My RasterLayer" filename="%s"
242                               visible="true">                               visible="true">
243                  </rasterlayer>                  </rasterlayer>
244              </map>              </map>
245          </session>''' % os.path.join(os.path.dirname(__file__),          </session>''' % os.path.join(os.pardir, os.pardir, "Data", "iceland",
                                      os.pardir, "Data", "iceland",  
246                                       "island.tif")                                       "island.tif")
247          #print written_contents          #print written_contents
248          #print "********************************************"          #print "********************************************"
# Line 256  class SaveSessionTest(unittest.TestCase, Line 252  class SaveSessionTest(unittest.TestCase,
252          self.validate_data(written_contents)          self.validate_data(written_contents)
253    
254      def testClassifiedLayer(self):      def testClassifiedLayer(self):
255          """Save a session with a single map with a single layer          """Save a session with a single map with classifications"""
            with a classificaton.  
         """  
256          # deliberately put an apersand in the title :)          # deliberately put an apersand in the title :)
257          session = Session("single map&layer")          session = Session("Map with Classifications")
258          proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])          proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
259          map = Map("Test Map", projection = proj)          map = Map("Test Map", projection = proj)
260          session.AddMap(map)          session.AddMap(map)
# Line 269  class SaveSessionTest(unittest.TestCase, Line 263  class SaveSessionTest(unittest.TestCase,
263                                 os.pardir, "Data", "iceland", "political.shp")                                 os.pardir, "Data", "iceland", "political.shp")
264          layer = Layer("My Layer", session.OpenShapefile(shpfile))          layer = Layer("My Layer", session.OpenShapefile(shpfile))
265          map.AddLayer(layer)          map.AddLayer(layer)
266            layer2 = Layer("My Layer", layer.ShapeStore())
267            map.AddLayer(layer2)
268    
269          clazz = layer.GetClassification()          clazz = layer.GetClassification()
270    
271          clazz.SetField("AREA")          layer.SetClassificationColumn("AREA")
272    
273          clazz.AppendGroup(ClassGroupSingleton(42,          clazz.AppendGroup(ClassGroupSingleton(42, ClassGroupProperties(),
274                                             ClassGroupProperties(),                                                "single"))
275                                             "single"))          clazz.AppendGroup(ClassGroupSingleton("text", ClassGroupProperties(),
276          clazz.AppendGroup(ClassGroupSingleton("text",                                                "single-text"))
                                            ClassGroupProperties(),  
                                            "single-text"))  
277    
278          clazz.AppendGroup(ClassGroupRange(0, 42,          clazz.AppendGroup(ClassGroupRange((0, 42),
279                                             ClassGroupProperties(),                                             ClassGroupProperties(),
280                                             "range"))                                             "range"))
281    
# Line 290  class SaveSessionTest(unittest.TestCase, Line 284  class SaveSessionTest(unittest.TestCase,
284          range.SetLabel("new-range")          range.SetLabel("new-range")
285          clazz.AppendGroup(range)          clazz.AppendGroup(range)
286    
287          filename = self.temp_file_name("save_singlemap.thuban")  
288            clazz = layer2.GetClassification()
289            layer2.SetClassificationColumn("POPYCOUN")
290    
291            # Classification with Latin 1 text
292            clazz.AppendGroup(ClassGroupSingleton('\xe4\xf6\xfc', # ae, oe, ue
293                                                  ClassGroupProperties(),
294                                                  '\xdcml\xe4uts')) # Uemlaeuts
295    
296    
297            filename = self.temp_file_name("%s.thuban" % self.id())
298          save_session(session, filename)          save_session(session, filename)
299    
300          file = open(filename)          file = open(filename)
301          written_contents = file.read()          written_contents = file.read()
302          file.close()          file.close()
303          expected_template = '''<?xml version="1.0" encoding="UTF-8"?>          expected_template = '''<?xml version="1.0" encoding="UTF-8"?>
304          <!DOCTYPE session SYSTEM "thuban-0.8.dtd">          <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
305          <session title="single map&amp;layer"          <session title="Map with Classifications"
306             xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">             xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
307              <fileshapesource id="D1" filename="%s" filetype="shapefile"/>              <fileshapesource id="D1" filename="%s" filetype="shapefile"/>
308              <map title="Test Map">              <map title="Test Map">
309                  <projection name="Unknown">                  <projection name="Unknown">
# Line 327  class SaveSessionTest(unittest.TestCase, Line 331  class SaveSessionTest(unittest.TestCase,
331                          </clrange>                          </clrange>
332                      </classification>                      </classification>
333                  </layer>                  </layer>
334                    <layer title="My Layer" shapestore="D1"
335                    fill="None" stroke="#000000" stroke_width="1" visible="true">
336                        <classification field="POPYCOUN" field_type="string">
337                            <clnull label="">
338                                <cldata fill="None" stroke="#000000" stroke_width="1"/>
339                            </clnull>
340                            <clpoint value="\xc3\xa4\xc3\xb6\xc3\xbc"
341                                 label="\xc3\x9cml\xc3\xa4uts">
342                                <cldata fill="None" stroke="#000000" stroke_width="1"/>
343                            </clpoint>
344                        </classification>
345                    </layer>
346              </map>              </map>
347          </session>'''          </session>'''
348    
# Line 358  class SaveSessionTest(unittest.TestCase, Line 374  class SaveSessionTest(unittest.TestCase,
374          written_contents = file.read()          written_contents = file.read()
375          file.close()          file.close()
376          expected_template = '''<?xml version="1.0" encoding="UTF-8"?>          expected_template = '''<?xml version="1.0" encoding="UTF-8"?>
377          <!DOCTYPE session SYSTEM "thuban-0.8.dtd">          <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
378          <session title="a DBF Table session"          <session title="a DBF Table session"
379             xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">             xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
380              <filetable id="D1" filename="%s" filetype="DBF" title="political"/>              <filetable id="D1" filename="%s" filetype="DBF" title="political"/>
381          </session>'''          </session>'''
382    
383          expected_contents = expected_template % dbffile          expected_contents = (expected_template
384                                 % os.path.join(os.pardir, os.pardir, "Data",
385                                                "iceland", "political.dbf"))
386          self.compare_xml(written_contents, expected_contents)          self.compare_xml(written_contents, expected_contents)
387    
388      def test_joined_table(self):      def test_joined_table(self):
# Line 401  class SaveSessionTest(unittest.TestCase, Line 419  class SaveSessionTest(unittest.TestCase,
419              #    print col.name              #    print col.name
420              joined = TransientJoinedTable(session.TransientDB(),              joined = TransientJoinedTable(session.TransientDB(),
421                                            store.Table(), "RDLNTYPE",                                            store.Table(), "RDLNTYPE",
422                                            dbftable, "RDTYPE")                                            dbftable, "RDTYPE",
423                                              outer_join = True)
424              store = session.AddShapeStore(DerivedShapeStore(store, joined))              store = session.AddShapeStore(DerivedShapeStore(store, joined))
425              layer.SetShapeStore(store)              layer.SetShapeStore(store)
426    
# Line 414  class SaveSessionTest(unittest.TestCase, Line 433  class SaveSessionTest(unittest.TestCase,
433              written_contents = file.read()              written_contents = file.read()
434              file.close()              file.close()
435              expected_template = '''<?xml version="1.0" encoding="UTF-8"?>              expected_template = '''<?xml version="1.0" encoding="UTF-8"?>
436              <!DOCTYPE session SYSTEM "thuban-0.8.dtd">              <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
437              <session title="A Joined Table session"              <session title="A Joined Table session"
438               xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd">               xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
439                  <fileshapesource filename="%(shpfile)s"                  <fileshapesource filename="%(shpfile)s"
440                                   filetype="shapefile" id="D142197204"/>                                   filetype="shapefile" id="D142197204"/>
441                  <filetable filename="%(dbffile)s"                  <filetable filename="%(dbffile)s"
# Line 425  class SaveSessionTest(unittest.TestCase, Line 444  class SaveSessionTest(unittest.TestCase,
444                  <jointable id="D142180284"                  <jointable id="D142180284"
445                             title="Join of roads-line and save_joinedtable"                             title="Join of roads-line and save_joinedtable"
446                             leftcolumn="RDLNTYPE" left="D142197204"                             leftcolumn="RDLNTYPE" left="D142197204"
447                             rightcolumn="RDTYPE" right="D141881756"/>                             rightcolumn="RDTYPE" right="D141881756"
448                               jointype="LEFT OUTER" />
449                  <derivedshapesource id="D141915644"                  <derivedshapesource id="D141915644"
450                                      table="D142180284"                                      table="D142180284"
451                                      shapesource="D142197204"/>                                      shapesource="D142197204"/>

Legend:
Removed from v.1268  
changed lines
  Added in v.1599

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26