/[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 984 by bh, Thu May 22 16:37:48 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_open_shapefile(self):
73            """Test Session.OpenShapefile()"""
74            session = self.session = Session("Test Session")
75            filename = os.path.join("..", "Data", "iceland",
76                                    "roads-line.shp")
77            store = session.OpenShapefile(filename)
78            self.assertEquals(store.FileName(), os.path.abspath(filename))
79            # The filetype of a shapefile is "shapefile"
80            self.assertEquals(store.FileType(), "shapefile")
81            # The shapestore itself depends on nothing else
82            self.assertEquals(store.Dependencies(), ())
83            # The shapestore's table depends on the shapestore
84            self.assertEquals(store.Table().Dependencies(), (store,))
85    
86            self.assertEquals(session.Tables(), [store.Table()])
87    
88    
89  class TestSessionBase(unittest.TestCase, support.SubscriberMixin):  class TestSessionBase(unittest.TestCase, support.SubscriberMixin):
# Line 207  class TestSessionWithContent(TestSession Line 249  class TestSessionWithContent(TestSession
249                               (self.session, CHANGED),                               (self.session, CHANGED),
250                               (CHANGED,)])                               (CHANGED,)])
251    
252        def test_shape_stores(self):
253            """Test Session.ShapeStores()"""
254            # Strictly speaking the session doesn't make guarantees about
255            # the order of the ShapeStores in the list, but currently it's
256            # deterministic and they're listed in the order in which they
257            # were created
258            self.assertEquals(self.session.ShapeStores(),
259                              [self.arc_layer.ShapeStore(),
260                               self.poly_layer.ShapeStore()])
261            # If we remove the map from the session and clear our instance
262            # variables that hold the layers and the map the list should
263            # become empty again.
264            self.session.RemoveMap(self.map)
265            self.arc_layer = self.poly_layer = self.map = None
266            self.assertEquals(self.session.ShapeStores(), [])
267    
268        def test_tables(self):
269            """Test Session.Tables()"""
270            # Strictly speaking the session doesn't make guarantees about
271            # the order of the tables in the list, but currently it's
272            # deterministic and they're listed in the order in which they
273            # were opened
274            self.assertEquals(self.session.Tables(),
275                              [self.arc_layer.ShapeStore().Table(),
276                               self.poly_layer.ShapeStore().Table()])
277            # If we remove the map from the session and clear our instance
278            # variables that hold the layers and the map the list should
279            # become empty again.
280            self.session.RemoveMap(self.map)
281            self.arc_layer = self.poly_layer = self.map = None
282            self.assertEquals(self.session.Tables(), [])
283    
284    
285  if __name__ == "__main__":  if __name__ == "__main__":
286      unittest.main()      unittest.main()

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26