Skip to content

Commit

Permalink
Merge pull request ome#5790 from joshmoore/script-fixes
Browse files Browse the repository at this point in the history
Script fixes
  • Loading branch information
joshmoore authored Jul 5, 2018
2 parents 62adef2 + 56248d4 commit 626beb5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
35 changes: 22 additions & 13 deletions components/tools/OmeroPy/src/omero/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Point(Type):
Wraps an rinternal(Point)
"""
PROTOTYPE_FUNCTION = rinternal
PROTOTYPE_FUNCTION = omero.Point
PROTOTYPE_DEFAULT = omero.Point


class Plane(Type):
Expand Down Expand Up @@ -508,15 +508,15 @@ def parse_input(input_string, params):
(omero.RLong, omero.RString, omero.RInt,
omero.RTime, omero.RDouble, omero.RFloat)):
val = param.prototype.__class__(val)
elif isinstance(param.prototype, omero.RList):
elif isinstance(param.prototype, (omero.RList, omero.RSet)):
rmethod = omero.rtypes.rlist
rwrap = omero.rtypes.wrap
if isinstance(param.prototype, omero.RSet):
rmethod = omero.rtypes.rset
if len(param.prototype.val) > 0:
rwrap = param.prototype.val[0].__class__
items = val.split(",")
if len(param.prototype.val) == 0:
# Don't know what needs to be added here, so calling wrap
# which will produce an rlist of rstrings.
val = omero.rtypes.wrap(items)
else:
p = param.prototype.val[0]
val = omero.rtypes.rlist([p.__class__(x) for x in items])
val = rmethod([rwrap(x) for x in items])
elif isinstance(param.prototype, omero.RObject):
try:
parts2 = val.split(":")
Expand Down Expand Up @@ -616,10 +616,19 @@ def compare_proto(key, proto, input, cache=None):
cache[id(proto)] = True
cache[id(input)] = True

itype = input is None and None or input.__class__
ptype = proto is None and None or proto.__class__

if not isinstance(input, ptype):
itype = None
ptype = None
both_collection = False
if input is not None:
itype = input.__class__
both_collection = isinstance(input, omero.RCollection)
if proto is not None:
ptype = proto.__class__
both_collection &= isinstance(proto, omero.RCollection)

# see https://github.com/openmicroscopy/openmicroscopy/issues/5788
# accept RSets as RLists and vice versa
if not (both_collection or isinstance(input, ptype)):
return error_msg("Wrong type", key, "%s != %s", itype, ptype)

# Now recurse if a collection type
Expand Down
33 changes: 32 additions & 1 deletion components/tools/OmeroPy/test/unit/scriptstest/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import omero

from omero.grid import JobParams
from omero.scripts import String, List, Bool, Long, MissingInputs, ParseExit
from omero.scripts import (
String, List, Bool, Long, Set,
MissingInputs, ParseExit, compare_proto)
from omero.scripts import client, parse_inputs, validate_inputs, parse_text
from omero.scripts import parse_file, group_params, rlong, rint, wrap, unwrap

Expand Down Expand Up @@ -313,6 +315,13 @@ def testParseInputsLongList(self):
assert 1 == rv["a"].val[0].val
assert 2 == rv["a"].val[1].val

def testParseInputsStringSetIsDefault(self):
params = JobParams()
params.inputs = {"a": Set("a", optional=False)}
rv = parse_inputs(["a=1"], params)
assert isinstance(rv["a"], omero.RSet)
assert "1" == rv["a"].val[0].val

def testParseInputsStringListIsDefault(self):
params = JobParams()
params.inputs = {"a": List("a", optional=False)}
Expand Down Expand Up @@ -362,3 +371,25 @@ def testParseIntList(self):
assert isinstance(x, omero.RInt)
assert 1 == rv[0].val
assert 2 == rv[1].val

def testParseIntSet(self):
"""
see ticket:7003
"""
params = JobParams()
a = Set("Channels").ofType(rint(0))
params.inputs = {"a": a}

rv = parse_inputs(["a=1,2"], params)["a"].val
for x in rv:
assert isinstance(x, omero.RInt)
assert 1 == rv[0].val
assert 2 == rv[1].val

def testCompareProto(self):
"""
https://github.com/openmicroscopy/openmicroscopy/issues/5788
"""
s = omero.rtypes.rset()
l = omero.rtypes.rlist()
assert not compare_proto("test", s, l)
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@

import omero
from omero.scripts import Long, List, validate_inputs
from omero.rtypes import rmap, rint, rlong, rstring, rlist, unwrap
from omero.rtypes import rmap, rint, rlong, rstring, rlist, rset, unwrap


class TestPrototypes(object):

def testRSetRInt(self):
params = omero.grid.JobParams()
param = omero.grid.Param()
param.prototype = rset(rint(0))
params.inputs = {"a": param}

input = rset(rint(1))
inputs = {"a": input}
assert "" == validate_inputs(params, inputs)

# Nested lists
def testRListRInt(self):
params = omero.grid.JobParams()
Expand Down

0 comments on commit 626beb5

Please sign in to comment.