Previous changeset 124:f267ed4a3026 (2021-01-08) Next changeset 126:def0f754ee1b (2021-03-26) |
Commit message:
Uploaded |
removed:
toolfactory/galaxy-tool-test |
b |
diff -r f267ed4a3026 -r 2dbb412af425 toolfactory/galaxy-tool-test --- a/toolfactory/galaxy-tool-test Fri Jan 08 06:57:35 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
b'@@ -1,457 +0,0 @@\n-#!/usr/bin/env python\n-\n-import argparse\n-import datetime as dt\n-import json\n-import logging\n-import os\n-import sys\n-import tempfile\n-from collections import namedtuple\n-from concurrent.futures import thread, ThreadPoolExecutor\n-\n-import yaml\n-\n-from galaxy.tool_util.verify.interactor import (\n- DictClientTestConfig,\n- GalaxyInteractorApi,\n- verify_tool,\n-)\n-\n-DESCRIPTION = """Script to quickly run a tool test against a running Galaxy instance."""\n-DEFAULT_SUITE_NAME = "Galaxy Tool Tests"\n-ALL_TESTS = -1\n-ALL_TOOLS = "*"\n-ALL_VERSION = "*"\n-LATEST_VERSION = None\n-\n-\n-TestReference = namedtuple("TestReference", ["tool_id", "tool_version", "test_index"])\n-TestException = namedtuple("TestException", ["tool_id", "exception", "was_recorded"])\n-\n-\n-class Results:\n-\n- def __init__(self, default_suitename, test_json, append=False):\n- self.test_json = test_json or "-"\n- test_results = []\n- test_exceptions = []\n- suitename = default_suitename\n- if append:\n- assert test_json != "-"\n- with open(test_json) as f:\n- previous_results = json.load(f)\n- test_results = previous_results["tests"]\n- if "suitename" in previous_results:\n- suitename = previous_results["suitename"]\n- self.test_results = test_results\n- self.test_exceptions = test_exceptions\n- self.suitename = suitename\n-\n- def register_result(self, result):\n- self.test_results.append(result)\n-\n- def register_exception(self, test_exception):\n- self.test_exceptions.append(test_exception)\n-\n- def already_successful(self, test_reference):\n- test_id = _test_id_for_reference(test_reference)\n- for test_result in self.test_results:\n- if test_result.get(\'id\') != test_id:\n- continue\n-\n- has_data = test_result.get(\'has_data\', False)\n- if has_data:\n- test_data = test_result.get("data", {})\n- if \'status\' in test_data and test_data[\'status\'] == \'success\':\n- return True\n-\n- return False\n-\n- def write(self):\n- tests = sorted(self.test_results, key=lambda el: el[\'id\'])\n- n_passed, n_failures, n_skips = 0, 0, 0\n- n_errors = len([e for e in self.test_exceptions if not e.was_recorded])\n- for test in tests:\n- has_data = test.get(\'has_data\', False)\n- if has_data:\n- test_data = test.get("data", {})\n- if \'status\' not in test_data:\n- raise Exception(f"Test result data {test_data} doesn\'t contain a status key.")\n- status = test_data[\'status\']\n- if status == "success":\n- n_passed += 1\n- elif status == "error":\n- n_errors += 1\n- elif status == "skip":\n- n_skips += 1\n- elif status == "failure":\n- n_failures += 1\n- report_obj = {\n- \'version\': \'0.1\',\n- \'suitename\': self.suitename,\n- \'results\': {\n- \'total\': n_passed + n_failures + n_skips + n_errors,\n- \'errors\': n_errors,\n- \'failures\': n_failures,\n- \'skips\': n_skips,\n- },\n- \'tests\': tests,\n- }\n- if self.test_json == "-":\n- print(json.dumps(report_obj))\n- else:\n- with open(self.test_json, "w") as f:\n- json.dump(report_obj, f)\n-\n- def info_message(self):\n- messages = []\n- passed_tests = self._tests_with_status(\'success\')\n- messages.append("Passed tool tests ({}): {}".format(\n- len(passed_tests),\n- [t["id"] for t in passed_tests]\n- ))\n- failed_tests = self._tests_with_status(\'failure\')\n- messages.append("Failed tool tests ({}): {}".format(\n- len(failed_tests),\n-'..b' logger.setLevel(logging.DEBUG if verbose else logging.INFO)\n- logger.addHandler(console)\n-\n- if not log_file:\n- # delete = false is chosen here because it is always nice to have a log file\n- # ready if you need to debug. Not having the "if only I had set a log file"\n- # moment after the fact.\n- temp = tempfile.NamedTemporaryFile(prefix="ephemeris_", delete=False)\n- log_file = temp.name\n- file_handler = logging.FileHandler(log_file)\n- logger.addHandler(file_handler)\n- logger.info(f"Storing log file in: {log_file}")\n- return logger\n-\n-\n-def _arg_parser():\n- parser = argparse.ArgumentParser(description=DESCRIPTION)\n- parser.add_argument(\'-u\', \'--galaxy-url\', default="http://localhost:8080", help=\'Galaxy URL\')\n- parser.add_argument(\'-k\', \'--key\', default=None, help=\'Galaxy User API Key\')\n- parser.add_argument(\'-a\', \'--admin-key\', default=None, help=\'Galaxy Admin API Key\')\n- parser.add_argument(\'--force_path_paste\', default=False, action="store_true", help=\'This requires Galaxy-side config option "allow_path_paste" enabled. Allows for fetching test data locally. Only for admins.\')\n- parser.add_argument(\'-t\', \'--tool-id\', default=ALL_TOOLS, help=\'Tool ID\')\n- parser.add_argument(\'--tool-version\', default=None, help=\'Tool Version (if tool id supplied). Defaults to just latest version, use * to test all versions\')\n- parser.add_argument(\'-i\', \'--test-index\', default=ALL_TESTS, type=int, help=\'Tool Test Index (starting at 0) - by default all tests will run.\')\n- parser.add_argument(\'-o\', \'--output\', default=None, help=\'directory to dump outputs to\')\n- parser.add_argument(\'--append\', default=False, action="store_true", help="Extend a test record json (created with --output-json) with additional tests.")\n- parser.add_argument(\'--skip-successful\', default=False, action="store_true", help="When used with --append, skip previously run successful tests.")\n- parser.add_argument(\'-j\', \'--output-json\', default=None, help=\'output metadata json\')\n- parser.add_argument(\'--verbose\', default=False, action="store_true", help="Verbose logging.")\n- parser.add_argument(\'-c\', \'--client-test-config\', default=None, help="Test config YAML to help with client testing")\n- parser.add_argument(\'--suite-name\', default=DEFAULT_SUITE_NAME, help="Suite name for tool test output")\n- parser.add_argument(\'--with-reference-data\', dest="with_reference_data", default=False, action="store_true")\n- parser.add_argument(\'--skip-with-reference-data\', dest="with_reference_data", action="store_false", help="Skip tests the Galaxy server believes use data tables or loc files.")\n- parser.add_argument(\'--history-per-suite\', dest="history_per_test_case", default=False, action="store_false", help="Create new history per test suite (all tests in same history).")\n- parser.add_argument(\'--history-per-test-case\', dest="history_per_test_case", action="store_true", help="Create new history per test case.")\n- parser.add_argument(\'--no-history-cleanup\', default=False, action="store_true", help="Perserve histories created for testing.")\n- parser.add_argument(\'--parallel-tests\', default=1, type=int, help="Parallel tests.")\n- parser.add_argument(\'--retries\', default=0, type=int, help="Retry failed tests.")\n- parser.add_argument(\'--page-size\', default=0, type=int, help="If positive, use pagination and just run one \'page\' to tool tests.")\n- parser.add_argument(\'--page-number\', default=0, type=int, help="If page size is used, run this \'page\' of tests - starts with 0.")\n- parser.add_argument(\'--download-attempts\', default=1, type=int, help="Galaxy may return a transient 500 status code for download if test results are written but not yet accessible.")\n- parser.add_argument(\'--download-sleep\', default=1, type=int, help="If download attempts is greater than 1, the amount to sleep between download attempts.")\n- return parser\n-\n-\n-if __name__ == "__main__":\n- main()\n' |