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

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

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

revision 584 by jonathan, Tue Apr 1 10:22:35 2003 UTC revision 982 by bh, Thu May 22 12:02:15 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002 by Intevation GmbH  # Copyright (c) 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 27  from Thuban.Model.map import Map Line 27  from Thuban.Model.map import Map
27  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
28  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
29  from Thuban.Model.color import Color  from Thuban.Model.color import Color
30    from Thuban.Model.table import MemoryTable, FIELDTYPE_STRING, \
31                                   FIELDTYPE_INT, FIELDTYPE_DOUBLE
32    
33  class TestSessionSimple(unittest.TestCase):  class TestSessionSimple(unittest.TestCase):
34    
# Line 38  class TestSessionSimple(unittest.TestCas Line 39  class TestSessionSimple(unittest.TestCas
39          session = Session("Test Session")          session = Session("Test Session")
40          self.assertEquals(session.Title(), "Test Session")          self.assertEquals(session.Title(), "Test Session")
41          self.assertEquals(session.Maps(), [])          self.assertEquals(session.Maps(), [])
42            self.assertEquals(session.Tables(), [])
43            self.assertEquals(session.ShapeStores(), [])
44          self.assertEquals(session.filename, None)          self.assertEquals(session.filename, None)
45          self.failIf(session.HasMaps())          self.failIf(session.HasMaps())
46          self.failIf(session.WasModified())          self.failIf(session.WasModified())
47          session.Destroy()          session.Destroy()
48    
49        def test_add_table(self):
50            """Test Session.AddTable()"""
51            session = Session("Test Session")
52            memtable = MemoryTable([("type", FIELDTYPE_STRING),
53                                    ("value", FIELDTYPE_DOUBLE),
54                                    ("code", FIELDTYPE_INT)],
55                                   [("OTHER/UNKNOWN", -1.5, 11),
56                                    ("RUINS", 0.0, 1),
57                                    ("FARM", 3.141, 2),
58                                    ("BUILDING", 2.5, 3),
59                                    ("HUT", 1e6, 4),
60                                    ("LIGHTHOUSE", -0.01, 5)])
61            table = session.AddTable(memtable)
62            self.assertEquals(session.Tables(), [table])
63    
64    
65  class TestSessionBase(unittest.TestCase, support.SubscriberMixin):  class TestSessionBase(unittest.TestCase, support.SubscriberMixin):
66    
# Line 71  class TestSessionBase(unittest.TestCase, Line 89  class TestSessionBase(unittest.TestCase,
89      def tearDown(self):      def tearDown(self):
90          """Destroy self.session and clear the message list"""          """Destroy self.session and clear the message list"""
91          self.session.Destroy()          self.session.Destroy()
92            self.session = None
93          self.clear_messages()          self.clear_messages()
94    
95    
# Line 105  class TestSessionWithContent(TestSession Line 124  class TestSessionWithContent(TestSession
124          """Extend the inherited method to add a non-empty map to self.session          """Extend the inherited method to add a non-empty map to self.session
125          """          """
126          TestSessionBase.setUp(self)          TestSessionBase.setUp(self)
127            open_shp = self.session.OpenShapefile
128          self.arc_layer = Layer("Roads",          self.arc_layer = Layer("Roads",
129                                 os.path.join("..", "Data", "iceland",                                 open_shp(os.path.join("..", "Data", "iceland",
130                                              "roads-line.shp"))                                                       "roads-line.shp")))
131          self.poly_layer = Layer("Political",          self.poly_layer = Layer("Political",
132                                  os.path.join("..", "Data", "iceland",                                  open_shp(os.path.join("..", "Data", "iceland",
133                                               "political.shp"))                                                        "political.shp")))
134          self.map = Map("A Map")          self.map = Map("A Map")
135          self.map.AddLayer(self.arc_layer)          self.map.AddLayer(self.arc_layer)
136          self.map.AddLayer(self.poly_layer)          self.map.AddLayer(self.poly_layer)
# Line 118  class TestSessionWithContent(TestSession Line 138  class TestSessionWithContent(TestSession
138          self.session.UnsetModified()          self.session.UnsetModified()
139          self.clear_messages()          self.clear_messages()
140    
141        def tearDown(self):
142            TestSessionBase.tearDown(self)
143            self.arc_layer = self.poly_layer = None
144    
145      def test_remove_map(self):      def test_remove_map(self):
146          """Test Session.RemoveMap"""          """Test Session.RemoveMap"""
147          self.session.RemoveMap(self.map)          self.session.RemoveMap(self.map)
# Line 201  class TestSessionWithContent(TestSession Line 225  class TestSessionWithContent(TestSession
225                               (self.session, CHANGED),                               (self.session, CHANGED),
226                               (CHANGED,)])                               (CHANGED,)])
227    
228        def test_shape_stores(self):
229            """Test Session.ShapeStores()"""
230            # Strictly speaking the session doesn't make guarantees about
231            # the order of the ShapeStores in the list, but currently it's
232            # deterministic and they're listed in the order in which they
233            # were created
234            self.assertEquals(self.session.ShapeStores(),
235                              [self.arc_layer.ShapeStore(),
236                               self.poly_layer.ShapeStore()])
237            # If we remove the map from the session and clear our instance
238            # variables that hold the layers and the map the list should
239            # become empty again.
240            self.session.RemoveMap(self.map)
241            self.arc_layer = self.poly_layer = self.map = None
242            self.assertEquals(self.session.ShapeStores(), [])
243    
244        def test_tables(self):
245            """Test Session.Tables()"""
246            # Strictly speaking the session doesn't make guarantees about
247            # the order of the tables in the list, but currently it's
248            # deterministic and they're listed in the order in which they
249            # were opened
250            self.assertEquals(self.session.Tables(),
251                              [self.arc_layer.ShapeStore().Table(),
252                               self.poly_layer.ShapeStore().Table()])
253            # If we remove the map from the session and clear our instance
254            # variables that hold the layers and the map the list should
255            # become empty again.
256            self.session.RemoveMap(self.map)
257            self.arc_layer = self.poly_layer = self.map = None
258            self.assertEquals(self.session.Tables(), [])
259    
260    
261  if __name__ == "__main__":  if __name__ == "__main__":
262      unittest.main()      unittest.main()

Legend:
Removed from v.584  
changed lines
  Added in v.982

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26