diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-05-30 16:57:33 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-05-30 17:06:51 +0200 |
commit | ef00d0758a854f04d908159f9616bc71a579ae0c (patch) | |
tree | 882b9d747c5cf543478ed5d63bd793548e2f447a /tests/format.py | |
parent | 10853c31a948a9a77053f05f91cdf8f5ea8da846 (diff) | |
download | clufter-ef00d0758a854f04d908159f9616bc71a579ae0c.tar.gz clufter-ef00d0758a854f04d908159f9616bc71a579ae0c.tar.xz clufter-ef00d0758a854f04d908159f9616bc71a579ae0c.zip |
tests: check validation harness using now fixed corosync.rng
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'tests/format.py')
-rw-r--r-- | tests/format.py | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/tests/format.py b/tests/format.py index f651f6c..3a18cab 100644 --- a/tests/format.py +++ b/tests/format.py @@ -6,54 +6,88 @@ __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" import unittest +from lxml import etree from os.path import dirname, join #from pprint import pprint import _bootstrap # known W402, required +from clufter.format import FormatError from clufter.formats.ccs import ccs +from clufter.formats.coro import coroxml_needle -WALK_DIR = join(dirname(__file__), 'XMLFormat-walk') -RESULT_WALK_FULL = { - 'cluster': ('cluster-full', { - 'clusternodes': ('clusternodes-full', { - 'clusternode': ('clusternode-full', { - }) - }), - 'cman': ('cman-full', { - }), - 'dlm': ('dlm-full', { - }), - 'rm': ('rm-full', { - 'failoverdomains': ('failoverdomains-full', { - 'failoverdomain': ('failoverdomain-full', { +class XMLFormatWalkTestCase(unittest.TestCase): + walk_dir = join(dirname(__file__), 'XMLFormat-walk') + result_walk_full = { + 'cluster': ('cluster-full', { + 'clusternodes': ('clusternodes-full', { + 'clusternode': ('clusternode-full', { }) }), - 'service': ('service-full', { + 'cman': ('cman-full', { + }), + 'dlm': ('dlm-full', { + }), + 'rm': ('rm-full', { + 'failoverdomains': ('failoverdomains-full', { + 'failoverdomain': ('failoverdomain-full', { + }) + }), + 'service': ('service-full', { + }) }) }) - }) -} - -RESULT_WALK_SPARSE = { - 'failoverdomain': ('failoverdomain-sparse', { - }), - 'heuristic': ('heuristic-sparse', { - }) -} - + } + result_walk_sparse = { + 'failoverdomain': ('failoverdomain-sparse', { + }), + 'heuristic': ('heuristic-sparse', { + }) + } -class XMLFormatWalkTestCase(unittest.TestCase): def testWalkFull(self): - r = ccs.walk_schema(WALK_DIR, 'full') + r = ccs.walk_schema(self.walk_dir, 'full') #pprint(r, width=8) # --> expected - self.assertTrue(r == RESULT_WALK_FULL) + self.assertTrue(r == self.result_walk_full) def testWalkSparse(self): - r = ccs.walk_schema(WALK_DIR, 'sparse') + r = ccs.walk_schema(self.walk_dir, 'sparse') #pprint(r, width=8) # --> expected - self.assertTrue(r == RESULT_WALK_SPARSE) + self.assertTrue(r == self.result_walk_sparse) + + +class XMLValidationTestCase(unittest.TestCase): + coro_input_ok = join(dirname(__file__), 'coro_ok.xml') + coro_input_fail = join(dirname(__file__), 'coro_fail.xml') + + def testRngImplicitValidationOk(self): + try: + et = coroxml_needle('file', self.coro_input_ok)('etree') + except Exception: + raise + self.assertTrue(False) + + def testRngImplicitValidationFail(self): + try: + et = coroxml_needle('file', self.coro_input_fail)('etree') + except FormatError as e: + self.assertTrue('Validation' in str(e)) + pass + else: + self.assertTrue(False) + + def testRngExplicitValidationOk(self): + et, entries = coroxml_needle.etree_validator( + etree.parse(self.coro_input_ok) + ) + self.assertFalse(entries) + + def testRngExplicitValidationFail(self): + et, entries = coroxml_needle.etree_validator( + etree.parse(self.coro_input_fail) + ) + self.assertTrue(entries) if __name__ == '__main__': |