From 03a4172680ced1a5667d7308fbc13dc50998209c Mon Sep 17 00:00:00 2001 From: Nic Herndon Date: Sat, 30 Jun 2018 23:06:42 +0000 Subject: [PATCH] Fixed bugs with unit test on Python 3 --- lib/galaxy/datatypes/binary.py | 2 +- lib/galaxy/tools/parser/xml.py | 3 ++- lib/galaxy/util/checkers.py | 2 +- test/unit/jobs/test_runner_params.py | 6 +++--- test/unit/tools/test_parsing.py | 6 +++--- test/unit/tools/test_tool_dependency_description.py | 2 +- test/unit/workflows/test_extract_summary.py | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/galaxy/datatypes/binary.py b/lib/galaxy/datatypes/binary.py index 254c8df25ed..a4eb0a9c3b8 100644 --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -683,7 +683,7 @@ class BcfUncompressed(Bcf): def sniff(self, filename): try: - header = open(filename).read(3) + header = open(filename, mode='rb').read(3) # The first 3 bytes of any BCF file are 'BCF', and the file is binary. if header == b'BCF': return True diff --git a/lib/galaxy/tools/parser/xml.py b/lib/galaxy/tools/parser/xml.py index 1cf79a2103d..c55594edea6 100644 --- a/lib/galaxy/tools/parser/xml.py +++ b/lib/galaxy/tools/parser/xml.py @@ -252,7 +252,8 @@ class XmlToolSource(ToolSource): data_dict[output_def.name] = output_def return output_def - map(_parse, out_elem.findall("data")) + for _ in out_elem.findall("data"): + _parse(_) for collection_elem in out_elem.findall("collection"): name = collection_elem.get("name") diff --git a/lib/galaxy/util/checkers.py b/lib/galaxy/util/checkers.py index 2d7eeefe493..191586a4b78 100644 --- a/lib/galaxy/util/checkers.py +++ b/lib/galaxy/util/checkers.py @@ -79,7 +79,7 @@ def check_gzip(file_path, check_content=True): # If the file is Bam, it should already have been detected as such, so we'll just check # for sff format. try: - header = gzip.open(file_path).read(4) + header = gzip.open(file_path, 'rb').read(4) if header == b'.sff': return (True, True) except Exception: diff --git a/test/unit/jobs/test_runner_params.py b/test/unit/jobs/test_runner_params.py index 3de98299204..96a73b8c400 100644 --- a/test/unit/jobs/test_runner_params.py +++ b/test/unit/jobs/test_runner_params.py @@ -21,7 +21,7 @@ def test_missing_parameter(): runners.RunnerParams(specs={}, params=dict(foo="bar")) except Exception as e: exception = e - assert exception.message == runners.JOB_RUNNER_PARAMETER_UNKNOWN_MESSAGE % "foo" + assert str(exception) == runners.JOB_RUNNER_PARAMETER_UNKNOWN_MESSAGE % "foo" def test_invalid_parameter(): @@ -30,7 +30,7 @@ def test_invalid_parameter(): runners.RunnerParams(specs=dict(foo=dict(valid=lambda x: x != "bar", defualt="baz")), params=dict(foo="bar")) except Exception as e: exception = e - assert exception.message == runners.JOB_RUNNER_PARAMETER_VALIDATION_FAILED_MESSAGE % "foo" + assert str(exception) == runners.JOB_RUNNER_PARAMETER_VALIDATION_FAILED_MESSAGE % "foo" def test_map_problem(): @@ -39,7 +39,7 @@ def test_map_problem(): runners.RunnerParams(specs=dict(foo=dict(map=lambda x: 1 / 0, default="baz")), params=dict(foo="bar")) except Exception as e: exception = e - assert exception.message == runners.JOB_RUNNER_PARAMETER_MAP_PROBLEM_MESSAGE % ("foo", "bar") + assert str(exception) == runners.JOB_RUNNER_PARAMETER_MAP_PROBLEM_MESSAGE % ("foo", "bar") def test_param_default(): diff --git a/test/unit/tools/test_parsing.py b/test/unit/tools/test_parsing.py index 7cae5aad073..0375d32b4ca 100644 --- a/test/unit/tools/test_parsing.py +++ b/test/unit/tools/test_parsing.py @@ -177,11 +177,11 @@ class XmlLoaderTestCase(BaseLoaderTestCase): def test_requirements(self): requirements, containers = self._tool_source.parse_requirements_and_containers() assert requirements[0].type == "package" - assert containers[0].identifier == "mycool/bwa" + assert list(containers)[0].identifier == "mycool/bwa" def test_outputs(self): outputs, output_collections = self._tool_source.parse_outputs(object()) - assert len(outputs) == 1 + assert len(outputs) == 1, outputs assert len(output_collections) == 0 def test_stdio(self): @@ -339,7 +339,7 @@ class YamlLoaderTestCase(BaseLoaderTestCase): page_sources = input_pages.page_sources assert len(page_sources) == 1 page_source = page_sources[0] - input_sources = page_source.parse_input_sources() + input_sources = list(page_source.parse_input_sources()) assert len(input_sources) == 2 def test_tests(self): diff --git a/test/unit/tools/test_tool_dependency_description.py b/test/unit/tools/test_tool_dependency_description.py index a9e75bd81e6..9dccd45beb4 100644 --- a/test/unit/tools/test_tool_dependency_description.py +++ b/test/unit/tools/test_tool_dependency_description.py @@ -35,7 +35,7 @@ def test_serialization(): assert result_requirement.version == "2.0" assert result_requirement.type == "package" - result_tool_shed_dependency = result_descript.installed_tool_dependencies[0] + result_tool_shed_dependency = list(result_descript.installed_tool_dependencies)[0] result_tool_shed_dependency.name = "tophat" result_tool_shed_dependency.version = "2.0" result_tool_shed_dependency.type = "package" diff --git a/test/unit/workflows/test_extract_summary.py b/test/unit/workflows/test_extract_summary.py index cb8a83df821..b9eef53e91a 100644 --- a/test/unit/workflows/test_extract_summary.py +++ b/test/unit/workflows/test_extract_summary.py @@ -55,7 +55,7 @@ class TestWorkflowExtractSummary(unittest.TestCase): assert len(job_dict) == 1 fake_job = job_dict.keys()[0] assert fake_job.id.startswith("fake_") - datasets = job_dict.values()[0] + datasets = list(job_dict.values())[0] assert datasets == [(None, hda)] def test_fake_job_hdca(self):