def run_test_list(tests): ok = 0 failed = [] # First, just run the tests. for t in tests: pname = t['pretty_name'] print('==============================') tfunc = t['test_func'] print('Running test:', pname) # Do this before the bottom frame so we have a clue how long startup # took and where the fail was. env = None try: testlib.clean_data_dir() # IMPORTANT! print('------------------------------') env = testlib.TestEnv(t['node_cnt']) except Exception as e: print('Error initing env, this is a test framework bug:', e) break print('==============================') # This is where the test actually runs. try: tfunc(env) env.shutdown() print('------------------------------') print('Success:', pname) ok += 1 time.sleep(0.1) # Wait for things to exit, just to be sure. except BaseException as e: env.shutdown() print('------------------------------') print('Failure:', pname) print('\nError:', e) failed.append(t) if type(e) is KeyboardInterrupt: break # TODO Report failures and why. print('==============================') # Collect results. res = { 'ok': ok, 'fail': len(failed), 'ignored': len(tests) - ok - len(failed), 'failed': failed } return res
def run_test_list(tests): ok = 0 fail = 0 # First, just run the tests. for t in tests: name = t['name'] print('==============================') tfunc = t['test_func'] if tfunc.__name__ == 'run_test': print('Running test:', name) else: print('Running test:', name + ':' + tfunc.__name__) # Do this before the bottom frame so we have a clue how long startup # took and where the fail was. env = None try: testlib.clean_data_dir() # IMPORTANT! print('------------------------------') env = testlib.TestEnv(t['node_cnt']) except Exception as e: print('Error initing env, this is a test framework bug:', e) break print('==============================') # This is where the test actually runs. try: tfunc(env) env.shutdown() print('------------------------------') print('Success:', name) ok += 1 except BaseException as e: env.shutdown() print('------------------------------') print('Failure:', name) print('\nError:', e) fail += 1 if type(e) is KeyboardInterrupt: break # TODO Report failures and why. print('==============================') # Collect results. res = {'ok': ok, 'fail': fail, 'ignored': len(tests) - ok - fail} return res
#!/usr/bin/env python3 import testlib import test_combinators def run_test(env): lit1 = env.lits[0] lit2 = env.lits[1] test_combinators.run_pushbreak_test(env, lit1, lit2, lit1) if __name__ == '__main__': env = None try: env = testlib.TestEnv(2) run_test(env) finally: if env is not None: env.shutdown()
#!/usr/bin/env python3 import testlib create = 1 def run_test(env): litcnt = len(env.lits) print('Found', len(env.lits), 'Lit nodes created.') if litcnt == create: print('OK') else: print('ERR') if __name__ == '__main__': env = None try: env = testlib.TestEnv(create) run_test(env) finally: if env is not None: env.shutdown()
'nodes': 2 }, { 'func': pushbreak_reverse, 'name': 'Test pushbreak_reverse', 'nodes': 2 } ] for test in tests: error = False try: print("==============================") print("Running test " + test['name']) print("==============================") env = testlib.TestEnv(test['nodes']) test['func'](env) print("-------") print("SUCCESS") print("-------") except Exception as e: print("-------") print("FAILURE:") print(e) print("-------") error = True env.shutdown() if error: sys.exit(1)