From dd196ce73618390736bd9df9ab41e97996ee7e9b Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 16 Oct 2012 09:22:49 -0400 Subject: added unit tests to test for schema validity --- testsuite/Testschema/test_schema.py | 40 +++++++++++++++++++++++++++++++++++++ testsuite/before_install.sh | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 testsuite/Testschema/test_schema.py (limited to 'testsuite') diff --git a/testsuite/Testschema/test_schema.py b/testsuite/Testschema/test_schema.py new file mode 100644 index 000000000..56fe76205 --- /dev/null +++ b/testsuite/Testschema/test_schema.py @@ -0,0 +1,40 @@ +import os +import re +import sys +import glob +from subprocess import Popen, PIPE, STDOUT + +# add all parent testsuite directories to sys.path to allow (most) +# relative imports in python 2.4 +_path = os.path.dirname(__file__) +while _path != '/': + if os.path.basename(_path).lower().startswith("test"): + sys.path.append(_path) + if os.path.basename(_path) == "testsuite": + break + _path = os.path.dirname(_path) +from common import * + +# path to Bcfg2 schema directory +srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", + "schemas")) + +# test for xmllint existence +try: + Popen(['xmllint'], stdout=PIPE, stderr=STDOUT).wait() + HAS_XMLLINT = True +except OSError: + HAS_XMLLINT = False + + +class TestSchemas(Bcfg2TestCase): + schema_url = "http://www.w3.org/2001/XMLSchema.xsd" + + @skipUnless(HAS_XMLLINT, "xmllint not installed") + def test_valid(self): + schemas = [s for s in glob.glob(os.path.join(srcpath,'*.xsd'))] + xmllint = Popen(['xmllint', '--xinclude', '--noout', '--schema', + self.schema_url] + schemas, + stdout=PIPE, stderr=STDOUT) + print(xmllint.communicate()[0]) + self.assertEqual(xmllint.wait(), 0) diff --git a/testsuite/before_install.sh b/testsuite/before_install.sh index 1a68669de..884971e45 100755 --- a/testsuite/before_install.sh +++ b/testsuite/before_install.sh @@ -3,7 +3,7 @@ # before_install script for Travis-CI sudo apt-get update -qq -sudo apt-get install -qq swig pylint +sudo apt-get install -qq swig pylint libxml2-utils if [[ "$WITH_OPTIONAL_DEPS" == "yes" ]]; then sudo apt-get install -qq python-selinux python-pylibacl python-pyinotify \ python-yaml yum -- cgit v1.2.3-1-g7c22