21 |
import xml.sax.handler |
import xml.sax.handler |
22 |
from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException |
from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException |
23 |
|
|
24 |
|
import xmlsupport |
25 |
|
|
26 |
import support |
import support |
27 |
support.initthuban() |
support.initthuban() |
28 |
|
|
96 |
eq(writer.encode('&"\'<>'), "&"'<>") |
eq(writer.encode('&"\'<>'), "&"'<>") |
97 |
eq(writer.encode(unicode('&"\'<>')), "&"'<>") |
eq(writer.encode(unicode('&"\'<>')), "&"'<>") |
98 |
|
|
99 |
class SaveSessionTest(unittest.TestCase, support.FileTestMixin): |
class SaveSessionTest(unittest.TestCase, support.FileTestMixin, |
100 |
|
xmlsupport.ValidationTest): |
101 |
|
|
102 |
def compare_xml(self, xml1, xml2): |
def compare_xml(self, xml1, xml2): |
103 |
self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2)) |
self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2)) |
117 |
'<!DOCTYPE session SYSTEM "thuban.dtd">\n' |
'<!DOCTYPE session SYSTEM "thuban.dtd">\n' |
118 |
'<session title="empty session">\n</session>\n') |
'<session title="empty session">\n</session>\n') |
119 |
|
|
120 |
|
self.validate_data(written_contents) |
121 |
|
|
122 |
def testSingleLayer(self): |
def testSingleLayer(self): |
123 |
"""Save a session with a single map with a single layer""" |
"""Save a session with a single map with a single layer""" |
124 |
# deliberately put an apersand in the title :) |
# deliberately put an apersand in the title :) |
161 |
#print expected_contents |
#print expected_contents |
162 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
163 |
|
|
164 |
|
self.validate_data(written_contents) |
165 |
|
|
166 |
layer.SetVisible(False) |
layer.SetVisible(False) |
167 |
save_session(session, filename) |
save_session(session, filename) |
168 |
|
|
177 |
#print "********************************************" |
#print "********************************************" |
178 |
#print expected_contents |
#print expected_contents |
179 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
180 |
|
self.validate_data(written_contents) |
181 |
|
|
182 |
session.Destroy() |
session.Destroy() |
183 |
|
|
226 |
#print expected_contents |
#print expected_contents |
227 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
228 |
|
|
229 |
|
self.validate_data(written_contents) |
230 |
|
|
231 |
def testRasterLayer(self): |
def testRasterLayer(self): |
232 |
# deliberately put an apersand in the title :) |
# deliberately put an apersand in the title :) |
233 |
session = Session("single map&layer") |
session = Session("single map&layer") |
238 |
os.pardir, "Data", "iceland", "island.tif") |
os.pardir, "Data", "iceland", "island.tif") |
239 |
layer = RasterLayer("My RasterLayer", imgfile) |
layer = RasterLayer("My RasterLayer", imgfile) |
240 |
map.AddLayer(layer) |
map.AddLayer(layer) |
241 |
|
|
242 |
filename = self.temp_file_name("save_singlemap.thuban") |
filename = self.temp_file_name("save_singlemap.thuban") |
243 |
save_session(session, filename) |
save_session(session, filename) |
244 |
session.Destroy() |
session.Destroy() |
245 |
|
|
246 |
file = open(filename) |
file = open(filename) |
247 |
written_contents = file.read() |
written_contents = file.read() |
248 |
file.close() |
file.close() |
262 |
#print expected_contents |
#print expected_contents |
263 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
264 |
|
|
265 |
|
self.validate_data(written_contents) |
266 |
|
|
267 |
def testClassifiedLayer(self): |
def testClassifiedLayer(self): |
268 |
"""Save a session with a single map with a single layer |
"""Save a session with a single map with a single layer |
269 |
with a classificaton. |
with a classificaton. |
335 |
</classification> |
</classification> |
336 |
</layer> |
</layer> |
337 |
</map> |
</map> |
338 |
</session>''' |
</session>''' |
339 |
|
|
340 |
expected_contents = expected_template % \ |
expected_contents = expected_template % \ |
341 |
(os.path.join("..", "..", "Data", "iceland", "political.shp"), |
(os.path.join("..", "..", "Data", "iceland", "political.shp"), |
342 |
"true") |
"true") |
346 |
#print expected_contents |
#print expected_contents |
347 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
348 |
|
|
349 |
|
self.validate_data(written_contents) |
350 |
|
|
351 |
session.Destroy() |
session.Destroy() |
352 |
|
|
353 |
|
|