/[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 723 by bh, Thu Apr 24 15:31:53 2003 UTC revision 987 by bh, Thu May 22 16:46:14 2003 UTC
# 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    
35      """Very simple test cases for Session"""      """Very simple test cases for Session"""
36    
37        def setUp(self):
38            """Initialize self.session to None"""
39            self.session = None
40    
41        def tearDown(self):
42            """Call self.session.Destroy() and reset self.session to None"""
43            self.session.Destroy()
44            self.session = None
45    
46      def test_initial_state(self):      def test_initial_state(self):
47          """Test Session's initial state"""          """Test Session's initial state"""
48          session = Session("Test Session")          session = self.session = Session("Test Session")
49          self.assertEquals(session.Title(), "Test Session")          self.assertEquals(session.Title(), "Test Session")
50          self.assertEquals(session.Maps(), [])          self.assertEquals(session.Maps(), [])
51            self.assertEquals(session.Tables(), [])
52            self.assertEquals(session.ShapeStores(), [])
53          self.assertEquals(session.filename, None)          self.assertEquals(session.filename, None)
54          self.failIf(session.HasMaps())          self.failIf(session.HasMaps())
55          self.failIf(session.WasModified())          self.failIf(session.WasModified())
56          session.Destroy()  
57        def test_add_table(self):
58            """Test Session.AddTable()"""
59            session = self.session = Session("Test Session")
60            memtable = MemoryTable([("type", FIELDTYPE_STRING),
61                                    ("value", FIELDTYPE_DOUBLE),
62                                    ("code", FIELDTYPE_INT)],
63                                   [("OTHER/UNKNOWN", -1.5, 11),
64                                    ("RUINS", 0.0, 1),
65                                    ("FARM", 3.141, 2),
66                                    ("BUILDING", 2.5, 3),
67                                    ("HUT", 1e6, 4),
68                                    ("LIGHTHOUSE", -0.01, 5)])
69            table = session.AddTable(memtable)
70            self.assertEquals(session.Tables(), [table])
71    
72        def test_remove_table(self):
73            """Test Session.RemoveTable()"""
74            session = self.session = Session("Test Session")
75            memtable = MemoryTable([("type", FIELDTYPE_STRING),
76                                    ("value", FIELDTYPE_DOUBLE),
77                                    ("code", FIELDTYPE_INT)],
78                                   [("OTHER/UNKNOWN", -1.5, 11),
79                                    ("RUINS", 0.0, 1),
80                                    ("FARM", 3.141, 2),
81                                    ("BUILDING", 2.5, 3),
82                                    ("HUT", 1e6, 4),
83                                    ("LIGHTHOUSE", -0.01, 5)])
84            table = session.AddTable(memtable)
85            self.assertEquals(session.Tables(), [table])
86            session.RemoveTable(table)
87            self.assertEquals(session.Tables(), [])
88            self.assertRaises(ValueError, session.RemoveTable, table)
89    
90        def test_open_shapefile(self):
91            """Test Session.OpenShapefile()"""
92            session = self.session = Session("Test Session")
93            filename = os.path.join("..", "Data", "iceland",
94                                    "roads-line.shp")
95            store = session.OpenShapefile(filename)
96            self.assertEquals(store.FileName(), os.path.abspath(filename))
97            # The filetype of a shapefile is "shapefile"
98            self.assertEquals(store.FileType(), "shapefile")
99            # The shapestore itself depends on nothing else
100            self.assertEquals(store.Dependencies(), ())
101            # The shapestore's table depends on the shapestore
102            self.assertEquals(store.Table().Dependencies(), (store,))
103    
104            self.assertEquals(session.Tables(), [store.Table()])
105    
106    
107  class TestSessionBase(unittest.TestCase, support.SubscriberMixin):  class TestSessionBase(unittest.TestCase, support.SubscriberMixin):
# Line 207  class TestSessionWithContent(TestSession Line 267  class TestSessionWithContent(TestSession
267                               (self.session, CHANGED),                               (self.session, CHANGED),
268                               (CHANGED,)])                               (CHANGED,)])
269    
270        def test_shape_stores(self):
271            """Test Session.ShapeStores()"""
272            # Strictly speaking the session doesn't make guarantees about
273            # the order of the ShapeStores in the list, but currently it's
274            # deterministic and they're listed in the order in which they
275            # were created
276            self.assertEquals(self.session.ShapeStores(),
277                              [self.arc_layer.ShapeStore(),
278                               self.poly_layer.ShapeStore()])
279            # If we remove the map from the session and clear our instance
280            # variables that hold the layers and the map the list should
281            # become empty again.
282            self.session.RemoveMap(self.map)
283            self.arc_layer = self.poly_layer = self.map = None
284            self.assertEquals(self.session.ShapeStores(), [])
285    
286        def test_tables(self):
287            """Test Session.Tables()"""
288            # Strictly speaking the session doesn't make guarantees about
289            # the order of the tables in the list, but currently it's
290            # deterministic and they're listed in the order in which they
291            # were opened
292            self.assertEquals(self.session.Tables(),
293                              [self.arc_layer.ShapeStore().Table(),
294                               self.poly_layer.ShapeStore().Table()])
295            # If we remove the map from the session and clear our instance
296            # variables that hold the layers and the map the list should
297            # become empty again.
298            self.session.RemoveMap(self.map)
299            self.arc_layer = self.poly_layer = self.map = None
300            self.assertEquals(self.session.Tables(), [])
301    
302    
303  if __name__ == "__main__":  if __name__ == "__main__":
304      unittest.main()      unittest.main()

Legend:
Removed from v.723  
changed lines
  Added in v.987

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26