/[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 723 - (hide annotations)
Thu Apr 24 15:31:53 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: 7912 byte(s)
First step towards table management. Introduce a simple data
abstraction so that we replace the data a layer uses more easily
in the next step.

* Thuban/Model/data.py: New file with a simple data abstraction
that bundles shapefile and dbffile into one object.

* Thuban/Model/session.py (Session.OpenShapefile): New method to
open shapefiles and return a shape store object

* Thuban/Model/layer.py (Layer.__init__): Pass the data as a store
object instead of a shapefile filename. This introduces a new
instance variable store holding the datastore. For intermediate
backwards compatibility keep the old instance variables.
(open_shapefile): Removed. No longer needed with the shape store.
(Layer.SetShapeStore, Layer.ShapeStore): New methods to set and
get the shape store used by a layer.
(Layer.Destroy): No need to explicitly destroy the shapefile or
table anymore.

* Thuban/UI/mainwindow.py (MainWindow.AddLayer)
(MainWindow.AddLayer): Use the session's OpenShapefile method to
open shapefiles

* Thuban/Model/load.py (ProcessSession.start_layer): Use the
session's OpenShapefile method to open shapefiles

* test/test_classification.py
(TestClassification.test_classification): Use the session's
OpenShapefile method to open shapefiles and build the filename in
a more platform independed way

* test/test_layer.py (TestLayer.setUp, TestLayer.tearDown):
Implement to have a session to use in the tests
(TestLayer.test_arc_layer, TestLayer.test_polygon_layer)
(TestLayer.test_point_layer, TestLayer.test_empty_layer): Use the
session's OpenShapefile method to open shapefiles
(TestLayerLegend.setUp): Instantiate a session so that we can use
it to open shapefiles.
(TestLayerLegend.tearDown): Make sure that all references to
layers and session are removed otherwise we may get a resource
leak

* test/test_map.py (TestMapAddLayer.test_add_layer)
(TestMapWithContents.setUp): Instantiate a session so that we can
use it to open shapefiles.
(TestMapWithContents.tearDown): Make sure that all references to
layers, maps and sessions are removed otherwise we may get a
resource leak
("__main__"): use support.run_tests() so that more info about
uncollected garbage is printed

* test/test_save.py (SaveSessionTest.testSingleLayer): Use the
session's OpenShapefile method to open shapefiles
("__main__"): use support.run_tests() so that more info about
uncollected garbage is printed

* test/test_selection.py (TestSelection.tearDown): Make sure that
all references to the session and the selection are removed
otherwise we may get a resource leak
(TestSelection.get_layer): Instantiate a session so that we can
use it to open shapefiles.
("__main__"): use support.run_tests() so that more info about
uncollected garbage is printed

* test/test_session.py (TestSessionBase.tearDown)
(TestSessionWithContent.tearDown): Make sure that all references
to the session and layers are removed otherwise we may get a
resource leak
(TestSessionWithContent.setUp): Use the session's OpenShapefile
method to open shapefiles

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     self.assertEquals(session.filename, None)
42     self.failIf(session.HasMaps())
43     self.failIf(session.WasModified())
44     session.Destroy()
45    
46    
47     class TestSessionBase(unittest.TestCase, support.SubscriberMixin):
48    
49     """Base class for Session test cases that test the messages"""
50    
51     def setUp(self):
52     """
53     Clear the message list, create a session and subscribe to its messages
54    
55     Bind the session to self.session.
56     """
57     self.clear_messages()
58    
59     # Create a Session and subscribe to all interesting channels.
60     self.session = Session("Test Session")
61 jonathan 584 for channel in (CHANGED,
62     MAPS_CHANGED,
63     FILENAME_CHANGED,
64     MAP_PROJECTION_CHANGED,
65     MAP_LAYERS_CHANGED,
66     LAYER_VISIBILITY_CHANGED,
67     LAYER_CHANGED):
68 bh 334 self.session.Subscribe(channel,
69     self.subscribe_with_params, channel)
70    
71     def tearDown(self):
72     """Destroy self.session and clear the message list"""
73     self.session.Destroy()
74 bh 723 self.session = None
75 bh 334 self.clear_messages()
76    
77    
78     class TestSessionMessages(TestSessionBase):
79    
80     """Simple Session test cases that test messges"""
81    
82     def test_add_map(self):
83     """Test Session.AddMap"""
84     self.failIf(self.session.WasModified())
85     map = Map("Some Map")
86     self.session.AddMap(map)
87     self.assert_(self.session.HasMaps())
88     self.assert_(self.session.WasModified())
89     self.assertEquals(self.session.Maps(), [map])
90     self.check_messages([(MAPS_CHANGED,),
91     (self.session, CHANGED)])
92    
93     def test_set_filename(self):
94     """Test Session.SetFilename"""
95     self.session.SetFilename("session_set_filename_test")
96     self.session.filename = "session_set_filename_test"
97     self.check_messages([(FILENAME_CHANGED,),
98     (self.session, CHANGED)])
99    
100    
101     class TestSessionWithContent(TestSessionBase):
102    
103     """Session test cases that start with a filled session."""
104    
105     def setUp(self):
106     """Extend the inherited method to add a non-empty map to self.session
107     """
108     TestSessionBase.setUp(self)
109 bh 723 open_shp = self.session.OpenShapefile
110 bh 334 self.arc_layer = Layer("Roads",
111 bh 723 open_shp(os.path.join("..", "Data", "iceland",
112     "roads-line.shp")))
113 bh 334 self.poly_layer = Layer("Political",
114 bh 723 open_shp(os.path.join("..", "Data", "iceland",
115     "political.shp")))
116 bh 334 self.map = Map("A Map")
117     self.map.AddLayer(self.arc_layer)
118     self.map.AddLayer(self.poly_layer)
119     self.session.AddMap(self.map)
120     self.session.UnsetModified()
121     self.clear_messages()
122    
123 bh 723 def tearDown(self):
124     TestSessionBase.tearDown(self)
125     self.arc_layer = self.poly_layer = None
126    
127 bh 334 def test_remove_map(self):
128     """Test Session.RemoveMap"""
129     self.session.RemoveMap(self.map)
130     self.assert_(self.session.WasModified())
131     self.failIf(self.session.HasMaps())
132     self.check_messages([(MAPS_CHANGED,),
133     (self.session, CHANGED)])
134    
135     def test_tree_info(self):
136     """Test Session.TreeInfo"""
137     self.assertEquals(self.session.TreeInfo(),
138     ('Session: Test Session',
139     ['Filename:',
140     'Unmodified',
141     self.map]))
142    
143     def test_forward_map_projection(self):
144     """Test Session forwarding of Map.SetProjection messages"""
145     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
146     self.map.SetProjection(proj)
147     self.check_messages([(self.map, MAP_PROJECTION_CHANGED),
148     (self.session, CHANGED)])
149     self.assert_(self.session.WasModified())
150    
151     def test_forward_map_projection(self):
152     """Test Session forwarding of Map.SetProjection messages"""
153     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
154     self.map.SetProjection(proj)
155     self.assert_(self.session.WasModified())
156     self.check_messages([(self.map, MAP_PROJECTION_CHANGED),
157     (self.session, CHANGED)])
158    
159     def test_forwarding_fill(self):
160     """Test Session's forwarding of Layer.SetFill messages"""
161 jonathan 409 self.poly_layer.GetClassification().SetDefaultFill(Color(0.0, 0.5, 1.0))
162 bh 334 self.assert_(self.session.WasModified())
163 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
164 bh 334 (self.session, CHANGED)])
165    
166     def test_forwarding_stroke(self):
167     """Test Session's forwarding of Layer.SetStroke messages"""
168 jonathan 409 self.poly_layer.GetClassification().\
169 jonathan 482 SetDefaultLineColor(Color(0.0, 0.5, 1.0))
170 bh 334 self.assert_(self.session.WasModified())
171 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
172 bh 334 (self.session, CHANGED)])
173    
174     def test_forwarding_stroke_width(self):
175     """Test Session's forwarding of Layer.SetStrokeWidth messages"""
176 jonathan 482 self.poly_layer.GetClassification().SetDefaultLineWidth(3)
177 bh 334 self.assert_(self.session.WasModified())
178 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
179 bh 334 (self.session, CHANGED)])
180    
181     def test_forwarding_visibility(self):
182     """Test Session's forwarding of Layer.SetVisible messages"""
183     self.poly_layer.SetVisible(0)
184     # Currently changing the visibility of a layer doesn't change
185     # the modification flag.
186     self.failIf(self.session.WasModified())
187     self.check_messages([(self.poly_layer, LAYER_VISIBILITY_CHANGED),
188     (self.session, CHANGED)])
189    
190     def test_unset_modified_map(self):
191     """Test Session.UnsetModified with map level changes"""
192     self.failIf(self.session.WasModified())
193     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
194     self.map.SetProjection(proj)
195     self.assert_(self.session.WasModified())
196     self.session.UnsetModified()
197     self.failIf(self.session.WasModified())
198    
199     def test_unset_modified_layer(self):
200     """Test Session.UnsetModified with layer level changes"""
201     self.failIf(self.session.WasModified())
202 jonathan 482 self.poly_layer.GetClassification().SetDefaultLineWidth(3)
203 bh 334 self.assert_(self.session.WasModified())
204     self.session.UnsetModified()
205     self.failIf(self.session.WasModified())
206 jonathan 584 self.check_messages([(self.poly_layer, LAYER_CHANGED),
207 bh 334 (self.session, CHANGED),
208     (CHANGED,)])
209    
210    
211     if __name__ == "__main__":
212     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