133 |
|
|
134 |
class TestProjFile(unittest.TestCase, support.SubscriberMixin): |
class TestProjFile(unittest.TestCase, support.SubscriberMixin): |
135 |
|
|
136 |
"""Test cases for reading and writing projection files. |
"""Test cases for ProjFile objects""" |
|
""" |
|
137 |
|
|
138 |
def setUp(self): |
def setUp(self): |
139 |
self.clear_messages() |
self.clear_messages() |
207 |
|
|
208 |
class ProjFileReadTests(ProjFileTest): |
class ProjFileReadTests(ProjFileTest): |
209 |
|
|
210 |
"""Test read ProjFile objects from files""" |
"""Test read ProjFile objects from files |
211 |
|
|
212 |
|
The files only cover error handling and the system projection file. |
213 |
|
""" |
214 |
|
|
215 |
def test_read_non_existing_file(self): |
def test_read_non_existing_file(self): |
216 |
"""Test read_proj_file with non-existing file""" |
"""Test read_proj_file with non-existing file""" |
249 |
self.assertEquals(warnings, []) |
self.assertEquals(warnings, []) |
250 |
self.assert_(len(projfile.GetProjections()) > 0) |
self.assert_(len(projfile.GetProjections()) > 0) |
251 |
|
|
252 |
|
# see whether it got cached and we get the same projfile object |
253 |
|
# when we read the file again |
254 |
|
projfile2, warnings = resource.get_system_proj_file() |
255 |
|
self.assert_(projfile is projfile2) |
256 |
|
|
257 |
|
|
258 |
class WriteProjFileTests(ProjFileTest): |
class WriteProjFileTests(ProjFileTest): |
259 |
|
|
322 |
self.doTestWrite(pf, file_contents) |
self.doTestWrite(pf, file_contents) |
323 |
|
|
324 |
|
|
325 |
class TestLoadingProjFile(support.FileLoadTestCase): |
class ProjFileLoadTestCase(support.FileLoadTestCase): |
326 |
|
|
327 |
|
"""Base class for the test cases that read specific test files""" |
328 |
|
|
329 |
file_extension = ".proj" |
file_extension = ".proj" |
330 |
|
|
331 |
|
def tearDown(self): |
332 |
|
"""Clear the cache explicitly""" |
333 |
|
resource.clear_proj_file_cache() |
334 |
|
|
335 |
|
|
336 |
|
class TestLoadingProjFile(ProjFileLoadTestCase): |
337 |
|
|
338 |
file_contents = '''\ |
file_contents = '''\ |
339 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
340 |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
386 |
"proj=tmerc", "units=m", |
"proj=tmerc", "units=m", |
387 |
"x_0=400000.000", "y_0=0.000"]) |
"x_0=400000.000", "y_0=0.000"]) |
388 |
|
|
389 |
|
def test_caching(self): |
390 |
|
# test whether the projfile cache works |
391 |
|
projfile, warnings = resource.read_proj_file(self.filename()) |
392 |
|
projfile2, warnings = resource.read_proj_file(self.filename()) |
393 |
|
|
394 |
class TestLoadingProjFileWithEmptyProjectionlist(support.FileLoadTestCase): |
# Both projfiles should be the same object |
395 |
|
self.assert_(projfile2 is projfile) |
396 |
|
|
397 |
|
# If we clear the cache we should get a new one. |
398 |
|
resource.clear_proj_file_cache() |
399 |
|
projfile3, warnings = resource.read_proj_file(self.filename()) |
400 |
|
self.assert_(projfile3 is not projfile) |
401 |
|
|
402 |
|
|
403 |
|
class TestLoadingProjFileWithEmptyProjectionlist(ProjFileLoadTestCase): |
404 |
|
|
|
file_extension = ".proj" |
|
405 |
file_contents = '''\ |
file_contents = '''\ |
406 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
407 |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
418 |
self.assertEquals(len(projfile.GetProjections()), 0) |
self.assertEquals(len(projfile.GetProjections()), 0) |
419 |
|
|
420 |
|
|
421 |
class TestProjFileWithInvalidParameters(unittest.TestCase, |
class TestProjFileWithInvalidParameters(ProjFileLoadTestCase): |
|
support.FileLoadTestCase): |
|
422 |
|
|
|
file_extension = ".proj" |
|
423 |
file_contents = '''\ |
file_contents = '''\ |
424 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
425 |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |