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

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

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

revision 1818 by bh, Mon Oct 13 15:54:14 2003 UTC revision 1825 by bh, Tue Oct 14 15:21:17 2003 UTC
# Line 23  support.initthuban() Line 23  support.initthuban()
23  from Thuban import _  from Thuban import _
24  from Thuban.Model.proj import Projection, ProjFile, \  from Thuban.Model.proj import Projection, ProjFile, \
25       PROJ_UNITS_METERS, PROJ_UNITS_DEGREES       PROJ_UNITS_METERS, PROJ_UNITS_DEGREES
26    from Thuban.Model.messages import PROJECTION_ADDED, PROJECTION_REMOVED, \
27         PROJECTION_REPLACED
28  import Thuban.Model.resource as resource  import Thuban.Model.resource as resource
29    
30  from xmlsupport import sax_eventlist  from xmlsupport import sax_eventlist
# Line 114  class TestProjection(unittest.TestCase, Line 115  class TestProjection(unittest.TestCase,
115          self.assertEquals(proj.EPSGCode(), "42")          self.assertEquals(proj.EPSGCode(), "42")
116    
117    
 class ProjFileTest(unittest.TestCase, support.FileTestMixin):  
118    
119      """Base class for the proj file tests"""  class TestProjFileSimple:
120    
121      def filename(self):      def test_init(self):
122          """Return the filename for the test"""          """Test ProjFile coinstructor"""
123          return self.temp_file_name(self.id() + ".proj")          proj_file = ProjFile("some_filename")
124            self.assertEquals(proj_file.GetFilename(), "some_filename")
125            self.assertEquals(len(proj_file.GetProjections()), 0)
126    
127        def test_set_filename(self):
128            """Test ProjFile.SetFilename()"""
129            proj_file = ProjFile("some_filename")
130            proj.SetFilename("other_name")
131            self.assertEquals(proj_file.GetFilename(), "other_name")
132    
133    
134  class TestProjFile(ProjFileTest, xmlsupport.ValidationTest):  class TestProjFile(unittest.TestCase, support.SubscriberMixin):
135    
136      """Test cases for reading and writing projection files.      """Test cases for reading and writing projection files.
137      """      """
138    
139      def test(self):      def setUp(self):
140          """Test ProjFile"""          self.clear_messages()
141            self.proj0 = Projection(["proj=tmerc", "ellps=clrk66"])
142            self.proj1 = Projection(["proj=utm", "ellps=clrk66"])
143            self.proj2 = Projection(["proj=lcc", "ellps=clrk66",
144                                     "lat_1=0", "lat_2=20"])
145            self.proj_file = ProjFile("some_filename")
146            for msg in [PROJECTION_ADDED, PROJECTION_REMOVED, PROJECTION_REPLACED]:
147                self.proj_file.Subscribe(msg, self.subscribe_with_params, msg)
148    
149        def test_add_remove(self):
150            """Test ProjFile.Add() and ProjFile.Remove()"""
151            self.proj_file.Add(self.proj0)
152            self.proj_file.Add(self.proj1)
153            self.assertEquals(self.proj_file.GetProjections(),
154                              [self.proj0, self.proj1])
155            self.check_messages([(self.proj0, PROJECTION_ADDED),
156                                 (self.proj1, PROJECTION_ADDED)])
157            self.clear_messages()
158    
159            self.proj_file.Remove(self.proj0)
160            self.assertEquals(self.proj_file.GetProjections(), [self.proj1])
161            self.check_messages([(self.proj0, PROJECTION_REMOVED)])
162    
163        def test_remove_non_existing(self):
164            """Test ProjFile.Remove(<proj not in projfile>)"""
165            self.assertRaises(ValueError, self.proj_file.Remove, self.proj0)
166            # Nothing happened, so no messages should have been sent
167            self.check_messages([])
168    
169        def test_replace(self):
170            """Test ProjFile.Replace()"""
171            self.proj_file.Add(self.proj0)
172            self.proj_file.Add(self.proj1)
173            self.clear_messages()
174    
175            # Replace()
176            self.proj_file.Replace(self.proj0, self.proj2)
177            self.assertEquals(self.proj_file.GetProjections(),
178                              [self.proj2, self.proj1])
179            self.check_messages([(self.proj0, self.proj2, PROJECTION_REPLACED)])
180    
181        def test_replace_non_existing(self):
182            """Test ProjFile.Replace(<proj not in projfile>, <some proj>)"""
183            self.proj_file.Add(self.proj0)
184            self.proj_file.Add(self.proj1)
185            self.clear_messages()
186            self.assertRaises(ValueError,
187                              self.proj_file.Replace, self.proj2, self.proj0)
188            # All projections should still be there
189            self.assertEquals(self.proj_file.GetProjections(),
190                              [self.proj0, self.proj1])
191            # Nothing happened, so no messages should have been sent
192            self.check_messages([])
193    
         proj0 = Projection(["proj=tmerc", "ellps=clrk66"])  
         proj1 = Projection(["proj=utm", "ellps=clrk66"])  
         proj2 = Projection(["proj=lcc", "ellps=clrk66",  
                             "lat_1=0", "lat_2=20"])  
   
         eq = self.assertEquals  
   
   
         #  
         # __init__()  
         # GetFilename()  
         # SetFilename()  
         #  
         for name in ["", "hello_world"]:  
             projFile = ProjFile(name)  
             eq(projFile.GetFilename(), name)  
   
             projFile.SetFilename("XXX")  
             projFile.SetFilename(name)  
             eq(projFile.GetFilename(), name)  
   
         # initial number of projections should be 0  
         eq(len(projFile.GetProjections()), 0)  
   
         #  
         # Add()  
         # Remove()  
         #  
         projFile.Add(proj0)  
         eq(len(projFile.GetProjections()), 1)  
         projFile.Remove(proj0)  
         eq(len(projFile.GetProjections()), 0)  
   
         # try to remove something that doesn't exist  
         self.assertRaises(ValueError, projFile.Remove, None)  
         self.assertRaises(ValueError, projFile.Remove, proj0)  
   
         projFile.Add(proj0)  
         projFile.Add(proj1)  
         projFile.Add(proj2)  
         eq(len(projFile.GetProjections()), 3)  
   
         # GetProjections() -- tests order  
         projs = projFile.GetProjections()  
         eq(projs[0], proj0)  
         eq(projs[1], proj1)  
         eq(projs[2], proj2)  
