def run_test(cls, debug=False): sys.stdout.write("********* soma-workflow tests: WORKFLOW *********\n") config_file_path = Configuration.search_config_path() # sys.stdout.write("Configuration file: " + config_file_path + "\n") resource_ids = Configuration.get_configured_resources(config_file_path) for resource_id in resource_ids: sys.stdout.write("===== Resource : " + resource_id + " ====== \n") sys.stdout.write("Do you want to test the resource %s (Y/n) ?" % resource_id) test_resource = sys.stdin.readline() if test_resource.strip() in ['no', 'n', 'N', 'No', 'NO']: # Skip the resource sys.stdout.write('Resource %s is not tested \n' % resource_id) continue config = Configuration.load_from_file(resource_id, config_file_path) if config.get_mode() not in cls.allowed_resources: sys.stdout.write('No tests available for this resource \n') continue (login, password) = get_user_id(resource_id, config) # with suppress_stdout(debug): # wf_controller = WorkflowController(resource_id, # login, # password) # cls.setup_wf_controller(wf_controller) # allowed_config = cls.allowed_config[:] # for configuration in cls.allowed_config: # if config.get_mode() != configuration[0]: # allowed_config.remove(configuration) # if len(allowed_config) == 0: # sys.stdout.write("No tests available for the resource %s \n" % # resource_id) # for configuration in allowed_config: # (mode, file_system) = configuration # sys.stdout.write("\n--------------------------------------\n") # sys.stdout.write("Mode : " + mode + \n") # sys.stdout.write("File system : " + file_system + \n") # cls.setup_path_management(file_system) with suppress_stdout(debug): JobTests.setup_connection(resource_id, login, password) suite_list = [] list_tests = [] for test in dir(cls): prefix = "test_" if len(test) < len(prefix): continue if test[0:len(prefix)] == prefix: list_tests.append(test) suite_list.append(unittest.TestSuite(map(cls, list_tests))) alltests = unittest.TestSuite(suite_list) with suppress_stdout(debug): unittest.TextTestRunner(verbosity=2).run(alltests)
def run_test(cls, debug=False): sys.stdout.write("********* soma-workflow tests: WORKFLOW *********\n") config_file_path = Configuration.search_config_path() # sys.stdout.write("Configuration file: " + config_file_path + "\n") resource_ids = Configuration.get_configured_resources(config_file_path) for resource_id in resource_ids: sys.stdout.write("============ Resource : " + resource_id + " =================== \n") sys.stdout.write("Do you want to test the resource " "%s (Y/n) ? " % resource_id) test_resource = sys.stdin.readline() if test_resource.strip() in ['no', 'n', 'N', 'No', 'NO']: # Skip the resource sys.stdout.write('Resource %s is not tested \n' % resource_id) continue config = Configuration.load_from_file(resource_id, config_file_path) (login, password) = get_user_id(resource_id, config) with suppress_stdout(debug): wf_controller = WorkflowController(resource_id, login, password) cls.setup_wf_controller(wf_controller) allowed_config = cls.allowed_config[:] for configuration in cls.allowed_config: if config.get_mode() != configuration[0]: allowed_config.remove(configuration) if len(allowed_config) == 0: sys.stdout.write("No tests available for the resource %s \n" % resource_id) for configuration in allowed_config: (mode, file_system) = configuration sys.stdout.write("\n---------------------------------------\n") sys.stdout.write("Mode : " + mode + '\n') sys.stdout.write("File system : " + file_system + '\n') cls.setup_path_management(file_system) suite_list = [] list_tests = [] for test in dir(cls): prefix = "test_" if len(test) < len(prefix): continue if test[0: len(prefix)] == prefix: list_tests.append(test) suite_list.append(unittest.TestSuite(map(cls, list_tests))) alltests = unittest.TestSuite(suite_list) with suppress_stdout(debug): unittest.TextTestRunner(verbosity=2).run(alltests) sys.exit(0)
def run_test(cls, debug=False, interactive=False, **kwargs): sys.stdout.write("********* soma-workflow tests: WORKFLOW *********\n") config_file_path = Configuration.search_config_path() # sys.stdout.write("Configuration file: " + config_file_path + "\n") resource_ids = Configuration.get_configured_resources(config_file_path) for resource_id in resource_ids: sys.stdout.write("============ Resource : " + resource_id + " =================== \n") config = Configuration.load_from_file(resource_id, config_file_path) if not interactive and config.get_mode() != LIGHT_MODE: sys.stdout.write('Resource %s is not tested in ' 'non-interactive mode\n' % resource_id) continue # skip login/password ask if interactive: sys.stdout.write("Do you want to test the resource " "%s (Y/n) ? " % resource_id) sys.stdout.flush() test_resource = sys.stdin.readline() if test_resource.strip() in ['no', 'n', 'N', 'No', 'NO']: # Skip the resource sys.stdout.write('Resource %s is not tested \n' % resource_id) sys.stdout.flush() continue (login, password) = get_user_id(resource_id, config) if config.get_mode() == LIGHT_MODE: # use a temporary sqlite database in soma-workflow to avoid # concurrent access problems tmpdb = tempfile.mkstemp('.db', prefix='swf_') os.close(tmpdb[0]) os.unlink(tmpdb[1]) # and so on for transfers / stdio files directory tmptrans = tempfile.mkdtemp(prefix='swf_') config._database_file = tmpdb[1] config._transfered_file_dir = tmptrans try: with suppress_stdout(debug): wf_controller = WorkflowController(resource_id, login, password, config=config) cls.setup_wf_controller(wf_controller) allowed_config = cls.allowed_config[:] for configuration in cls.allowed_config: if config.get_mode() != configuration[0]: allowed_config.remove(configuration) if len(allowed_config) == 0: sys.stdout.write( "No tests available for the resource %s \n" % resource_id) for configuration in allowed_config: (mode, file_system) = configuration sys.stdout.write( "\n---------------------------------------\n") sys.stdout.write("Mode : " + mode + '\n') sys.stdout.write("File system : " + file_system + '\n') cls.setup_path_management(file_system) if file_system in (cls.SHARED_RESOURCE_PATH, cls.SHARED_TRANSFER) \ and not config.get_path_translation(): sys.stdout.write( "Paths translation unavailable - not testing " "this case\n") sys.stdout.flush() continue suite_list = [] list_tests = [] for test in dir(cls): prefix = "test_" if len(test) < len(prefix): continue if test[0: len(prefix)] == prefix: list_tests.append(test) suite_list.append(unittest.TestSuite(map(cls, list_tests))) alltests = unittest.TestSuite(suite_list) with suppress_stdout(debug): res = unittest.TextTestRunner(verbosity=2).run( alltests) sys.stdout.flush() if len(res.errors) != 0 or len(res.failures) != 0: raise RuntimeError("tests failed.") finally: if config.get_mode() == LIGHT_MODE: if not kwargs.get('keep_temporary', False): os.unlink(config._database_file) if os.path.exists(config._database_file + '-journal'): os.unlink(config._database_file + '-journal') shutil.rmtree(config._transfered_file_dir) else: print('temporary files kept:') print('databse file:', config._database_file) print('transfers:', config._transfered_file_dir)
def run_test(cls, debug=False, interactive=False, **kwargs): sys.stdout.write("********* soma-workflow tests: %s *********\n" % cls.__name__) config_file_path = Configuration.search_config_path() resource_ids = Configuration.get_configured_resources(config_file_path) enabled_resources = getattr(WorkflowTest, 'enabled_resources', None) enable_resources = [] if not hasattr(WorkflowTest, 'resource_pass'): WorkflowTest.resource_pass = {} for resource_id in resource_ids: sys.stdout.write("============ Resource : " + resource_id + " =================== \n") config = Configuration.load_from_file(resource_id, config_file_path) if not interactive \ and ((enabled_resources is None and config.get_mode() != LIGHT_MODE) or (enabled_resources is not None and resource_id not in enabled_resources)): sys.stdout.write('Resource %s is not tested in ' 'non-interactive mode\n' % resource_id) continue # skip login/password ask if interactive: if enabled_resources is None: sys.stdout.write("Do you want to test the resource " "%s (Y/n) ? " % resource_id) sys.stdout.flush() test_resource = sys.stdin.readline() if test_resource.strip() in ['no', 'n', 'N', 'No', 'NO']: # Skip the resource sys.stdout.write('Resource %s is not tested \n' % resource_id) sys.stdout.flush() continue enable_resources.append(resource_id) (login, password) = get_user_id(resource_id, config) WorkflowTest.resource_pass[resource_id] = (login, password) else: if resource_id not in enabled_resources: continue (login, password) = WorkflowTest.resource_pass[resource_id] else: (login, password) = get_user_id(resource_id, config, interactive=interactive) if config.get_mode() == LIGHT_MODE: # use a temporary sqlite database in soma-workflow to avoid # concurrent access problems tmpdb = tempfile.mkstemp('.db', prefix='swf_') os.close(tmpdb[0]) os.unlink(tmpdb[1]) # and so on for transfers / stdio files directory tmptrans = tempfile.mkdtemp(prefix='swf_') config._database_file = tmpdb[1] config._transfered_file_dir = tmptrans wf_controller = None try: with suppress_stdout(debug): wf_controller = WorkflowController(resource_id, login, password, config=config) cls.setup_wf_controller(wf_controller) allowed_config = cls.allowed_config[:] for configuration in cls.allowed_config: if config.get_mode() != configuration[0]: allowed_config.remove(configuration) if len(allowed_config) == 0: sys.stdout.write( "No tests available for the resource %s \n" % resource_id) for configuration in allowed_config: (mode, file_system) = configuration sys.stdout.write( "\n---------------------------------------\n") sys.stdout.write("Mode : " + mode + '\n') sys.stdout.write("File system : " + file_system + '\n') cls.setup_path_management(file_system) if file_system in (cls.SHARED_RESOURCE_PATH, cls.SHARED_TRANSFER) \ and not config.get_path_translation(): sys.stdout.write( "Paths translation unavailable - not testing " "this case\n") sys.stdout.flush() continue suite_list = [] list_tests = [] for test in dir(cls): prefix = "test_" if len(test) < len(prefix): continue if test[0:len(prefix)] == prefix: list_tests.append(test) suite_list.append( unittest.TestSuite(list(map(cls, list_tests)))) alltests = unittest.TestSuite(suite_list) with suppress_stdout(debug): res = unittest.TextTestRunner( verbosity=2).run(alltests) sys.stdout.flush() sys.stdout.write("after test\n") if len(res.errors) != 0 or len(res.failures) != 0: raise RuntimeError("tests failed.") finally: sys.stdout.write("del wf_controller") if wf_controller: wf_controller.stop_engine() del wf_controller cls.setup_wf_controller(None) # del WorkflowController sys.stdout.write("deleted.") if config.get_mode() == LIGHT_MODE: if not kwargs.get('keep_temporary', False): if os.path.exists(config._database_file): os.unlink(config._database_file) if os.path.exists(config._database_file + '-journal'): os.unlink(config._database_file + '-journal') shutil.rmtree(config._transfered_file_dir) else: print('temporary files kept:') print('databse file:', config._database_file) print('transfers:', config._transfered_file_dir) if interactive and enabled_resources is None: print('set enabled_resources') WorkflowTest.enabled_resources = enable_resources