def verify_data(data_dir, platform, os_name, tests): """Verify test data is correct. @param data_dir: top level directory for all tests @param platform: The platform name we for this test data (e.g. lxd) @param os_name: The operating system under test (xenial, artful, etc.). @param tests: list of test names @return_value: {<test_name>: {passed: True/False, failures: []}} """ base_dir = os.sep.join((data_dir, platform, os_name)) runner = unittest2.TextTestRunner(verbosity=util.current_verbosity()) res = {} for test_name in tests: LOG.debug('verifying test data for %s', test_name) # get cloudconfig for test test_conf = config.load_test_config(test_name) test_module = config.name_to_module(test_name) cloud_conf = test_conf['cloud_config'] # load script outputs data = {'platform': platform, 'os_name': os_name} test_dir = os.path.join(base_dir, test_name) for script_name in os.listdir(test_dir): with open(os.path.join(test_dir, script_name), 'rb') as fp: data[script_name] = fp.read() # get test suite and launch tests suite = testcases.get_suite(test_module, data, cloud_conf) suite_results = runner.run(suite) res[test_name] = { 'passed': suite_results.wasSuccessful(), 'failures': [{ 'module': type(test_class).__base__.__module__, 'class': type(test_class).__base__.__name__, 'function': str(test_class).split()[0], 'error': trace.splitlines()[-1], 'traceback': trace, } for test_class, trace in suite_results.failures] } for failure in res[test_name]['failures']: LOG.warning('test case: %s failed %s.%s with: %s', test_name, failure['class'], failure['function'], failure['error']) return res
def verify_data(data_dir, platform, os_name, tests): """Verify test data is correct. @param data_dir: top level directory for all tests @param platform: The platform name we for this test data (e.g. lxd) @param os_name: The operating system under test (xenial, artful, etc.). @param tests: list of test names @return_value: {<test_name>: {passed: True/False, failures: []}} """ base_dir = os.sep.join((data_dir, platform, os_name)) runner = unittest2.TextTestRunner(verbosity=util.current_verbosity()) res = {} for test_name in tests: LOG.debug('verifying test data for %s', test_name) # get cloudconfig for test test_conf = config.load_test_config(test_name) test_module = config.name_to_module(test_name) cloud_conf = test_conf['cloud_config'] # load script outputs data = {'platform': platform, 'os_name': os_name} test_dir = os.path.join(base_dir, test_name) for script_name in os.listdir(test_dir): with open(os.path.join(test_dir, script_name), 'rb') as fp: data[script_name] = fp.read() # get test suite and launch tests suite = testcases.get_suite(test_module, data, cloud_conf) suite_results = runner.run(suite) res[test_name] = { 'passed': suite_results.wasSuccessful(), 'failures': [{'module': type(test_class).__base__.__module__, 'class': type(test_class).__base__.__name__, 'function': str(test_class).split()[0], 'error': trace.splitlines()[-1], 'traceback': trace, } for test_class, trace in suite_results.failures] } for failure in res[test_name]['failures']: LOG.warning('test case: %s failed %s.%s with: %s', test_name, failure['class'], failure['function'], failure['error']) return res
def verify_data(base_dir, tests): """ verify test data is correct, base_dir: base directory for data test_config: dict of all test config, from util.load_test_config() tests: list of test names return_value: {<test_name>: {passed: True/False, failures: []}} """ runner = unittest.TextTestRunner(verbosity=util.current_verbosity()) res = {} for test_name in tests: LOG.debug('verifying test data for %s', test_name) # get cloudconfig for test test_conf = config.load_test_config(test_name) test_module = config.name_to_module(test_name) cloud_conf = test_conf['cloud_config'] # load script outputs data = {} test_dir = os.path.join(base_dir, test_name) for script_name in os.listdir(test_dir): with open(os.path.join(test_dir, script_name), 'r') as fp: data[script_name] = fp.read() # get test suite and launch tests suite = testcases.get_suite(test_module, data, cloud_conf) suite_results = runner.run(suite) res[test_name] = { 'passed': suite_results.wasSuccessful(), 'failures': [{ 'module': type(test_class).__base__.__module__, 'class': type(test_class).__base__.__name__, 'function': str(test_class).split()[0], 'error': trace.splitlines()[-1], 'traceback': trace, } for test_class, trace in suite_results.failures] } for failure in res[test_name]['failures']: LOG.warning('test case: %s failed %s.%s with: %s', test_name, failure['class'], failure['function'], failure['error']) return res