2013-09-21 22:27:41 +00:00
|
|
|
import unittest
|
2013-09-21 22:34:15 +00:00
|
|
|
import platform
|
2014-10-25 21:26:41 +00:00
|
|
|
import sys
|
2019-04-17 12:57:21 +00:00
|
|
|
import argparse
|
2022-01-06 08:37:14 +00:00
|
|
|
import locale
|
2013-09-21 22:27:41 +00:00
|
|
|
|
2013-09-21 22:34:15 +00:00
|
|
|
if platform.python_version() < '2.7':
|
|
|
|
unittest = __import__('unittest2')
|
|
|
|
else:
|
|
|
|
import unittest
|
2013-09-21 22:27:41 +00:00
|
|
|
|
2019-04-17 12:57:21 +00:00
|
|
|
try:
|
|
|
|
import xmlrunner
|
|
|
|
have_xml = True
|
|
|
|
except ImportError:
|
|
|
|
have_xml = False
|
|
|
|
|
|
|
|
|
2013-09-21 22:27:41 +00:00
|
|
|
if __name__ == '__main__':
|
2019-04-17 12:57:21 +00:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Test suit for KiCad Python functions')
|
|
|
|
parser.add_argument('--xml', action="store", type=str,
|
|
|
|
help='Output XML test results to the given directory')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.xml and not have_xml:
|
|
|
|
print("XML test reporting not available")
|
|
|
|
print("Install the xmlrunner package.")
|
|
|
|
sys.exit(2)
|
|
|
|
|
2022-01-06 08:37:14 +00:00
|
|
|
# Useful in some non English installs (using a comma as load number separator) to avoid
|
|
|
|
# wxWidgets alerts when running the test code
|
|
|
|
locale.setlocale(locale.LC_ALL, 'C')
|
|
|
|
|
2019-04-17 12:57:21 +00:00
|
|
|
testsuite = unittest.TestLoader().discover('testcases', pattern="*.py")
|
|
|
|
|
|
|
|
if args.xml:
|
|
|
|
# Dump XML results to the right directory
|
|
|
|
runner = xmlrunner.XMLTestRunner(output=args.xml)
|
|
|
|
else:
|
|
|
|
# Use a normal text runner
|
|
|
|
runner = unittest.TextTestRunner(verbosity=100)
|
|
|
|
|
|
|
|
results = runner.run(testsuite)
|
2014-10-25 21:26:41 +00:00
|
|
|
|
|
|
|
# Return an error code if any of the testsuite tests fail
|
2015-02-01 18:20:20 +00:00
|
|
|
if not results.wasSuccessful():
|
2014-10-25 21:26:41 +00:00
|
|
|
sys.exit(1)
|