/[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 1831 by bh, Thu Oct 16 16:36:11 2003 UTC revision 2698 by bernhard, Mon Sep 18 00:56:26 2006 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002, 2003 by Intevation GmbH  # Copyright (c) 2002, 2003, 2006 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4    # Bernhard Reiter <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 14  __version__ = "$Revision$" Line 15  __version__ = "$Revision$"
15  # $Id$  # $Id$
16    
17  import unittest  import unittest
18    import locale
19  import os  import os
20    
21    import localessupport
22  import xmlsupport  import xmlsupport
23  import support  import support
24  support.initthuban()  support.initthuban()
# Line 55  class TestProjection(unittest.TestCase, Line 58  class TestProjection(unittest.TestCase,
58                                   (3620891.3077618643, 0.0,                                   (3620891.3077618643, 0.0,
59                                    3875381.8535437919, 252962.10480170773),                                    3875381.8535437919, 252962.10480170773),
60                                   epsilon = 1e-5)                                   epsilon = 1e-5)
61            self.assertFloatSeqEqual(proj.InverseBBox((3620891.3077618643, 0.0,
62                                                       3875381.8535437919,
63                                                       252962.10480170773)),
64                                     (-0.018341599754143501, 0.0,
65                                      2.017992992681688, 2.0377390677846736),
66                                     epsilon = 1e-5)
67    
68          # GetName()          # GetName()
69          self.assertEquals(proj.GetName(), _("Unknown"))          self.assertEquals(proj.GetName(), _("Unknown"))
# Line 80  class TestProjection(unittest.TestCase, Line 89  class TestProjection(unittest.TestCase,
89          self.assertEquals(proj.GetParameter("south"), "south")          self.assertEquals(proj.GetParameter("south"), "south")
90    
91      def test_get_projection_units_geo(self):      def test_get_projection_units_geo(self):
92          """Test Projection.GetProjectedUnits() for geographic projection"""          """Test Projection.GetProjectedUnits() for geographic projection.
93            Test for the alias 'longlat' as well.
94            """
95          proj = Projection(["proj=latlong", "to_meter=0.017453292519943295",          proj = Projection(["proj=latlong", "to_meter=0.017453292519943295",
96                             "ellps=clrk66"])                             "ellps=clrk66"])
97          self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES)          self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES)
98            proj = Projection(["proj=longlat", "to_meter=0.017453292519943295",
99                               "ellps=clrk66"])
100            self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES)
101    
102        def test_lc_numeric_robustness(self):
103            """Test if an LC_NUMERIC local with comma as decimal_point will work.
104    
105            Some versions of proj are not robust against this.
106            Starting with Python 2.4 there is a different behaviour when
107            calling C extensions and now they will see changes locales settings
108            which might tickle the bug in proj.
109            """
110            params = ["proj=latlong", "to_meter=0.01745", "ellps=clrk66"]
111    
112            oldlocale = localessupport.setdecimalcommalocale()
113            if oldlocale == None:
114                raise support.SkipTest(
115                        "No locale with comma as decimal_point found.")
116    
117            proj = Projection(params)
118            #print proj.work_around_broken_proj
119            result1 =  proj.Forward(1.2,3.2)
120    
121            locale.setlocale(locale.LC_NUMERIC, "C")
122            proj = Projection(params)
123            result2= proj.Forward(1.2,3.2)
124    
125            locale.setlocale(locale.LC_NUMERIC, oldlocale)
126            self.assertFloatSeqEqual(result1, result2, epsilon = 1e-5 )
127    
128      def test_get_projection_units_normal(self):      def test_get_projection_units_normal(self):
129          """Test Projection.GetProjectedUnits() for normal projection"""          """Test Projection.GetProjectedUnits() for normal projection"""
# Line 224  class ProjFileReadTests(ProjFileTest): Line 264  class ProjFileReadTests(ProjFileTest):
264          As currently written this only works on unix-like systems and          As currently written this only works on unix-like systems and
265          not e.g. on MS Windows.          not e.g. on MS Windows.
266          """          """
267            if os.name != "posix":
268                raise support.SkipTest("Test only works on posix systems")
269          filename = self.filename()          filename = self.filename()
270          file = open(filename, "w")          file = open(filename, "w")
271          file.close()          file.close()
# Line 239  class ProjFileReadTests(ProjFileTest): Line 281  class ProjFileReadTests(ProjFileTest):
281          self.assertRaises(SAXParseException, resource.read_proj_file, filename)          self.assertRaises(SAXParseException, resource.read_proj_file, filename)
282    
283      def test_get_system_proj_file(self):      def test_get_system_proj_file(self):
284          """Test resource.get_system_proj_file()          """Test resource.get_system_proj_file(DEFAULT_PROJ_FILE)
285    
286          This is primarily to test whether the system proj file contains          This is primarily to test whether the system proj file contains
287          invalid projection paramers and whether the proj file is not          invalid projection paramers and whether the proj file is not
288          empty          empty
289          """          """
290          projfile, warnings = resource.get_system_proj_file()          projfile, warnings\
291                      = resource.get_system_proj_file(resource.DEFAULT_PROJ_FILE)
292          self.assertEquals(warnings, [])          self.assertEquals(warnings, [])
293          self.assert_(len(projfile.GetProjections()) > 0)          self.assert_(len(projfile.GetProjections()) > 0)
294    
295          # see whether it got cached and we get the same projfile object          # see whether it got cached and we get the same projfile object
296          # when we read the file again          # when we read the file again
297          projfile2, warnings = resource.get_system_proj_file()          projfile2, warnings \
298                       = resource.get_system_proj_file(resource.DEFAULT_PROJ_FILE)
299          self.assert_(projfile is projfile2)          self.assert_(projfile is projfile2)
300    
301    

Legend:
Removed from v.1831  
changed lines
  Added in v.2698

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26