From ef00d0758a854f04d908159f9616bc71a579ae0c Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Fri, 30 May 2014 16:57:33 +0200 Subject: tests: check validation harness using now fixed corosync.rng MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- tests/format.py | 94 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 30 deletions(-) (limited to 'tests/format.py') 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ý " 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__': -- cgit