From c126a7ac20a8f02cef54132707874f8b85c240e8 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Fri, 29 Nov 2019 18:05:32 +0000 Subject: [PATCH] Restore casting a boolean param to str when comparing with one Broken in https://github.com/galaxyproject/galaxy/pull/9047 --- lib/galaxy/tools/wrappers.py | 4 ++++ test/unit/tools/test_wrappers.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/tools/wrappers.py b/lib/galaxy/tools/wrappers.py index 3812ec886015..a8b59a62915e 100644 --- a/lib/galaxy/tools/wrappers.py +++ b/lib/galaxy/tools/wrappers.py @@ -89,6 +89,8 @@ def _get_cast_value(self): return cast.get(self.input.type, str)(self) def __eq__(self, other): + if self.input.type == 'boolean' and isinstance(other, string_types): + return str(self) == other return self._get_cast_value() == other def __ne__(self, other): @@ -112,6 +114,8 @@ def __getattr__(self, key): return getattr(self.value, key) def __gt__(self, other): + if self.input.type == 'boolean' and isinstance(other, string_types): + return str(self) > other return self._get_cast_value() > other def __int__(self): diff --git a/test/unit/tools/test_wrappers.py b/test/unit/tools/test_wrappers.py index 929823ac2451..9bf91d19fcfd 100644 --- a/test/unit/tools/test_wrappers.py +++ b/test/unit/tools/test_wrappers.py @@ -5,6 +5,7 @@ from galaxy.datatypes.metadata import MetadataSpecCollection from galaxy.jobs.datasets import DatasetPath from galaxy.tools.parameters.basic import ( + BooleanToolParameter, DrillDownSelectToolParameter, FloatToolParameter, IntegerToolParameter, @@ -89,10 +90,12 @@ def valuewrapper(tool, value, paramtype): if paramtype == "integer": parameter = IntegerToolParameter(tool, XML('')) elif paramtype == "text": - parameter = TextToolParameter(tool, XML('')) + parameter = TextToolParameter(tool, XML('')) elif paramtype == "float": - parameter = FloatToolParameter(tool, XML('')) - return InputValueWrapper(parameter, str(value)) + parameter = FloatToolParameter(tool, XML('')) + elif paramtype == "boolean": + parameter = BooleanToolParameter(tool, XML('')) + return InputValueWrapper(parameter, value) @with_mock_tool @@ -106,6 +109,14 @@ def test_input_value_wrapper_comparison(tool): assert wrapper > 2 assert wrapper < 10 assert wrapper < 5.1 + wrapper = valuewrapper(tool, True, "boolean") + assert bool(wrapper) is True, wrapper + assert str(wrapper) == "truevalue" + assert wrapper == "truevalue" + wrapper = valuewrapper(tool, False, "boolean") + assert bool(wrapper) is False, wrapper + assert str(wrapper) == "falsevalue" + assert wrapper == "falsevalue" @with_mock_tool