diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-12-10 17:19:54 -0600 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-12-10 17:22:38 -0600 |
commit | 9d6e6241954d001a5b49e4ea9a48c10e2a792958 (patch) | |
tree | 270309c0e04eacf2ce1e0d6cc6d61f1485899c0a /testsuite/Testschema/test_schema.py | |
parent | 7dcb468f09781bacf79823748ef12bfbd1faeb21 (diff) | |
download | bcfg2-9d6e6241954d001a5b49e4ea9a48c10e2a792958.tar.gz bcfg2-9d6e6241954d001a5b49e4ea9a48c10e2a792958.tar.bz2 bcfg2-9d6e6241954d001a5b49e4ea9a48c10e2a792958.zip |
generate XML schema docs from XML schemas themselves
Diffstat (limited to 'testsuite/Testschema/test_schema.py')
-rw-r--r-- | testsuite/Testschema/test_schema.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/testsuite/Testschema/test_schema.py b/testsuite/Testschema/test_schema.py index 56fe76205..ddfe4775f 100644 --- a/testsuite/Testschema/test_schema.py +++ b/testsuite/Testschema/test_schema.py @@ -1,7 +1,7 @@ import os -import re import sys import glob +import lxml.etree from subprocess import Popen, PIPE, STDOUT # add all parent testsuite directories to sys.path to allow (most) @@ -27,14 +27,46 @@ except OSError: HAS_XMLLINT = False +XS = "http://www.w3.org/2001/XMLSchema" +XS_NS = "{%s}" % XS +NSMAP = dict(xs=XS) + + 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'))] + 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) + + def test_duplicates(self): + entities = dict() + for root, _, files in os.walk(srcpath): + for fname in files: + if not fname.endswith(".xsd"): + continue + path = os.path.join(root, fname) + relpath = path[len(srcpath):].strip("/") + schema = lxml.etree.parse(path).getroot() + ns = schema.get("targetNamespace") + if ns not in entities: + entities[ns] = dict(group=dict(), + attributeGroup=dict(), + simpleType=dict(), + complexType=dict()) + for entity in schema.xpath("//xs:*[@name]", namespaces=NSMAP): + tag = entity.tag[len(XS_NS):] + if tag not in entities[ns]: + continue + name = entity.get("name") + if name in entities[ns][tag]: + self.assertNotIn(name, entities[ns][tag], + "Duplicate %s %s (in %s and %s)" % + (tag, name, fname, + entities[ns][tag][name])) + entities[ns][tag][name] = fname |