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 |
|
|
233 |
As currently written this only works on unix-like systems and |
As currently written this only works on unix-like systems and |
234 |
not e.g. on MS Windows. |
not e.g. on MS Windows. |
235 |
""" |
""" |
236 |
filename = self.temp_file_name("projfile.proj") |
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 |
242 |
|
|
243 |
def test_read_empty_file(self): |
def test_read_empty_file(self): |
244 |
"""Test read_proj_file with empty file""" |
"""Test read_proj_file with empty file""" |
245 |
filename = self.temp_file_name("projfile.proj") |
filename = self.filename() |
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() |
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 |
|
|
353 |
' invalid UTM zone number']) |
' invalid UTM zone number']) |
354 |
|
|
355 |
|
|
|
|
|
356 |
if __name__ == "__main__": |
if __name__ == "__main__": |
357 |
unittest.main() |
unittest.main() |