1 |
# Copyright (c) 2002 by Intevation GmbH |
# Copyright (c) 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
13 |
# $Source$ |
# $Source$ |
14 |
# $Id$ |
# $Id$ |
15 |
|
|
|
from Thuban import _ |
|
|
|
|
16 |
import unittest |
import unittest |
17 |
import os |
import os |
18 |
|
|
19 |
import support |
import support |
20 |
support.initthuban() |
support.initthuban() |
21 |
|
|
22 |
|
from Thuban import _ |
23 |
from Thuban.Model.proj import Projection, ProjFile |
from Thuban.Model.proj import Projection, ProjFile |
24 |
|
|
25 |
import Thuban.Model.resource as resource |
import Thuban.Model.resource as resource |
26 |
|
|
27 |
from test_save import sax_eventlist |
from xmlsupport import sax_eventlist |
28 |
|
|
29 |
from xml.sax import SAXParseException |
from xml.sax import SAXParseException |
30 |
|
|
132 |
|
|
133 |
proj0 = Projection(["proj=tmerc", "ellps=clrk66"]) |
proj0 = Projection(["proj=tmerc", "ellps=clrk66"]) |
134 |
proj1 = Projection(["proj=utm", "ellps=clrk66"]) |
proj1 = Projection(["proj=utm", "ellps=clrk66"]) |
135 |
proj2 = Projection(["proj=lcc", "ellps=clrk66"]) |
proj2 = Projection(["proj=lcc", "ellps=clrk66", |
136 |
|
"lat_1=0", "lat_2=20"]) |
137 |
|
|
138 |
eq = self.assertEquals |
eq = self.assertEquals |
139 |
|
|
191 |
self.assertRaises(ValueError, projFile.Replace, proj0, proj2) |
self.assertRaises(ValueError, projFile.Replace, proj0, proj2) |
192 |
|
|
193 |
def testRead(self): |
def testRead(self): |
194 |
"""Test ReadProjFile""" |
"""Test read_proj_file""" |
195 |
|
|
196 |
self.doTestRead(sample_projfile_data, sample_projfile) |
self.doTestRead(sample_projfile_data, sample_projfile) |
197 |
self.doTestRead(sample_projfile_data2, sample_projfile2) |
self.doTestRead(sample_projfile_data2, sample_projfile2) |
200 |
# file doesn't exist |
# file doesn't exist |
201 |
# |
# |
202 |
self.assertRaises(IOError, |
self.assertRaises(IOError, |
203 |
resource.ReadProjFile, self.temp_file_name("nonexistent.proj")) |
resource.read_proj_file, self.temp_file_name("nonexistent.proj")) |
204 |
|
|
205 |
# |
# |
206 |
# file isn't readable |
# file isn't readable |
209 |
file = open(filename, "w") |
file = open(filename, "w") |
210 |
file.close() |
file.close() |
211 |
os.chmod(filename, 0200) # write-only |
os.chmod(filename, 0200) # write-only |
212 |
self.assertRaises(IOError, resource.ReadProjFile, filename) |
self.assertRaises(IOError, resource.read_proj_file, filename) |
213 |
os.chmod(filename, 0600) # read/write so we reuse the file |
os.chmod(filename, 0600) # read/write so we reuse the file |
214 |
|
|
215 |
# |
# |
219 |
file = open(filename, "w") |
file = open(filename, "w") |
220 |
file.close() |
file.close() |
221 |
|
|
222 |
self.assertRaises(SAXParseException, resource.ReadProjFile, filename) |
self.assertRaises(SAXParseException, resource.read_proj_file, filename) |
223 |
|
|
224 |
def testWrite(self): |
def testWrite(self): |
225 |
"""Test WriteProjFile""" |
"""Test write_proj_file""" |
226 |
|
|
227 |
self.doTestWrite(sample_projfile_data, sample_projfile) |
self.doTestWrite(sample_projfile_data, sample_projfile) |
228 |
self.doTestWrite(sample_projfile_data2, sample_projfile2) |
self.doTestWrite(sample_projfile_data2, sample_projfile2) |
235 |
for proj in data: |
for proj in data: |
236 |
pf.Add(Projection(proj[1], proj[0])) |
pf.Add(Projection(proj[1], proj[0])) |
237 |
|
|
238 |
resource.WriteProjFile(pf) |
resource.write_proj_file(pf) |
239 |
|
|
240 |
file = open(filename) |
file = open(filename) |
241 |
written_contents = file.read() |
written_contents = file.read() |
249 |
file.write(input) |
file.write(input) |
250 |
file.close() |
file.close() |
251 |
|
|
252 |
pf = resource.ReadProjFile(filename) |
pf = resource.read_proj_file(filename) |
253 |
|
|
254 |
eq = self.assertEquals |
eq = self.assertEquals |
255 |
|
|