1
2
3 """
4 Test cases related to Schematron parsing and validation
5 """
6
7 from __future__ import absolute_import
8
9 import unittest
10
11 from .common_imports import etree, HelperTestCase, make_doctest
12
13
16 tree_valid = self.parse('<AAA><BBB/><CCC/></AAA>')
17 tree_invalid = self.parse('<AAA><BBB/><CCC/><DDD/></AAA>')
18 schema = self.parse('''\
19 <schema xmlns="http://purl.oclc.org/dsdl/schematron" >
20 <pattern name="Open model">
21 <rule context="AAA">
22 <assert test="BBB"> BBB element is not present</assert>
23 <assert test="CCC"> CCC element is not present</assert>
24 </rule>
25 </pattern>
26 <pattern name="Closed model">
27 <rule context="AAA">
28 <assert test="BBB"> BBB element is not present</assert>
29 <assert test="CCC"> CCC element is not present</assert>
30 <assert test="count(BBB|CCC) = count (*)">There is an extra element</assert>
31 </rule>
32 </pattern>
33 </schema>
34 ''')
35 schema = etree.Schematron(schema)
36 self.assertTrue(schema.validate(tree_valid))
37 self.assertFalse(schema.error_log.filter_from_errors())
38
39 self.assertFalse(schema.validate(tree_invalid))
40 self.assertTrue(schema.error_log.filter_from_errors())
41
42 self.assertTrue(schema.validate(tree_valid))
43 self.assertFalse(schema.error_log.filter_from_errors())
44
47
49 schema = self.parse('''\
50 <schema xmlns="http://purl.oclc.org/dsdl/schematron" >
51 <pattern name="Open model">
52 </pattern>
53 </schema>
54 ''')
55 self.assertRaises(etree.SchematronParseError,
56 etree.Schematron, schema)
57
64
72
73
75 suite = unittest.TestSuite()
76 suite.addTests([unittest.makeSuite(ETreeSchematronTestCase)])
77 suite.addTests(
78 [make_doctest('../../../doc/validation.txt')])
79 return suite
80
81 if __name__ == '__main__':
82 print('to test use test.py %s' % __file__)
83