summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-29 16:26:16 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-29 16:26:16 +0200
commitea088393c441007c02c1c0f7796c13ed29b6159f (patch)
tree98dd6765f464f47760b6d390e628ea0d178e1674
parentfb6be296585e253a9f075b1418c9b8edcbbc604c (diff)
downloadxdd2esi-ea088393c441007c02c1c0f7796c13ed29b6159f.tar.gz
xdd2esi-ea088393c441007c02c1c0f7796c13ed29b6159f.zip
Add test.py
-rw-r--r--test.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..9cb3b92
--- /dev/null
+++ b/test.py
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+# vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
+
+""" test.py
+Tests xdd2esilib with some test-XDDs and validates them
+29. June 2012
+"""
+
+import glob
+import xdd2esilib
+import esilib
+import argparse
+import os
+import warnings
+import logging
+
+warncount = 0
+
+def parseargs():
+ """ Parse the command-line arguments """
+ parser = argparse.ArgumentParser(
+ description='Test xdd2esilib with test-XDDs and validate them',
+ epilog='Florian Bruhin')
+ parser.add_argument('xddfolder', default=os.getcwd(), nargs='?',
+ help='Directory containing XDD files (will search for *.xdd) to test')
+ parser.add_argument('-S', '--schema', default='EtherCatInfo.xsd',
+ help=('Filename of the schema (default: EtherCatInfo.xsd), searched'
+ 'in the XDD folder'))
+ parser.add_argument('-t', '--template', default='template.esi.xml',
+ help=('Filename of the template (default: template.esi.xml), searched'
+ 'in the XDD folder'))
+ options = parser.parse_args()
+ return options
+
+def init():
+ """ Initializes this module """
+ options = parseargs()
+ logging.disable(logging.ERROR)
+ return options
+
+def main():
+ """ Main function """
+ options = init()
+ if not os.path.isdir(options.xddfolder):
+ raise IOError("xddfolder is not a folder!")
+ os.chdir(options.xddfolder)
+ xdds = glob.glob('*.xdd')
+ if len(xdds) == 0:
+ raise IOError("xddfolder does not contain any XDD files!")
+ for xdd in xdds:
+ with warnings.catch_warnings(record=True) as w:
+ try:
+ xdd2esilib.run(xdd, outfile=None, template=options.template,
+ schema=options.schema)
+ except esilib.InvalidESIWarning:
+ failpass = 'FAIL'
+ except Exception as e:
+ failpass = 'EXCEPTION'
+ exception = "{}: {}".format(e.__class__.__name__, e)
+ else:
+ failpass = 'PASS'
+ exception = None
+ if len(w) == 0:
+ warncnt = ''
+ elif len(w) == 1:
+ warncnt = ", {} warning".format(len(w))
+ else:
+ warncnt = ", {} warnings".format(len(w))
+ print("WARNINGS: ", w)
+ for warning in w:
+ if warning.category is esilib.InvalidESIWarning:
+ failpass = 'FAIL'
+ if failpass != "PASS" or warncnt != '':
+ print()
+ print('{:40.40} {}{}'.format(xdd, failpass, warncnt))
+ for warning in w:
+ print(" {}: {}".format(warning.category.__name__, warning.message))
+ if exception is not None:
+ print(" {}".format(exception))
+ if failpass != "PASS" or warncnt != '':
+ print(" xdd2esi.py --force --dry-run --loglevel=debug --template "
+ "{} --schema {} {} -".format(
+ os.path.join(options.xddfolder, options.template),
+ os.path.join(options.xddfolder, options.schema),
+ os.path.join(options.xddfolder, xdd)))
+ print()
+
+if __name__ == '__main__':
+ main()