Parent Directory
|
Revision Log
* Resources/XML/thuban-0.8.dtd: New DTD for the new file format version. * Thuban/Model/save.py (sort_data_stores): New. Make topological sort of the data sources so they can be written with sources that data sources that depend on other data sources come after the sources they depend on. (SessionSaver.__init__): Add idmap instance variable to map from objects to the ids used in the file. (SessionSaver.get_id, SessionSaver.define_id) (SessionSaver.has_id): New. Methods to manage the idmap (SessionSaver.write): Use thuban-0.8.dtd (SessionSaver.write_session): Add a namespace on the session and write out the data sources before the maps. (SessionSaver.write_data_containers): New. Write the data containers. (SessionSaver.write_layer): Layer elements now refer to a shapestore and don't contain filenames anymore. * Thuban/Model/load.py (LoadError): Exception class to raise when errors in the files are discovered (SessionLoader.__init__): Define dispatchers for elements with a thuban-0.8 namespace too. (SessionLoader.check_attrs): New helper method to check and convert attributes (AttrDesc): New. Helper class for SessionLoader.check_attrs (SessionLoader.start_fileshapesource) (SessionLoader.start_derivedshapesource) (SessionLoader.start_filetable, SessionLoader.start_jointable): Handlers for the new elements in the new fileformat (SessionLoader.start_layer): Handle the shapestore attribute in addition to filename. (SessionLoader.start_table, SessionLoader.end_table): Removed. They were never used in the old formats and aren't needed for the new. * Thuban/Model/session.py (Session.DataContainers): New method to return all "data containers", i.e. shapestores and tables * test/xmlsupport.py (SaxEventLister.__init__) (SaxEventLister.startElementNS, sax_eventlist): Add support to normalize IDs. * test/test_xmlsupport.py (TestEventList.test_even_list_id_normalization): New test case for id normalization * test/test_load.py (LoadSessionTest.check_format): Use ID normalization (LoadSessionTest.thubanids, LoadSessionTest.thubanidrefs): New class atrributes used for ID normalization (TestSingleLayer, TestLayerVisibility, TestLabels.test) (TestLayerProjection.test, TestRasterLayer.test): Adapt to new file format (TestJoinedTable): New test for loading sessions with joined tables. (TestLoadError): New. Test whether missing required attributes cause a LoadError. * test/test_save.py (SaveSessionTest.thubanids) (SaveSessionTest.thubanidrefs): New class attributes for ID normalization in .thuban files. (SaveSessionTest.compare_xml): Use id-normalization. (SaveSessionTest.testEmptySession) (SaveSessionTest.testLayerProjection) (SaveSessionTest.testRasterLayer) (SaveSessionTest.testClassifiedLayer): Adapt to new file format. (SaveSessionTest.testLayerProjection): The filename used was the same as for testSingleLayer. Use a different one. (SaveSessionTest.test_dbf_table) (SaveSessionTest.test_joined_table): New test cases for saving the new data sources structures. (TestStoreSort, MockDataStore): Classes to test the sorting of the data stores for writing.
1 | bh | 1245 | # Copyright (C) 2003 by Intevation GmbH |
2 | # Authors: | ||
3 | # Bernhard Herzog <[email protected]> | ||
4 | # | ||
5 | # This program is free software under the GPL (>=v2) | ||
6 | # Read the file COPYING coming with the software for details. | ||
7 | |||
8 | """Test for the xmlsupport.py module | ||
9 | """ | ||
10 | |||
11 | __version__ = "$Revision$" | ||
12 | # $Source$ | ||
13 | # $Id$ | ||
14 | |||
15 | import unittest | ||
16 | |||
17 | import xmlsupport | ||
18 | import support | ||
19 | |||
20 | class TestValidation(unittest.TestCase, xmlsupport.ValidationTest): | ||
21 | |||
22 | def test_simple(self): | ||
23 | """test xmlsupport validating valid XML | ||
24 | |||
25 | The test succeeds if validate_data doesn't raise any exception | ||
26 | """ | ||
27 | data = ('<?xml version="1.0" encoding="UTF-8"?>\n' | ||
28 | '<!DOCTYPE session SYSTEM "thuban.dtd">\n' | ||
29 | '<session title="empty session">\n</session>\n') | ||
30 | self.validate_data(data) | ||
31 | |||
32 | def test_invalid(self): | ||
33 | """test xmlsupport validating invalid XML | ||
34 | |||
35 | The test succeeds if validate_data raises an assertion error | ||
36 | """ | ||
37 | data = ('<?xml version="1.0" encoding="UTF-8"?>\n' | ||
38 | '<!DOCTYPE session SYSTEM "thuban.dtd">\n' | ||
39 | '<session foo="bar">\n</session>\n') | ||
40 | # only really run this test when pyRXP is available | ||
41 | if xmlsupport.pyRXP is not None: | ||
42 | self.assertRaises(AssertionError, self.validate_data, data) | ||
43 | |||
44 | |||
45 | bh | 1257 | |
46 | class TestEventList(unittest.TestCase): | ||
47 | |||
48 | """Test cases for sax_eventlist""" | ||
49 | |||
50 | def test_even_list_simple(self): | ||
51 | """Test sax_eventlist on very simple XML""" | ||
52 | data = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>' | ||
53 | '<!DOCTYPE session SYSTEM "thuban.dtd">' | ||
54 | '<session title="single map&layer">' | ||
55 | '</session>']) | ||
56 | |||
57 | self.assertEquals(xmlsupport.sax_eventlist(data = data), | ||
58 | [('start', (None, u'session'), None, | ||
59 | [((None, u'title'), u'single map&layer')]), | ||
60 | ('end', (None, u'session'), None)]) | ||
61 | |||
62 | def test_even_list_namespace(self): | ||
63 | """Test sax_eventlist on XML with a default namespace""" | ||
64 | data = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>' | ||
65 | '<!DOCTYPE session SYSTEM "thuban.dtd">' | ||
66 | '<session title="single map&layer"' | ||
67 | ' xmlns="http://example.com/example.dtd">' | ||
68 | '</session>']) | ||
69 | |||
70 | self.assertEquals(xmlsupport.sax_eventlist(data = data), | ||
71 | [('start', (u'http://example.com/example.dtd', | ||
72 | u'session'), | ||
73 | None, [((None, u'title'), u'single map&layer')]), | ||
74 | ('end', (u'http://example.com/example.dtd', | ||
75 | u'session'), None)]) | ||
76 | |||
77 | bh | 1268 | def test_even_list_id_normalization(self): |
78 | """Test sax_eventlist on XML with a default namespace""" | ||
79 | data1 = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>' | ||
80 | '<!DOCTYPE session SYSTEM "thuban.dtd">' | ||
81 | '<session title="bla">' | ||
82 | ' <table id="foo"/>' | ||
83 | ' <tableref id="foo"/>' | ||
84 | '</session>']) | ||
85 | |||
86 | data2 = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>' | ||
87 | '<!DOCTYPE session SYSTEM "thuban.dtd">' | ||
88 | '<session title="bla">' | ||
89 | ' <table id="bar"/>' | ||
90 | ' <tableref id="bar"/>' | ||
91 | '</session>']) | ||
92 | ids = [((None, "table"), (None, "id"))] | ||
93 | idrefs = [((None, "tableref"), (None, "id"))] | ||
94 | self.assertEquals(xmlsupport.sax_eventlist(data = data1, ids = ids, | ||
95 | idrefs = idrefs), | ||
96 | xmlsupport.sax_eventlist(data = data2, ids = ids, | ||
97 | idrefs = idrefs)) | ||
98 | |||
99 | bh | 1245 | if __name__ == "__main__": |
100 | # Fake the __file__ global because it's needed by a test | ||
101 | import sys | ||
102 | __file__ = sys.argv[0] | ||
103 | support.run_tests() |
Name | Value |
---|---|
svn:eol-style | native |
svn:keywords | Author Date Id Revision |
[email protected] | ViewVC Help |
Powered by ViewVC 1.1.26 |