/[thuban]/branches/WIP-pyshapelib-bramz/test/xmlsupport.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/test/xmlsupport.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1245 - (show annotations)
Thu Jun 19 19:29:23 2003 UTC (21 years, 8 months ago) by bh
Original Path: trunk/thuban/test/xmlsupport.py
File MIME type: text/x-python
File size: 1733 byte(s)
Add XML validation to some of the tests. Validation will only be
done if pyRXP is installed (http://reportlab.com/xml/pyrxp.html).
To make the DTD available to the test cases it's moved into
Resources/XML

* Resources/XML/thuban.dtd: New. This is now the real Thuban DTD
for versions up to and including 0.2. Two slight changes: added an
encoding specification and fixed the comment which refered to
GRASS, not Thuban

* test/xmlsupport.py: New support module for tests involving XML.
Currently there's a mix-in class for XML validation.

* test/test_xmlsupport.py: New. Tests for the xmlsupport module

* test/test_save.py (SaveSessionTest): Derive from ValidationTest
so that we can validate the
(SaveSessionTest.testEmptySession)
(SaveSessionTest.testSingleLayer)
(SaveSessionTest.testSingleLayer)
(SaveSessionTest.testLayerProjection)
(SaveSessionTest.testRasterLayer)
(SaveSessionTest.testClassifiedLayer): Validate the generated XML

* test/runtests.py (main): Call print_additional_summary instead
of print_garbage_information

* test/support.py (resource_dir): New function to return the
"Resource" subdirectory
(print_additional_summary): New function to combine several
summary functions
(run_tests): Use print_additional_summary instead of calling
print_garbage_information directly

1 # 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 """XML support code for the test cases"""
9
10 import sys
11 import os
12 import support
13
14 try:
15 import pyRXP
16 except ImportError:
17 pyRXP = None
18
19 class ValidationTest:
20
21 """Mix-in class for tests that want to check for validity of XML data"""
22
23 # If true, at least one test case tried to validate XML data but
24 # couldn't because PyRXP is not available
25 validation_attempt_ignored = False
26
27 def validate_data(self, data):
28 """Validate the XML data"""
29 if pyRXP is not None:
30 parser = pyRXP.Parser()
31 try:
32 parser.parse(data, eoCB = self.rxp_eo_cb)
33 except pyRXP.error, val:
34 raise AssertionError, str(val), sys.exc_info()[2]
35 else:
36 ValidationTest.validation_attempt_ignored = True
37
38 def rxp_eo_cb(self, filename):
39 """Resolve an eternal entity
40
41 In the Thuban test cases the only external entities that have to
42 be resolved are the DTDs which now live in the resource
43 directory. So, interpret any filename relative to that
44 directory.
45 """
46 return os.path.join(support.resource_dir(), "XML", filename)
47
48
49
50 def print_summary_message():
51 """Print a summary message about validation tests
52
53 Currently simply print a message about pyRXP not being available if
54 a test case's attempt to validate XML was ignored because of that.
55 """
56 if ValidationTest.validation_attempt_ignored:
57 print "XML validation attempts ignored because pyRXP is not available"

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26