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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 851 - (hide annotations)
Wed May 7 15:11:12 2003 UTC (21 years, 10 months ago) by bh
Original Path: trunk/thuban/test/test_session.py
File MIME type: text/x-python
File size: 9612 byte(s)
* Thuban/Model/session.py (Session.__init__): New instance
variable shapestores to hold a list of all open shapestore objects
(Session.ShapeStores): New. Accessor method for the shapestores
list.
(Session._add_shapestore, Session._clean_weak_store_refs): New.
Internal methods to maintain the shapestores list.
(Session.Tables): New. Return all tables open in the session.
(Session.OpenShapefile): Insert the new ShapeStore into the
shapestores list.

* test/test_session.py (TestSessionSimple.test_initial_state): Add
tests for ShapeStores and Tables
(TestSessionWithContent.test_shape_stores)
(TestSessionWithContent.test_tables): New. Test cases for
ShapeStores and Tables

1 bh 723 # Copyright (c) 2002, 2003 by Intevation GmbH
2 bh 334 # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Test the Session class
10     """
11    
12     __version__ = "$Revision$"
13     # $Source$
14     # $Id$
15    
16     import os
17     import unittest
18    
19     import support
20     support.initthuban()
21    
22     from Thuban.Model.messages import CHANGED, MAPS_CHANGED, FILENAME_CHANGED, \
23 jonathan 584 MAP_PROJECTION_CHANGED, MAP_LAYERS_CHANGED, \
24     LAYER_VISIBILITY_CHANGED, LAYER_CHANGED
25 bh 334 from Thuban.Model.session import Session
26     from Thuban.Model.map import Map
27     from Thuban.Model.layer import Layer
28     from Thuban.Model.proj import Projection
29     from Thuban.Model.color import Color
30    
31    
32     class TestSessionSimple(unittest.TestCase):
33    
34     """Very simple test cases for Session"""
35    
36     def test_initial_state(self):
37     """Test Session's initial state"""
38     session = Session("Test Session")
39     self.assertEquals(session.Title(), "Test Session")
40     self.assertEquals(session.Maps(), [])
41 bh 851 self.assertEquals(session.Tables(), [])
42     self.assertEquals(session.ShapeStores(), [])
43 bh 334 self.assertEquals(session.filename, None)
44     self.failIf(session.HasMaps())
45     self.failIf(session.WasModified())
46     session.Destroy()
47    
48    
49     class TestSessionBase(unittest.TestCase, support.SubscriberMixin):
50    
51     """Base class for Session test cases that test the messages"""
52    
53     def setUp(self):
54     """
55     Clear the message list, create a session and subscribe to its messages
56    
57     Bind the session to self.session.
58     """
59     self.clear_messages()
60    
61     # Create a Session and subscribe to all interesting channels.
62     self.session = Session("Test Session")
63 jonathan 584 for channel in (CHANGED,
64     MAPS_CHANGED,
65     FILENAME_CHANGED,
66     MAP_PROJECTION_CHANGED,
67     MAP_LAYERS_CHANGED,
68     LAYER_VISIBILITY_CHANGED,
69     LAYER_CHANGED):
70 bh 334 self.session.Subscribe(channel,
71     self.subscribe_with_params, channel)
72    
73     def tearDown(self):
74     """Destroy self.session and clear the message list"""
75     self.session.Destroy()
76 bh 723 self.session = None
77 bh 334 self.clear_messages()
78    
79    
80     class TestSessionMessages(TestSessionBase):
81    
82     """Simple Session test cases that test messges"""
83    
84     def test_add_map(self):
85     """Test Session.AddMap"""
86     self.failIf(self.session.WasModified())
87     map = Map("Some Map")
88     self.session.AddMap(map)
89     self.assert_(self.session.HasMaps())
90     self.assert_(self.session.WasModified())
91     self.assertEquals(self.session.Maps(), [map])
92     self.check_messages([(MAPS_CHANGED,),
93     (self.session, CHANGED)])
94    
95     def test_set_filename(self):
96     """Test Session.SetFilename"""
97     self.session.SetFilename("session_set_filename_test")
98     self.session.filename = "session_set_filename_test"
99     self.check_messages([(FILENAME_CHANGED,),
100     (self.session, CHANGED)])
101    
102    
103     class TestSessionWithContent(TestSessionBase):
104    
105     """Session test cases that start with a filled session."""
106    
107     def setUp(self):
108     """Extend the inherited method to add a non-empty map to self.session
109     """
110     TestSessionBase.setUp(self)
111 bh 723 open_shp = self.session.OpenShapefile
112 bh 334 self.arc_layer = Layer("Roads",
113 bh 723 open_shp(os.path.join("..", "Data", "iceland",
114     "roads-line.shp")))
115 bh 334 self.poly_layer = Layer("Political",
116 bh 723 open_shp(os.path.join("..", "Data", "iceland",
117     "political.shp")))
118 bh 334 self.map = Map("A Map")
119     self.map.AddLayer(self.arc_layer)
120     self.map.AddLayer(self.poly_layer)
121     self.session.AddMap(self.map)
122     self.session.UnsetModified()
123     self.clear_messages()
124    
125 bh 723 def tearDown(self):
126     TestSessionBase.tearDown(self)
127     self.arc_layer = self.poly_layer = None
128    
129 bh 334 def test_remove_map(self):
130     """Test Session.RemoveMap"""
131     self.session.RemoveMap(self.map)
132     self.assert_(self.session.WasModified())
133     self.failIf(self.session.HasMaps())
134     self.check_messages([(MAPS_CHANGED,),
135     (self.session, CHANGED)])
136    
137     def test_tree_info(self):
138     """Test Session.TreeInfo"""
139     self.assertEquals(self.session.TreeInfo(),
140     ('Session: Test Session',
141     ['Filename:',
142     'Unmodified',
143     self.map]))
144    
145     def test_forward_map_projection(self):
146     """Test Session forwarding of Map.SetProjection messages"""
147     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
148     self.map.SetProjection(proj)
149     self.check_messages([(self.map, MAP_PROJECTION_CHANGED),
150     (self.session, CHANGED)])
151     self.assert_(self.session.WasModified())
152    
153     def test_forward_map_projection(self):
154     """Test Session forwarding of Map.SetProjection messages"""
155     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
156     self.map.SetProjection(proj)
157     self.assert_(self.session.WasModified())
158     self.check_messages([(self.map, MAP_PROJECTION_CHANGED),
159     (self.session, CHANGED)])
160    
161     def test_forwarding_fill(self):
162     """Test Session's forwarding of Layer.SetFill messages"""
163 jonathan 409 self.poly_layer.GetClassification().SetDefaultFill(Color(0.0, 0.5, 1.0))
164 bh 334 self.assert_(self.session.WasModified())
165 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
166 bh 334 (self.session, CHANGED)])
167    
168     def test_forwarding_stroke(self):
169     """Test Session's forwarding of Layer.SetStroke messages"""
170 jonathan 409 self.poly_layer.GetClassification().\
171 jonathan 482 SetDefaultLineColor(Color(0.0, 0.5, 1.0))
172 bh 334 self.assert_(self.session.WasModified())
173 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
174 bh 334 (self.session, CHANGED)])
175    
176     def test_forwarding_stroke_width(self):
177     """Test Session's forwarding of Layer.SetStrokeWidth messages"""
178 jonathan 482 self.poly_layer.GetClassification().SetDefaultLineWidth(3)
179 bh 334 self.assert_(self.session.WasModified())
180 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
181 bh 334 (self.session, CHANGED)])
182    
183     def test_forwarding_visibility(self):
184     """Test Session's forwarding of Layer.SetVisible messages"""
185     self.poly_layer.SetVisible(0)
186     # Currently changing the visibility of a layer doesn't change
187     # the modification flag.
188     self.failIf(self.session.WasModified())
189     self.check_messages([(self.poly_layer, LAYER_VISIBILITY_CHANGED),
190     (self.session, CHANGED)])
191    
192     def test_unset_modified_map(self):
193     """Test Session.UnsetModified with map level changes"""
194     self.failIf(self.session.WasModified())
195     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
196     self.map.SetProjection(proj)
197     self.assert_(self.session.WasModified())
198     self.session.UnsetModified()
199     self.failIf(self.session.WasModified())
200    
201     def test_unset_modified_layer(self):
202     """Test Session.UnsetModified with layer level changes"""
203     self.failIf(self.session.WasModified())
204 jonathan 482 self.poly_layer.GetClassification().SetDefaultLineWidth(3)
205 bh 334 self.assert_(self.session.WasModified())
206     self.session.UnsetModified()
207     self.failIf(self.session.WasModified())
208 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
209 bh 334 (self.session, CHANGED),
210     (CHANGED,)])
211    
212 bh 851 def test_shape_stores(self):
213     """Test Session.ShapeStores()"""
214     # Strictly speaking the session doesn't make guarantees about
215     # the order of the ShapeStores in the list, but currently it's
216     # deterministic and they're listed in the order in which they
217     # were created
218     self.assertEquals(self.session.ShapeStores(),
219     [self.arc_layer.ShapeStore(),
220     self.poly_layer.ShapeStore()])
221     # If we remove the map from the session and clear our instance
222     # variables that hold the layers and the map the list should
223     # become empty again.
224     self.session.RemoveMap(self.map)
225     self.arc_layer = self.poly_layer = self.map = None
226     self.assertEquals(self.session.ShapeStores(), [])
227 bh 334
228 bh 851 def test_tables(self):
229     """Test Session.Tables()"""
230     # Strictly speaking the session doesn't make guarantees about
231     # the order of the tables in the list, but currently it's
232     # deterministic and they're listed in the order in which they
233     # were opened
234     self.assertEquals(self.session.Tables(),
235     [self.arc_layer.ShapeStore().Table(),
236     self.poly_layer.ShapeStore().Table()])
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.Tables(), [])
243    
244    
245 bh 334 if __name__ == "__main__":
246     unittest.main()

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26