From dfba28a4435fcebfaf4d944ccddac564f795d3fb Mon Sep 17 00:00:00 2001 From: Bjoern Gruening Date: Mon, 28 Dec 2020 21:38:40 +0100 Subject: [PATCH] fix mutable arguments in tests --- test/functional/test_toolbox.py | 5 +++-- test/integration/test_job_resubmission.py | 6 ++++-- test/unit/jobs/test_mapper.py | 3 ++- test/unit/tools/test_actions.py | 6 ++++-- test/unit/tools/test_collect_primary_datasets.py | 3 ++- test/unit/tools/test_evaluation.py | 8 ++++++-- test/unit/workflows/test_workflow_progress.py | 3 ++- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/functional/test_toolbox.py b/test/functional/test_toolbox.py index 72a5bdef4bc..f7d701be18b 100644 --- a/test/functional/test_toolbox.py +++ b/test/functional/test_toolbox.py @@ -23,10 +23,11 @@ TOOL_TYPES_NO_TEST = (DataManagerTool, ) class ToolTestCase(DrivenFunctionalTestCase): """Abstract test case that runs tests based on a `galaxy.tools.test.ToolTest`.""" - def do_it(self, tool_id=None, tool_version=None, test_index=0, resource_parameters={}): + def do_it(self, tool_id=None, tool_version=None, test_index=0, resource_parameters=None): """ Run through a tool test case. """ + resource_parameters = resource_parameters or {} if tool_id is None: tool_id = self.tool_id assert tool_id @@ -71,7 +72,7 @@ def build_tests(app=None, G = globals() # Eliminate all previous tests from G. - for key, val in G.copy().items(): + for key in G.copy().keys(): if key.startswith('TestForTool_'): del G[key] diff --git a/test/integration/test_job_resubmission.py b/test/integration/test_job_resubmission.py index 35c96ffbd43..809eac31a4f 100644 --- a/test/integration/test_job_resubmission.py +++ b/test/integration/test_job_resubmission.py @@ -19,10 +19,12 @@ JOB_RESUBMISSION_PULSAR_JOB_CONFIG_FILE = os.path.join(SCRIPT_DIRECTORY, "resubm class _BaseResubmissionIntegerationTestCase(integration_util.IntegrationTestCase): framework_tool_and_types = True - def _assert_job_passes(self, tool_id="exit_code_oom", resource_parameters={}): + def _assert_job_passes(self, tool_id="exit_code_oom", resource_parameters=None): + resource_parameters = resource_parameters or {} self._run_tool_test(tool_id, resource_parameters=resource_parameters) - def _assert_job_fails(self, tool_id="exit_code_oom", resource_parameters={}): + def _assert_job_fails(self, tool_id="exit_code_oom", resource_parameters=None): + resource_parameters = resource_parameters or {} exception_thrown = False try: self._run_tool_test(tool_id, resource_parameters=resource_parameters) diff --git a/test/unit/jobs/test_mapper.py b/test/unit/jobs/test_mapper.py index f16be8fa728..be25c4ff077 100644 --- a/test/unit/jobs/test_mapper.py +++ b/test/unit/jobs/test_mapper.py @@ -143,7 +143,8 @@ def __mapper(tool_job_destination=TOOL_JOB_DESTINATION): return mapper -def __dynamic_destination(params={}): +def __dynamic_destination(params=None): + params = params or {} return JobDestination(runner="dynamic", params=params) diff --git a/test/unit/tools/test_actions.py b/test/unit/tools/test_actions.py index 3f7347ee286..83432cd3906 100644 --- a/test/unit/tools/test_actions.py +++ b/test/unit/tools/test_actions.py @@ -117,7 +117,7 @@ class DefaultToolActionTestCase(unittest.TestCase, tools_support.UsesApp, tools_ self._simple_execute() except UserActivationRequiredException: return - assert False, "Tool execution succeeded for inactive user!" + raise AssertionError("Tool execution succeeded for inactive user!") def __add_dataset(self, state='ok'): hda = model.HistoryDatasetAssociation() @@ -193,7 +193,9 @@ def test_determine_output_format(): __assert_output_format_is("fastqsolexa", change_on_metadata_output, [("i1", "txt"), ("i2", "txt")]) -def __assert_output_format_is(expected, output, input_extensions=[], param_context=[], add_collection=False): +def __assert_output_format_is(expected, output, input_extensions=None, param_context=None, add_collection=False): + input_extensions = input_extensions or {} + param_context = param_context or {} inputs = {} last_ext = "data" i = 1 diff --git a/test/unit/tools/test_collect_primary_datasets.py b/test/unit/tools/test_collect_primary_datasets.py index a675b6ff51d..b076bb7f6c5 100644 --- a/test/unit/tools/test_collect_primary_datasets.py +++ b/test/unit/tools/test_collect_primary_datasets.py @@ -386,7 +386,8 @@ class CollectPrimaryDatasetsTestCase(unittest.TestCase, tools_support.UsesApp, t self.job.history = self.history self.outputs = {DEFAULT_TOOL_OUTPUT: self.hda} - def _new_history(self, hdas=[], flush=True): + def _new_history(self, hdas=None, flush=True): + hdas = hdas or [] history = model.History() self.app.model.context.add(history) for hda in hdas: diff --git a/test/unit/tools/test_evaluation.py b/test/unit/tools/test_evaluation.py index fb21adcf911..54163c7a31a 100644 --- a/test/unit/tools/test_evaluation.py +++ b/test/unit/tools/test_evaluation.py @@ -233,10 +233,14 @@ class TestComputeEnvironment(SimpleComputeEnvironment): self, new_file_path, working_directory, - input_paths=['/galaxy/files/dataset_1.dat'], - output_paths=['/galaxy/files/dataset_2.dat'], + input_paths=None, + output_paths=None, unstructured_path_rewrites=None ): + if input_paths is None: + input_paths = ['/galaxy/files/dataset_1.dat'] + if output_paths is None: + output_paths = ['/galaxy/files/dataset_2.dat'] self._new_file_path = new_file_path self._working_directory = working_directory self._input_paths = input_paths diff --git a/test/unit/workflows/test_workflow_progress.py b/test/unit/workflows/test_workflow_progress.py index 4f6f9f2e9a6..c9a8ec0770b 100644 --- a/test/unit/workflows/test_workflow_progress.py +++ b/test/unit/workflows/test_workflow_progress.py @@ -218,7 +218,8 @@ class MockModuleInjector: def __init__(self, progress): self.progress = progress - def inject(self, step, step_args={}): + def inject(self, step, step_args=None): + step_args = step_args or {} step.module = MockModule(self.progress)