def _test_tool(self, tool, test_user, test_user_api_key): if test_user_api_key is None: whoami = self.gi.make_get_request(self.gi.url + "/whoami").json() if whoami is not None: test_user_api_key = self.gi.key galaxy_interactor_kwds = { "galaxy_url": re.sub('/api', '', self.gi.url), "master_api_key": self.gi.key, "api_key": None, # TODO "keep_outputs_dir": '', } if test_user_api_key is None: galaxy_interactor_kwds["test_user"] = test_user galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) tool_id = tool["id"] tool_version = tool["version"] tool_test_dicts = galaxy_interactor.get_tool_tests( tool_id, tool_version=tool_version) test_indices = list(range(len(tool_test_dicts))) tool_test_results = [] tests_passed = [] test_exceptions = [] for test_index in test_indices: test_id = tool_id + "-" + str(test_index) def register(job_data): tool_test_results.append({ 'id': test_id, 'has_data': True, 'data': job_data, }) try: verify_tool(tool_id, galaxy_interactor, test_index=test_index, tool_version=tool_version, register_job_data=register, quiet=True) tests_passed.append(test_id) except Exception as e: test_exceptions.append((test_id, e)) Results = namedtuple( "Results", ["tool_test_results", "tests_passed", "test_exceptions"]) return Results(tool_test_results=tool_test_results, tests_passed=tests_passed, test_exceptions=test_exceptions)
def run_tool_test(self, tool_id, index=0, resource_parameters={}): host, port, url = target_url_parts() galaxy_interactor_kwds = { "galaxy_url": url, "master_api_key": get_master_api_key(), "api_key": get_user_api_key(), "keep_outputs_dir": None, } galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) verify_tool(tool_id=tool_id, test_index=index, galaxy_interactor=galaxy_interactor, resource_parameters=resource_parameters)
def _get_interactor(self, test_user, test_user_api_key): if test_user_api_key is None: whoami = self.gi.make_get_request(self.gi.url + "/whoami").json() if whoami is not None: test_user_api_key = self.gi.key galaxy_interactor_kwds = { "galaxy_url": re.sub('/api', '', self.gi.url), "master_api_key": self.gi.key, "api_key": test_user_api_key, # TODO "keep_outputs_dir": '', } if test_user_api_key is None: galaxy_interactor_kwds["test_user"] = test_user galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) return galaxy_interactor
def main(argv=None): if argv is None: argv = sys.argv[1:] args = _arg_parser().parse_args(argv) galaxy_interactor_kwds = { "galaxy_url": args.galaxy_url, "master_api_key": args.admin_key, "api_key": args.key, "keep_outputs_dir": args.output, } tool_id = args.tool_id tool_version = args.tool_version galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) raw_test_index = args.test_index if raw_test_index == ALL_TESTS: tool_test_dicts = galaxy_interactor.get_tool_tests( tool_id, tool_version=tool_version) test_indices = list(range(len(tool_test_dicts))) else: test_indices = [int(raw_test_index)] test_results = [] if args.append: with open(args.output_json, "r") as f: previous_results = json.load(f) test_results = previous_results["tests"] exceptions = [] verbose = args.verbose for test_index in test_indices: if tool_version: tool_id_and_version = "%s/%s" % (tool_id, tool_version) else: tool_id_and_version = tool_id test_identifier = "tool %s test # %d" % (tool_id_and_version, test_index) def register(job_data): test_results.append({ 'id': tool_id + "-" + str(test_index), 'has_data': True, 'data': job_data, }) try: verify_tool(tool_id, galaxy_interactor, test_index=test_index, tool_version=tool_version, register_job_data=register, quiet=not verbose, force_path_paste=args.force_path_paste) if verbose: print("%s passed" % test_identifier) except Exception as e: if verbose: print("%s failed, %s" % (test_identifier, e)) exceptions.append(e) report_obj = { 'version': '0.1', 'tests': test_results, } output_json = args.output_json if output_json: if args.output_json == "-": assert not args.append print(json.dumps(report_obj)) else: with open(args.output_json, "w") as f: json.dump(report_obj, f) if exceptions: raise exceptions[0]
def build_tests(app=None, testing_shed_tools=False, master_api_key=None, user_api_key=None, name_prefix="TestForTool_", baseclass=ToolTestCase, create_admin=False, user_email=None, G=None, contains=None): """ If the module level variable `toolbox` is set, generate `ToolTestCase` classes for all of its tests and put them into this modules globals() so they can be discovered by nose. """ # galaxy_interactor = None # if app is None: host, port, url = target_url_parts() keep_outputs_dir = setup_keep_outdir() galaxy_interactor_kwds = { "galaxy_url": url, "master_api_key": master_api_key, "api_key": user_api_key, "keep_outputs_dir": keep_outputs_dir, "user_api_key_is_admin_key": True, } if create_admin and not user_api_key: galaxy_interactor_kwds['test_user'] = user_email galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) if not G: # Push all the toolbox tests to module level G = globals() # Eliminate all previous tests from G. for key, val in G.copy().items(): if key.startswith('TestForTool_'): del G[key] tests_summary = galaxy_interactor.get_tests_summary() for tool_id, tool_summary in tests_summary.items(): # Create a new subclass of ToolTestCase, dynamically adding methods # named test_tool_XXX that run each test defined in the tool config. if contains and contains not in tool_id: continue name = name_prefix + tool_id.replace(' ', '_') baseclasses = (baseclass, ) namespace = dict() all_versions_test_count = 0 for tool_version, version_summary in tool_summary.items(): count = version_summary["count"] for i in range(count): test_function_name = 'test_tool_%06d' % all_versions_test_count def make_test_method(tool_version, test_index): def test_tool(self): self.do_it(tool_version=tool_version, test_index=test_index) test_tool.__name__ = test_function_name return test_tool test_method = make_test_method(tool_version, i) test_method.__doc__ = "( %s ) > Test-%d" % (tool_id, all_versions_test_count + 1) namespace[test_function_name] = test_method namespace['tool_id'] = tool_id namespace["galaxy_interactor"] = galaxy_interactor namespace['master_api_key'] = master_api_key namespace['user_api_key'] = user_api_key or galaxy_interactor.api_key namespace['test_count'] = count all_versions_test_count += 1 # Create new class object, with name name, derived # from baseclasses (which should be a tuple of classes) and with namespace dict. new_class_obj = type(str(name), baseclasses, namespace) G[name] = new_class_obj return G
def build_tests(app=None, testing_shed_tools=False, master_api_key=None, user_api_key=None, name_prefix="TestForTool_", baseclass=ToolTestCase, create_admin=False, user_email=None, G=None, contains=None): """ If the module level variable `toolbox` is set, generate `ToolTestCase` classes for all of its tests and put them into this modules globals() so they can be discovered by nose. """ # galaxy_interactor = None # if app is None: host, port, url = target_url_parts() keep_outputs_dir = setup_keep_outdir() galaxy_interactor_kwds = { "galaxy_url": url, "master_api_key": master_api_key, "api_key": user_api_key, "keep_outputs_dir": keep_outputs_dir, "user_api_key_is_admin_key": True, } if create_admin and not user_api_key: galaxy_interactor_kwds['test_user'] = user_email galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) if not G: # Push all the toolbox tests to module level G = globals() # Eliminate all previous tests from G. for key, val in G.copy().items(): if key.startswith('TestForTool_'): del G[key] tests_summary = galaxy_interactor.get_tests_summary() for tool_id, tool_summary in tests_summary.items(): # Create a new subclass of ToolTestCase, dynamically adding methods # named test_tool_XXX that run each test defined in the tool config. if contains and contains not in tool_id: continue name = name_prefix + tool_id.replace(' ', '_') baseclasses = (baseclass, ) namespace = dict() all_versions_test_count = 0 for tool_version, version_summary in tool_summary.items(): count = version_summary["count"] for i in range(count): test_function_name = 'test_tool_%06d' % all_versions_test_count def make_test_method(tool_version, test_index): def test_tool(self): self.do_it(tool_version=tool_version, test_index=test_index) test_tool.__name__ = test_function_name return test_tool test_method = make_test_method(tool_version, i) test_method.__doc__ = "( %s ) > Test-%d" % ( tool_id, all_versions_test_count + 1) namespace[test_function_name] = test_method namespace['tool_id'] = tool_id namespace["galaxy_interactor"] = galaxy_interactor namespace['master_api_key'] = master_api_key namespace[ 'user_api_key'] = user_api_key or galaxy_interactor.api_key namespace['test_count'] = count all_versions_test_count += 1 # Create new class object, with name name, derived # from baseclasses (which should be a tuple of classes) and with namespace dict. new_class_obj = type(str(name), baseclasses, namespace) G[name] = new_class_obj return G
def main(argv=None): if argv is None: argv = sys.argv[1:] args = _arg_parser().parse_args(argv) galaxy_interactor_kwds = { "galaxy_url": args.galaxy_url, "master_api_key": args.admin_key, "api_key": args.key, "keep_outputs_dir": args.output, } tool_id = args.tool_id tool_version = args.tool_version galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) raw_test_index = args.test_index if raw_test_index == ALL_TESTS: tool_test_dicts = galaxy_interactor.get_tool_tests(tool_id, tool_version=tool_version) test_indices = list(range(len(tool_test_dicts))) else: test_indices = [int(raw_test_index)] test_results = [] if args.append: with open(args.output_json, "r") as f: previous_results = json.load(f) test_results = previous_results["tests"] exceptions = [] verbose = args.verbose for test_index in test_indices: if tool_version: tool_id_and_version = "%s/%s" % (tool_id, tool_version) else: tool_id_and_version = tool_id test_identifier = "tool %s test # %d" % (tool_id_and_version, test_index) def register(job_data): test_results.append({ 'id': tool_id + "-" + str(test_index), 'has_data': True, 'data': job_data, }) try: verify_tool( tool_id, galaxy_interactor, test_index=test_index, tool_version=tool_version, register_job_data=register, quiet=not verbose ) if verbose: print("%s passed" % test_identifier) except Exception as e: if verbose: print("%s failed, %s" % (test_identifier, e)) exceptions.append(e) report_obj = { 'version': '0.1', 'tests': test_results, } output_json = args.output_json if output_json: if args.output_json == "-": assert not args.append print(json.dumps(report_obj)) else: with open(args.output_json, "w") as f: json.dump(report_obj, f) if exceptions: raise exceptions[0]