Skip to content

Commit

Permalink
Merge pull request #9052 from nsoranzo/release_19.05_followup_on_9047
Browse files Browse the repository at this point in the history
[19.05] Restore casting a boolean param to str when comparing with one
  • Loading branch information
nsoranzo authored Nov 30, 2019
2 parents c0338b3 + c126a7a commit 157bb02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
17 changes: 14 additions & 3 deletions test/unit/tools/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -89,10 +90,12 @@ def valuewrapper(tool, value, paramtype):
if paramtype == "integer":
parameter = IntegerToolParameter(tool, XML('<param name="blah" type="integer" value="10" min="0" />'))
elif paramtype == "text":
parameter = TextToolParameter(tool, XML('<param name="blah" type="text" value="10"/>'))
parameter = TextToolParameter(tool, XML('<param name="blah" type="text" value="foo"/>'))
elif paramtype == "float":
parameter = FloatToolParameter(tool, XML('<param name="bla" type="float" value="10"/>'))
return InputValueWrapper(parameter, str(value))
parameter = FloatToolParameter(tool, XML('<param name="blah" type="float" value="10.0"/>'))
elif paramtype == "boolean":
parameter = BooleanToolParameter(tool, XML('<param name="blah" type="boolean" truevalue="truevalue" falsevalue="falsevalue"/>'))
return InputValueWrapper(parameter, value)


@with_mock_tool
Expand All @@ -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
Expand Down

0 comments on commit 157bb02

Please sign in to comment.