194    
195          projFile.Remove(proj2)  class ProjFileTest(unittest.TestCase, support.FileTestMixin,
196          projFile.Remove(proj1)                     xmlsupport.ValidationTest):
197    
198          # Replace()      """Base class for the proj file tests that read or write files"""
199          projFile.Replace(proj0, proj1)  
200          projs = projFile.GetProjections()      def filename(self):
201          eq(projs[0], proj1)          """Return the filename for the test"""
202            return self.temp_file_name(self.id() + ".proj")
203          # replace a non-existent projection  
204          self.assertRaises(ValueError, projFile.Replace, None, proj2)  
205          self.assertRaises(ValueError, projFile.Replace, proj0, proj2)  class ProjFileReadTests(ProjFileTest):
206    
207        """Test read ProjFile objects from files"""
208    
209      def test_read_non_existing_file(self):      def test_read_non_existing_file(self):
210          """Test read_proj_file with non-existing file"""          """Test read_proj_file with non-existing file"""
# Line 229  class TestProjFile(ProjFileTest, xmlsupp Line 244  class TestProjFile(ProjFileTest, xmlsupp
244          self.assert_(len(projfile.GetProjections()) > 0)          self.assert_(len(projfile.GetProjections()) > 0)
245    
246    
247  class WriteProjFileTests(ProjFileTest, xmlsupport.ValidationTest):  class WriteProjFileTests(ProjFileTest):
248    
249      """Test cases for writing proj files"""      """Test cases for writing proj files"""
250    

Legend:
Removed from v.1818  
changed lines
  Added in v.1825

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26