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" |