1
2
3 """
4 Test cases related to Schematron parsing and validation
5 """
6
7 import unittest, sys
8
9 from common_imports import etree, doctest, HelperTestCase, fileInTestDir
10
13 tree_valid = self.parse('<AAA><BBB/><CCC/></AAA>')
14 tree_invalid = self.parse('<AAA><BBB/><CCC/><DDD/></AAA>')
15 schema = self.parse('''\
16 <schema xmlns="http://purl.oclc.org/dsdl/schematron" >
17 <pattern name="Open model">
18 <rule context="AAA">
19 <assert test="BBB"> BBB element is not present</assert>
20 <assert test="CCC"> CCC element is not present</assert>
21 </rule>
22 </pattern>
23 <pattern name="Closed model">
24 <rule context="AAA">
25 <assert test="BBB"> BBB element is not present</assert>
26 <assert test="CCC"> CCC element is not present</assert>
27 <assert test="count(BBB|CCC) = count (*)">There is an extra element</assert>
28 </rule>
29 </pattern>
30 </schema>
31 ''')
32 schema = etree.Schematron(schema)
33 self.assert_(schema.validate(tree_valid))
34 self.assert_(not schema.validate(tree_invalid))
35
38
40 schema = self.parse('''\
41 <schema xmlns="http://purl.oclc.org/dsdl/schematron" >
42 <pattern name="Open model">
43 </pattern>
44 </schema>
45 ''')
46 self.assertRaises(etree.SchematronParseError,
47 etree.Schematron, schema)
48
55
63
64
66 suite = unittest.TestSuite()
67 suite.addTests([unittest.makeSuite(ETreeSchematronTestCase)])
68 suite.addTests(
69 [doctest.DocFileSuite('../../../doc/validation.txt')])
70 return suite
71
72 if __name__ == '__main__':
73 print 'to test use test.py %s' % __file__
74