/[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 1827 by bh, Tue Oct 14 16:04:35 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 tearDown(self):
150            self.clear_messages()
151            self.proj_file.Destroy()
152    
153        def test_add_remove(self):
154            """Test ProjFile.Add() and ProjFile.Remove()"""
155            self.proj_file.Add(self.proj0)
156            self.proj_file.Add(self.proj1)
157            self.assertEquals(self.proj_file.GetProjections(),
158                              [self.proj0, self.proj1])
159            self.check_messages([(self.proj0, PROJECTION_ADDED),
160                                 (self.proj1, PROJECTION_ADDED)])
161            self.clear_messages()
162    
163            self.proj_file.Remove(self.proj0)
164            self.assertEquals(self.proj_file.GetProjections(), [self.proj1])
165            self.check_messages([(self.proj0, PROJECTION_REMOVED)])
166    
167        def test_remove_non_existing(self):
168            """Test ProjFile.Remove(<proj not in projfile>)"""
169            self.assertRaises(ValueError, self.proj_file.Remove, self.proj0)
170            # Nothing happened, so no messages should have been sent
171            self.check_messages([])
172    
173        def test_replace(self):
174            """Test ProjFile.Replace()"""
175            self.proj_file.Add(self.proj0)
176            self.proj_file.Add(self.proj1)
177            self.clear_messages()
178    
179          proj0 = Projection(["proj=tmerc", "ellps=clrk66"])          # Replace()
180          proj1 = Projection(["proj=utm", "ellps=clrk66"])          self.proj_file.Replace(self.proj0, self.proj2)
181          proj2 = Projection(["proj=lcc", "ellps=clrk66",          self.assertEquals(self.proj_file.GetProjections(),
182                              "lat_1=0", "lat_2=20"])                            [self.proj2, self.proj1])
183            self.check_messages([(self.proj0, self.proj2, PROJECTION_REPLACED)])
184          eq = self.assertEquals  
185        def test_replace_non_existing(self):
186            """Test ProjFile.Replace(<proj not in projfile>, <some proj>)"""
187          #          self.proj_file.Add(self.proj0)
188          # __init__()          self.proj_file.Add(self.proj1)
189          # GetFilename()          self.clear_messages()
190          # SetFilename()          self.assertRaises(ValueError,
191          #                            self.proj_file.Replace, self.proj2, self.proj0)
192          for name in ["", "hello_world"]:          # All projections should still be there
193              projFile = ProjFile(name)          self.assertEquals(self.proj_file.GetProjections(),
194              eq(projFile.GetFilename(), name)                            [self.proj0, self.proj1])
195            # Nothing happened, so no messages should have been sent
196              projFile.SetFilename("XXX")          self.check_messages([])
             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)  
197    
         projFile.Remove(proj2)  
         projFile.Remove(proj1)  
198    
199          # Replace()  class ProjFileTest(unittest.TestCase, support.FileTestMixin,
200          projFile.Replace(proj0, proj1)                     xmlsupport.ValidationTest):
201          projs = projFile.GetProjections()  
202          eq(projs[0], proj1)      """Base class for the proj file tests that read or write files"""
203    
204          # replace a non-existent projection      def filename(self):
205          self.assertRaises(ValueError, projFile.Replace, None, proj2)          """Return the filename for the test"""
206          self.assertRaises(ValueError, projFile.Replace, proj0, proj2)          return self.temp_file_name(self.id() + ".proj")
207    
208    
209    class ProjFileReadTests(ProjFileTest):
210    
211        """Test read ProjFile objects from files"""
212    
213      def test_read_non_existing_file(self):      def test_read_non_existing_file(self):
214          """Test read_proj_file with non-existing file"""          """Test read_proj_file with non-existing file"""
# Line 229  class TestProjFile(ProjFileTest, xmlsupp Line 248  class TestProjFile(ProjFileTest, xmlsupp
248          self.assert_(len(projfile.GetProjections()) > 0)          self.assert_(len(projfile.GetProjections()) > 0)
249    
250    
251  class WriteProjFileTests(ProjFileTest, xmlsupport.ValidationTest):  class WriteProjFileTests(ProjFileTest):
252    
253      """Test cases for writing proj files"""      """Test cases for writing proj files"""
254    
# Line 413  class TestProjFileWithInvalidParameters( Line 432  class TestProjFileWithInvalidParameters(
432    
433    
434  if __name__ == "__main__":  if __name__ == "__main__":
435      unittest.main()      support.run_tests()

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26