Skip to content

Commit

Permalink
Merge pull request #7826 from mvdbeek/fix_value_wrapper_comparison
Browse files Browse the repository at this point in the history
Fix InputValueWrapper gt/ge/lt/le comparisons
  • Loading branch information
jmchilton authored Apr 26, 2019
2 parents a13e9cb + 60d8710 commit c0291c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import tempfile
from functools import total_ordering

from six import string_types, text_type
from six.moves import shlex_quote
Expand Down Expand Up @@ -67,6 +68,7 @@ def __getattr__(self, key):
return getattr(self.obj, key)


@total_ordering
class InputValueWrapper(ToolParameterValueWrapper):
"""
Wraps an input so that __str__ gives the "param_dict" representation.
Expand Down Expand Up @@ -107,6 +109,16 @@ def __iter__(self):
def __getattr__(self, key):
return getattr(self.value, key)

def __gt__(self, other):
if isinstance(other, string_types):
return str(self) > other
elif isinstance(other, int):
return int(self) > other
elif isinstance(other, float):
return float(self) > other
else:
super(InputValueWrapper, self).__gt__(other)

def __int__(self):
return int(float(self))

Expand Down
6 changes: 6 additions & 0 deletions test/unit/tools/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def test_input_value_wrapper(tool):
parameter = IntegerToolParameter(tool, XML('<param name="blah" type="integer" value="10" min="0" />'))
wrapper = InputValueWrapper(parameter, "5")
assert str(wrapper) == "5"
assert int(wrapper) == 5
assert wrapper == "5"
assert wrapper == 5
assert wrapper == 5.0
assert wrapper > 2
assert wrapper < 10


def test_dataset_wrapper():
Expand Down

0 comments on commit c0291c4

Please sign in to comment.