/[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 1787 by bh, Wed Oct 8 10:39:18 2003 UTC revision 1813 by bh, Mon Oct 13 14:01:37 2003 UTC
# Line 21  import support Line 21  import support
21  support.initthuban()  support.initthuban()
22    
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
26    
27  import Thuban.Model.resource as resource  import Thuban.Model.resource as resource
28    
# Line 70  class TestProjection(unittest.TestCase, Line 71  class TestProjection(unittest.TestCase,
71          proj = Projection(params, "MyName")          proj = Projection(params, "MyName")
72          self.assertEquals(proj.GetName(), "MyName")          self.assertEquals(proj.GetName(), "MyName")
73    
74        def test_get_parameter_without_equals_sign(self):
75            """Test Projection.GetParameter() for a parameter without '=' sign"""
76            proj = Projection(["proj=utm", "zone=34", "south", "ellps=clrk66"])
77            # The Projection class pretends that for parameters specified
78            # without a value the value is the same as the parameter name.
79            self.assertEquals(proj.GetParameter("south"), "south")
80    
81        def test_get_projection_units_geo(self):
82            """Test Projection.GetProjectedUnits() for geographic projection"""
83            proj = Projection(["proj=latlong", "to_meter=0.017453292519943295",
84                               "ellps=clrk66"])
85            self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES)
86    
87        def test_get_projection_units_normal(self):
88            """Test Projection.GetProjectedUnits() for normal projection"""
89            proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
90            self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_METERS)
91    
92    
93  sample_projfile = '''\  sample_projfile = '''\
94  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
# Line 120  sample_projfile2 = '''\ Line 139  sample_projfile2 = '''\
139    
140  sample_projfile_data2 = []  sample_projfile_data2 = []
141    
142  class TestProjFile(unittest.TestCase, support.FileTestMixin,  class ProjFileTest(unittest.TestCase, support.FileTestMixin):
143                     xmlsupport.ValidationTest):  
144        """Base class for the proj file tests"""
145    
146        def filename(self):
147            """Return the filename for the test"""
148            return self.temp_file_name(self.id() + ".proj")
149    
150    
151    class TestProjFile(ProjFileTest, xmlsupport.ValidationTest):
152    
153      """Test cases for reading and writing projection files.      """Test cases for reading and writing projection files.
154      """      """
155    
     def compare_xml(self, xml1, xml2):  
         self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2))  
   
156      def test(self):      def test(self):
157          """Test ProjFile"""          """Test ProjFile"""
158    
# Line 194  class TestProjFile(unittest.TestCase, su Line 218  class TestProjFile(unittest.TestCase, su
218    
219      def testRead(self):      def testRead(self):
220          """Test read_proj_file"""          """Test read_proj_file"""
   
221          self.doTestRead(sample_projfile_data, sample_projfile)          self.doTestRead(sample_projfile_data, sample_projfile)
222          self.doTestRead(sample_projfile_data2, sample_projfile2)          self.doTestRead(sample_projfile_data2, sample_projfile2)
223    
224          #      def test_read_non_existing_file(self):
225          # file doesn't exist          """Test read_proj_file with non-existing file"""
         #  
226          self.assertRaises(IOError,          self.assertRaises(IOError,
227              resource.read_proj_file, self.temp_file_name("nonexistent.proj"))                            resource.read_proj_file,
228                              self.temp_file_name("nonexistent.proj"))
229    
230          #      def test_read_unreadable_file(self):
231          # file isn't readable          """Test read_proj_file with unreadable file
232          #  
233          filename = self.temp_file_name("projfile.proj")          As currently written this only works on unix-like systems and
234            not e.g. on MS Windows.
235            """
236            filename = self.filename()
237          file = open(filename, "w")          file = open(filename, "w")
238          file.close()          file.close()
239          os.chmod(filename, 0200) # write-only          os.chmod(filename, 0200) # write-only
240          self.assertRaises(IOError, resource.read_proj_file, filename)          self.assertRaises(IOError, resource.read_proj_file, filename)
241          os.chmod(filename, 0600) # read/write so we reuse the file          os.chmod(filename, 0600) # read/write so we reuse the file
242    
243          #      def test_read_empty_file(self):
244          # file has invalid XML (or none at all)          """Test read_proj_file with empty file"""
245          #          filename = self.filename()
         filename = self.temp_file_name("projfile.proj")  
246          file = open(filename, "w")          file = open(filename, "w")
247          file.close()          file.close()
248    
249          self.assertRaises(SAXParseException, resource.read_proj_file, filename)          self.assertRaises(SAXParseException, resource.read_proj_file, filename)
250    
     def testWrite(self):  
         """Test write_proj_file"""  
   
         self.doTestWrite(sample_projfile_data, sample_projfile)  
         self.doTestWrite(sample_projfile_data2, sample_projfile2)  
   
     def doTestWrite(self, data, expected):  
   
         filename = self.temp_file_name("projfile.proj")  
   
         pf = ProjFile(filename)  
         for proj in data:  
             pf.Add(Projection(proj[1], proj[0]))  
   
         resource.write_proj_file(pf)  
   
         file = open(filename)  
         written_contents = file.read()  
         file.close()  
         self.compare_xml(written_contents, expected)  
         self.validate_data(written_contents)  
         self.validate_data(expected)  
   
251      def doTestRead(self, data, input):      def doTestRead(self, data, input):
252    
253          filename = self.temp_file_name("projfile.proj")          filename = self.filename()
254          file = open(filename, "w")          file = open(filename, "w")
255          file.write(input)          file.write(input)
256          file.close()          file.close()
# Line 277  class TestProjFile(unittest.TestCase, su Line 279  class TestProjFile(unittest.TestCase, su
279          self.assert_(len(projfile.GetProjections()) > 0)          self.assert_(len(projfile.GetProjections()) > 0)
280    
281    
282    class WriteProjFileTests(ProjFileTest, xmlsupport.ValidationTest):
283    
284        """Test cases for writing proj files"""
285    
286        def compare_xml(self, xml1, xml2):
287            self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2))
288    
289        def doTestWrite(self, data, expected):
290            filename = self.filename()
291    
292            pf = ProjFile(filename)
293            for proj in data:
294                pf.Add(Projection(proj[1], proj[0]))
295    
296            resource.write_proj_file(pf)
297    
298            file = open(filename)
299            written_contents = file.read()
300            file.close()
301            self.compare_xml(written_contents, expected)
302            self.validate_data(written_contents)
303            self.validate_data(expected)
304    
305        def test_write(self):
306            """Test write_proj_file"""
307            self.doTestWrite(sample_projfile_data, sample_projfile)
308    
309        def test_write_empty_file(self):
310            """Test write empty ProjFile"""
311            self.doTestWrite(sample_projfile_data2, sample_projfile2)
312    
313    
314  class TestProjFileWithInvalidParameters(unittest.TestCase,  class TestProjFileWithInvalidParameters(unittest.TestCase,
315                                          support.FileLoadTestCase):                                          support.FileLoadTestCase):
316    
# Line 319  class TestProjFileWithInvalidParameters( Line 353  class TestProjFileWithInvalidParameters(
353                          ' invalid UTM zone number'])                          ' invalid UTM zone number'])
354    
355    
   
356  if __name__ == "__main__":  if __name__ == "__main__":
357      unittest.main()      unittest.main()

Legend:
Removed from v.1787  
changed lines
  Added in v.1813

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26