/[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 1756 by bh, Fri Sep 26 14:03:51 2003 UTC revision 1811 by bh, Mon Oct 13 13:36:34 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 194  class TestProjFile(unittest.TestCase, su Line 213  class TestProjFile(unittest.TestCase, su
213    
214      def testRead(self):      def testRead(self):
215          """Test read_proj_file"""          """Test read_proj_file"""
   
216          self.doTestRead(sample_projfile_data, sample_projfile)          self.doTestRead(sample_projfile_data, sample_projfile)
217          self.doTestRead(sample_projfile_data2, sample_projfile2)          self.doTestRead(sample_projfile_data2, sample_projfile2)
218    
219          #      def test_read_non_existing_file(self):
220          # file doesn't exist          """Test read_proj_file with non-existing file"""
         #  
221          self.assertRaises(IOError,          self.assertRaises(IOError,
222              resource.read_proj_file, self.temp_file_name("nonexistent.proj"))                            resource.read_proj_file,
223                              self.temp_file_name("nonexistent.proj"))
224    
225          #      def test_read_unreadable_file(self):
226          # file isn't readable          """Test read_proj_file with unreadable file
227          #  
228            As currently written this only works on unix-like systems and
229            not e.g. on MS Windows.
230            """
231          filename = self.temp_file_name("projfile.proj")          filename = self.temp_file_name("projfile.proj")
232          file = open(filename, "w")          file = open(filename, "w")
233          file.close()          file.close()
# Line 214  class TestProjFile(unittest.TestCase, su Line 235  class TestProjFile(unittest.TestCase, su
235          self.assertRaises(IOError, resource.read_proj_file, filename)          self.assertRaises(IOError, resource.read_proj_file, filename)
236          os.chmod(filename, 0600) # read/write so we reuse the file          os.chmod(filename, 0600) # read/write so we reuse the file
237    
238          #      def test_read_empty_file(self):
239          # file has invalid XML (or none at all)          """Test read_proj_file with empty file"""
         #  
240          filename = self.temp_file_name("projfile.proj")          filename = self.temp_file_name("projfile.proj")
241          file = open(filename, "w")          file = open(filename, "w")
242          file.close()          file.close()
# Line 253  class TestProjFile(unittest.TestCase, su Line 273  class TestProjFile(unittest.TestCase, su
273          file.write(input)          file.write(input)
274          file.close()          file.close()
275    
276          pf = resource.read_proj_file(filename)          pf, warnings = resource.read_proj_file(filename)
277            self.assertEquals(warnings, [])
278    
279          eq = self.assertEquals          eq = self.assertEquals
280    
# Line 264  class TestProjFile(unittest.TestCase, su Line 285  class TestProjFile(unittest.TestCase, su
285              for param in proj.GetAllParameters():              for param in proj.GetAllParameters():
286                  self.assert_(param in d[1])                  self.assert_(param in d[1])
287    
288        def test_get_system_proj_file(self):
289            """Test resource.get_system_proj_file()
290    
291            This is primarily to test whether the system proj file contains
292            invalid projection paramers and whether the proj file is not
293            empty
294            """
295            projfile, warnings = resource.get_system_proj_file()
296            self.assertEquals(warnings, [])
297            self.assert_(len(projfile.GetProjections()) > 0)
298    
299    
300    class TestProjFileWithInvalidParameters(unittest.TestCase,
301                                            support.FileLoadTestCase):
302    
303        file_extension = ".proj"
304        file_contents = '''\
305    <?xml version="1.0" encoding="UTF-8"?>
306    <!DOCTYPE projectionlist SYSTEM "projfile.dtd">
307    <projectionlist>
308        <projection name="Universal Transverse Mercator">
309            <parameter value="proj=utm"/>
310            <parameter value="ellps=clrk66"/>
311            <!-- an invalid zone number to trigger the parameter checking
312                 in the proj library -->
313            <parameter value="zone=1000"/>
314        </projection>
315        <projection name="Transverse Mercator">
316            <parameter value="proj=tmerc"/>
317            <parameter value="ellps=clrk66"/>
318            <parameter value="lat_0=90w"/>
319            <parameter value="lon_0=90w"/>
320            <parameter value="k=1"/>
321        </projection>
322    </projectionlist>
323    '''
324    
325        def setUp(self):
326            support.FileLoadTestCase.setUp(self)
327    
328        def test(self):
329            """Test reading a proj file with invalid parameters"""
330            projfile, warnings = resource.read_proj_file(self.filename())
331            projs = projfile.GetProjections()
332            self.assertEquals(len(projs), 1)
333            params = projs[0].GetAllParameters()[:]
334            params.sort()
335            self.assertEquals(params, ['ellps=clrk66', 'k=1', 'lat_0=90w',
336                                       'lon_0=90w', 'proj=tmerc'])
337            self.assertEquals(warnings,
338                           ['Error in projection "Universal Transverse Mercator":'
339                            ' invalid UTM zone number'])
340    
341    
342    
343  if __name__ == "__main__":  if __name__ == "__main__":
344      unittest.main()      unittest.main()

Legend:
Removed from v.1756  
changed lines
  Added in v.1811

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26