1import unittest 2 3import lit.discovery 4import lit.LitConfig 5import lit.worker 6 7""" 8TestCase adaptor for providing a Python 'unittest' compatible interface to 'lit' 9tests. 10""" 11 12 13class UnresolvedError(RuntimeError): 14 pass 15 16 17class LitTestCase(unittest.TestCase): 18 def __init__(self, test, lit_config): 19 unittest.TestCase.__init__(self) 20 self._test = test 21 self._lit_config = lit_config 22 23 def id(self): 24 return self._test.getFullName() 25 26 def shortDescription(self): 27 return self._test.getFullName() 28 29 def runTest(self): 30 # Run the test. 31 result = lit.worker._execute(self._test, self._lit_config) 32 33 # Adapt the result to unittest. 34 if result.code is lit.Test.UNRESOLVED: 35 raise UnresolvedError(result.output) 36 elif result.code.isFailure: 37 self.fail(result.output) 38 39 40def load_test_suite(inputs): 41 import platform 42 windows = platform.system() == 'Windows' 43 44 # Create the global config object. 45 lit_config = lit.LitConfig.LitConfig( 46 progname='lit', 47 path=[], 48 quiet=False, 49 useValgrind=False, 50 valgrindLeakCheck=False, 51 valgrindArgs=[], 52 noExecute=False, 53 debug=False, 54 isWindows=windows, 55 order='smart', 56 params={}) 57 58 # Perform test discovery. 59 tests = lit.discovery.find_tests_for_inputs(lit_config, inputs, False) 60 test_adaptors = [LitTestCase(t, lit_config) for t in tests] 61 62 # Return a unittest test suite which just runs the tests in order. 63 return unittest.TestSuite(test_adaptors) 64