80 |
self.assertEquals(proj.GetParameter("south"), "south") |
self.assertEquals(proj.GetParameter("south"), "south") |
81 |
|
|
82 |
def test_get_projection_units_geo(self): |
def test_get_projection_units_geo(self): |
83 |
"""Test Projection.GetProjectedUnits() for geographic projection""" |
"""Test Projection.GetProjectedUnits() for geographic projection. |
84 |
|
Test for the alias 'longlat' as well. |
85 |
|
""" |
86 |
proj = Projection(["proj=latlong", "to_meter=0.017453292519943295", |
proj = Projection(["proj=latlong", "to_meter=0.017453292519943295", |
87 |
"ellps=clrk66"]) |
"ellps=clrk66"]) |
88 |
self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES) |
self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES) |
89 |
|
proj = Projection(["proj=longlat", "to_meter=0.017453292519943295", |
90 |
|
"ellps=clrk66"]) |
91 |
|
self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES) |
92 |
|
|
93 |
def test_get_projection_units_normal(self): |
def test_get_projection_units_normal(self): |
94 |
"""Test Projection.GetProjectedUnits() for normal projection""" |
"""Test Projection.GetProjectedUnits() for normal projection""" |
138 |
|
|
139 |
class TestProjFile(unittest.TestCase, support.SubscriberMixin): |
class TestProjFile(unittest.TestCase, support.SubscriberMixin): |
140 |
|
|
141 |
"""Test cases for reading and writing projection files. |
"""Test cases for ProjFile objects""" |
|
""" |
|
142 |
|
|
143 |
def setUp(self): |
def setUp(self): |
144 |
self.clear_messages() |
self.clear_messages() |
150 |
for msg in [PROJECTION_ADDED, PROJECTION_REMOVED, PROJECTION_REPLACED]: |
for msg in [PROJECTION_ADDED, PROJECTION_REMOVED, PROJECTION_REPLACED]: |
151 |
self.proj_file.Subscribe(msg, self.subscribe_with_params, msg) |
self.proj_file.Subscribe(msg, self.subscribe_with_params, msg) |
152 |
|
|
153 |
|
def tearDown(self): |
154 |
|
self.clear_messages() |
155 |
|
self.proj_file.Destroy() |
156 |
|
|
157 |
def test_add_remove(self): |
def test_add_remove(self): |
158 |
"""Test ProjFile.Add() and ProjFile.Remove()""" |
"""Test ProjFile.Add() and ProjFile.Remove()""" |
159 |
self.proj_file.Add(self.proj0) |
self.proj_file.Add(self.proj0) |
212 |
|
|
213 |
class ProjFileReadTests(ProjFileTest): |
class ProjFileReadTests(ProjFileTest): |
214 |
|
|
215 |
"""Test read ProjFile objects from files""" |
"""Test read ProjFile objects from files |
216 |
|
|
217 |
|
The files only cover error handling and the system projection file. |
218 |
|
""" |
219 |
|
|
220 |
def test_read_non_existing_file(self): |
def test_read_non_existing_file(self): |
221 |
"""Test read_proj_file with non-existing file""" |
"""Test read_proj_file with non-existing file""" |
244 |
self.assertRaises(SAXParseException, resource.read_proj_file, filename) |
self.assertRaises(SAXParseException, resource.read_proj_file, filename) |
245 |
|
|
246 |
def test_get_system_proj_file(self): |
def test_get_system_proj_file(self): |
247 |
"""Test resource.get_system_proj_file() |
"""Test resource.get_system_proj_file(DEFAULT_PROJ_FILE) |
248 |
|
|
249 |
This is primarily to test whether the system proj file contains |
This is primarily to test whether the system proj file contains |
250 |
invalid projection paramers and whether the proj file is not |
invalid projection paramers and whether the proj file is not |
251 |
empty |
empty |
252 |
""" |
""" |
253 |
projfile, warnings = resource.get_system_proj_file() |
projfile, warnings\ |
254 |
|
= resource.get_system_proj_file(resource.DEFAULT_PROJ_FILE) |
255 |
self.assertEquals(warnings, []) |
self.assertEquals(warnings, []) |
256 |
self.assert_(len(projfile.GetProjections()) > 0) |
self.assert_(len(projfile.GetProjections()) > 0) |
257 |
|
|
258 |
|
# see whether it got cached and we get the same projfile object |
259 |
|
# when we read the file again |
260 |
|
projfile2, warnings \ |
261 |
|
= resource.get_system_proj_file(resource.DEFAULT_PROJ_FILE) |
262 |
|
self.assert_(projfile is projfile2) |
263 |
|
|
264 |
|
|
265 |
class WriteProjFileTests(ProjFileTest): |
class WriteProjFileTests(ProjFileTest): |
266 |
|
|
329 |
self.doTestWrite(pf, file_contents) |
self.doTestWrite(pf, file_contents) |
330 |
|
|
331 |
|
|
332 |
class TestLoadingProjFile(support.FileLoadTestCase): |
class ProjFileLoadTestCase(support.FileLoadTestCase): |
333 |
|
|
334 |
|
"""Base class for the test cases that read specific test files""" |
335 |
|
|
336 |
file_extension = ".proj" |
file_extension = ".proj" |
337 |
|
|
338 |
|
def tearDown(self): |
339 |
|
"""Clear the cache explicitly""" |
340 |
|
resource.clear_proj_file_cache() |
341 |
|
|
342 |
|
|
343 |
|
class TestLoadingProjFile(ProjFileLoadTestCase): |
344 |
|
|
345 |
file_contents = '''\ |
file_contents = '''\ |
346 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
347 |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
393 |
"proj=tmerc", "units=m", |
"proj=tmerc", "units=m", |
394 |
"x_0=400000.000", "y_0=0.000"]) |
"x_0=400000.000", "y_0=0.000"]) |
395 |
|
|
396 |
|
def test_caching(self): |
397 |
|
# test whether the projfile cache works |
398 |
|
projfile, warnings = resource.read_proj_file(self.filename()) |
399 |
|
projfile2, warnings = resource.read_proj_file(self.filename()) |
400 |
|
|
401 |
|
# Both projfiles should be the same object |
402 |
|
self.assert_(projfile2 is projfile) |
403 |
|
|
404 |
class TestLoadingProjFileWithEmptyProjectionlist(support.FileLoadTestCase): |
# If we clear the cache we should get a new one. |
405 |
|
resource.clear_proj_file_cache() |
406 |
|
projfile3, warnings = resource.read_proj_file(self.filename()) |
407 |
|
self.assert_(projfile3 is not projfile) |
408 |
|
|
409 |
|
|
410 |
|
class TestLoadingProjFileWithEmptyProjectionlist(ProjFileLoadTestCase): |
411 |
|
|
|
file_extension = ".proj" |
|
412 |
file_contents = '''\ |
file_contents = '''\ |
413 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
414 |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
425 |
self.assertEquals(len(projfile.GetProjections()), 0) |
self.assertEquals(len(projfile.GetProjections()), 0) |
426 |
|
|
427 |
|
|
428 |
class TestProjFileWithInvalidParameters(unittest.TestCase, |
class TestProjFileWithInvalidParameters(ProjFileLoadTestCase): |
|
support.FileLoadTestCase): |
|
429 |
|
|
|
file_extension = ".proj" |
|
430 |
file_contents = '''\ |
file_contents = '''\ |
431 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
432 |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
466 |
|
|
467 |
|
|
468 |
if __name__ == "__main__": |
if __name__ == "__main__": |
469 |
unittest.main() |
support.run_tests() |