1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
"""!
@brief Test runner for unit and integration tests in the project.
@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause
"""
import enum
import sys
import unittest
# Generate images without having a window appear.
import matplotlib
matplotlib.use('Agg')
from pyclustering.tests.suite_holder import suite_holder
from pyclustering import __PYCLUSTERING_ROOT_DIRECTORY__
class pyclustering_integration_tests(suite_holder):
def __init__(self):
super().__init__()
pyclustering_integration_tests.fill_suite(self.get_suite())
@staticmethod
def fill_suite(integration_suite):
integration_suite.addTests(unittest.TestLoader().discover(__PYCLUSTERING_ROOT_DIRECTORY__, "it_*.py"))
class pyclustering_unit_tests(suite_holder):
def __init__(self):
super().__init__()
pyclustering_unit_tests.fill_suite(self.get_suite())
@staticmethod
def fill_suite(unit_suite):
unit_suite.addTests(unittest.TestLoader().discover(__PYCLUSTERING_ROOT_DIRECTORY__, "ut_*.py"))
class pyclustering_tests(suite_holder):
def __init__(self):
super().__init__()
pyclustering_tests.fill_suite(self.get_suite())
@staticmethod
def fill_suite(pyclustering_suite):
pyclustering_integration_tests.fill_suite(pyclustering_suite)
pyclustering_unit_tests.fill_suite(pyclustering_suite)
class exit_code(enum.IntEnum):
success = 0,
error_unknown_type_test = -1,
error_too_many_arguments = -2,
error_failure = -3
class tests_runner:
@staticmethod
def run():
result = None
return_code = exit_code.success
if len(sys.argv) == 1:
result = pyclustering_tests().run()
elif len(sys.argv) == 2:
if sys.argv[1] == "--integration":
result = pyclustering_integration_tests().run()
elif sys.argv[1] == "--unit":
result = pyclustering_unit_tests().run()
elif sys.argv[1] == "test":
result = pyclustering_tests().run()
else:
print("Unknown type of test is specified '" + str(sys.argv[1]) + "'.")
return_code = exit_code.error_unknown_type_test
else:
print("Too many arguments '" + str(len(sys.argv)) + "' is used.")
return_code = exit_code.error_too_many_arguments
# Get execution result
if result is not None:
if result.wasSuccessful() is False:
return_code = exit_code.error_failure
exit(return_code)
|