def testGetAttrWorks(self):
     rbool(True).val
     rdouble(0.0).val
     rfloat(0.0).val
     rint(0).val
     rlong(0).val
     rtime(0).val
     rinternal(None).val
     robject(None).val
     rstring("").val
     rclass("").val
     rarray().val
     rlist().val
     rset().val
     rmap().val
Example #2
0
def handleParse(c):
    """
    Raises ParseExit if the client has the configuration property
    "omero.scripts.parse". If the value is anything other than "only",
    then the parameters will also be sent to the server.
    """
    parse = c.getProperty("omero.scripts.parse")
    if len(parse) > 0:  # TODO Add to omero/Constants.ice
        if parse != "only":
            c.createSession().detachOnDestroy()
            c.setOutput("omero.scripts.parse", rinternal(c.params))
        raise ParseExit(c.params)
    def testObjectCreationEqualsAndHash(self):

        # RBool
        true1 = rbool(True)
        true2 = rbool(True)
        false1 = rbool(False)
        false2 = rbool(False)
        assert true1 == true2
        assert false1 == false2
        assert true1.getValue()
        assert not false1.getValue()
        assert true1 == true2
        assert true1 != false1

        # RDouble
        double_zero1 = rdouble(0.0)
        double_zero2 = rdouble(0.0)
        double_notzero1 = rdouble(1.1)
        double_notzero1b = rdouble(1.1)
        double_notzero2 = rdouble(2.2)
        assert double_zero1.getValue() == 0.0
        assert double_notzero1.getValue() == 1.1
        assert double_zero1 == double_zero2
        assert double_zero1 != double_notzero1
        assert double_notzero1 == double_notzero1b
        assert double_notzero1 != double_notzero2

        # RFloat
        float_zero1 = rfloat(0.0)
        float_zero2 = rfloat(0.0)
        float_notzero1 = rfloat(1.1)
        float_notzero1b = rfloat(1.1)
        float_notzero2 = rfloat(2.2)
        assert float_zero1.getValue() == 0.0
        assert float_notzero1.getValue() == 1.1
        assert float_zero1 == float_zero2
        assert float_zero1 != float_notzero1
        assert float_notzero1 == float_notzero1b
        assert float_notzero1 != float_notzero2

        # RInt
        int_zero1 = rint(0)
        int_zero2 = rint(0)
        int_notzero1 = rint(1)
        int_notzero1b = rint(1)
        int_notzero2 = rint(2)
        assert int_zero1.getValue() == 0
        assert int_notzero1.getValue() == 1
        assert int_zero1 == int_zero2
        assert int_zero1 != int_notzero1
        assert int_notzero1 == int_notzero1b
        assert int_notzero1 != int_notzero2

        # RLong
        long_zero1 = rlong(0)
        long_zero2 = rlong(0)
        long_notzero1 = rlong(1)
        long_notzero1b = rlong(1)
        long_notzero2 = rlong(2)
        assert long_zero1.getValue() == 0
        assert long_notzero1.getValue() == 1
        assert long_zero1 == long_zero2
        assert long_zero1 != long_notzero1
        assert long_notzero1 == long_notzero1b
        assert long_notzero1 != long_notzero2

        # RTime
        time_zero1 = rtime(0)
        time_zero2 = rtime(0)
        time_notzero1 = rtime(1)
        time_notzero1b = rtime(1)
        time_notzero2 = rtime(2)
        assert time_zero1.getValue() == 0
        assert time_notzero1.getValue() == 1
        assert time_zero1 == time_zero2
        assert time_zero1 != time_notzero1
        assert time_notzero1 == time_notzero1b
        assert time_notzero1 != time_notzero2

        # RInternal
        internal_null1 = rinternal(None)
        internal_null2 = rinternal(None)
        internal_notnull1 = rinternal(omero.grid.JobParams())
        internal_notnull2 = rinternal(omero.grid.JobParams())
        assert internal_null1 == internal_null2
        assert internal_null1 == internal_null2
        assert internal_null1 != internal_notnull2
        assert internal_notnull1 == internal_notnull1
        assert internal_notnull1 != internal_notnull2

        # RObject
        object_null1 = robject(None)
        object_null2 = robject(None)
        object_notnull1 = robject(omero.model.ImageI())
        object_notnull2 = robject(omero.model.ImageI())
        assert object_null1 == object_null2
        assert object_null1 == object_null2
        assert object_null1 != object_notnull2
        assert object_notnull1 == object_notnull1
        assert object_notnull1 != object_notnull2

        # RString
        string_null1 = rstring(None)
        string_null2 = rstring(None)
        string_notnull1 = rstring("str1")
        string_notnull1b = rstring("str1")
        string_notnull2 = rstring("str2")
        assert string_null1 == string_null2
        assert string_null1 == string_null2
        assert string_null1 != string_notnull2
        assert string_notnull1 == string_notnull1
        assert string_notnull1 != string_notnull2
        assert string_notnull1 == string_notnull1b

        # RClass
        class_null1 = rclass(None)
        class_null2 = rclass(None)
        class_notnull1 = rclass("str1")
        class_notnull1b = rclass("str1")
        class_notnull2 = rclass("str2")
        assert class_null1 == class_null2
        assert class_null1 == class_null2
        assert class_null1 != class_notnull2
        assert class_notnull1 == class_notnull1
        assert class_notnull1 != class_notnull2
        assert class_notnull1 == class_notnull1b
    def testUnwrap(self):
        # NUMS plain
        assert 0 == unwrap(0)
        assert 1 == unwrap(1)
        assert 0.0 == unwrap(0.0)
        assert 1.0 == unwrap(1.0)
        # NUMS rtyped
        assert 0 == unwrap(rint(0))
        assert 0 == unwrap(rlong(0))
        assert 1 == unwrap(rint(1))
        assert 1 == unwrap(rlong(1))
        assert 0.0 == unwrap(rfloat(0.0))
        assert 0.0 == unwrap(rdouble(0.0))
        assert 1.0 == unwrap(rfloat(1.0))
        assert 1.0 == unwrap(rdouble(1.0))

        # STRINGS
        assert "" == unwrap("")
        assert "str" == unwrap("str")

        # BOOL
        assert True == unwrap(True)
        assert False == unwrap(False)
        assert True == unwrap(rbool(True))
        assert False == unwrap(rbool(False))

        # TIME
        # Bit odd, do we want the long for time, or transformed?
        assert 0 == unwrap(rtime(0))
        assert 1 == unwrap(rtime(1))

        # CLASS
        # same for class, should we map it?
        assert "k" == unwrap(rclass("k"))

        # INTERNAL
        color = omero.Color()
        assert color == unwrap(rinternal(color))

        # OBJECT
        image = omero.model.ImageI()
        assert image == unwrap(robject(image))

        # COLLECTIONS
        # empty
        assert [] == unwrap([])
        assert {} == unwrap({})
        assert set() == unwrap(set())
        # plain in collection
        assert [1] == unwrap([1])
        # rtype in collection
        assert [1] == unwrap([rint(1)])
        assert {"a": 1} == unwrap({"a": 1})
        # plain in rcollection ILLEGAL
        # assert [1] == unwrap(rlist([1]))
        # assert {"a":1} == unwrap(rmap({"a":1}))
        # rtype in rcollection
        assert [1] == unwrap(rlist([rint(1)]))
        assert {"a": 1} == unwrap(rmap({"a": rint(1)}))
        # rtype keys ILLEGAL
        # assert {"a":1} == unwrap(rmap({rstring("a"):rint(1)}))
        # recursion, ticket:1977
        m1 = rmap({"a": rint(1)})
        m1.val["m1"] = m1
        m2 = {"a": 1}
        m2["m1"] = m2
        unwrap(m1)
        assert m2["a"] == unwrap(m1)["a"]
        # Can't compare directly "maximum recursion depth exceeded in cmp"
        assert type(m2["m1"]) == type(unwrap(m1)["m1"])
 def testPassThroughNoneAndRTypes(self):
     """
     To prevent having to check for isintance(int,...) or
     isintance(RInt,...) all over the place, the static methods
     automatically check for acceptable
     types and simply pass them through. Similarly, the primitive types all
     check for None and return a null RType if necessary.
     """
     # Bool
     assert None == rbool(None)
     assert rbool(True) == rbool(rbool(True))
     assert rbool(True) == rbool(1)
     assert rbool(False) == rbool(0)
     # Double
     assert None == rdouble(None)
     assert rdouble(0.0) == rdouble(rdouble(0.0))
     assert rdouble(0.0) == rdouble(rdouble(0))
     assert rdouble(0.0) == rdouble(rdouble("0.0"))
     pytest.raises(ValueError, lambda: rdouble("string"))
     # Float
     assert None == rfloat(None)
     assert rfloat(0.0) == rfloat(rfloat(0.0))
     assert rfloat(0.0) == rfloat(rfloat(0))
     assert rfloat(0.0) == rfloat(rfloat("0.0"))
     pytest.raises(ValueError, lambda: rfloat("string"))
     # Long
     assert None == rlong(None)
     assert rlong(0) == rlong(rlong(0))
     assert rlong(0) == rlong(rlong(0.0))
     assert rlong(0) == rlong(rlong("0"))
     pytest.raises(ValueError, lambda: rlong("string"))
     # Time
     assert None == rtime(None)
     assert rtime(0) == rtime(rtime(0))
     assert rtime(0) == rtime(rtime(0.0))
     assert rtime(0) == rtime(rtime("0"))
     pytest.raises(ValueError, lambda: rtime("string"))
     # Int
     assert None == rint(None)
     assert rint(0) == rint(rint(0))
     assert rint(0) == rint(rint(0.0))
     assert rint(0) == rint(rint("0"))
     pytest.raises(ValueError, lambda: rint("string"))
     #
     # Starting here handling of null is different.
     #
     # String
     assert rstring("") == rstring(None)
     assert rstring("a") == rstring(rstring("a"))
     assert rstring("0") == rstring(0)
     # Class
     assert rclass("") == rclass(None)
     assert rclass("c") == rclass(rclass("c"))
     pytest.raises(ValueError, lambda: rclass(0))
     # Internal
     internal = omero.Internal()
     assert rinternal(None) == rinternal(None)
     assert rinternal(internal) == rinternal(rinternal(internal))
     pytest.raises(ValueError, lambda: rinternal("string"))
     # Object
     obj = omero.model.ImageI()
     assert robject(None) == robject(None)
     assert robject(obj) == robject(robject(obj))
     pytest.raises(ValueError, lambda: robject("string"))
     #
     # Same does not hold for collections
     #
     # Array
     assert rarray([]) == rarray(None)
     # assert rarray(obj) == rarray(rarray(obj))
     # pytest.raises(ValueError, lambda : rarray("string"))
     # List
     assert rlist([]) == rlist(None)
     # assert rlist(obj) == rlist(rlist(obj))
     # pytest.raises(ValueError, lambda : rlist("string"))
     # Set
     assert rset([]) == rset(None)
     # assert rset(obj) == rset(rset(obj))
     # pytest.raises(ValueError, lambda : rset("string"))
     # Map
     assert rmap({}) == rmap(None)
Example #6
0
    def testUnwrap(self):
        # NUMS plain
        assert 0 == unwrap(0)
        assert 1 == unwrap(1)
        assert 0.0 == unwrap(0.0)
        assert 1.0 == unwrap(1.0)
        # NUMS rtyped
        assert 0 == unwrap(rint(0))
        assert 0 == unwrap(rlong(0))
        assert 1 == unwrap(rint(1))
        assert 1 == unwrap(rlong(1))
        assert 0.0 == unwrap(rfloat(0.0))
        assert 0.0 == unwrap(rdouble(0.0))
        assert 1.0 == unwrap(rfloat(1.0))
        assert 1.0 == unwrap(rdouble(1.0))

        # STRINGS
        assert "" == unwrap("")
        assert "str" == unwrap("str")

        # BOOL
        assert True == unwrap(True)
        assert False == unwrap(False)
        assert True == unwrap(rbool(True))
        assert False == unwrap(rbool(False))

        # TIME
        # Bit odd, do we want the long for time, or transformed?
        assert 0 == unwrap(rtime(0))
        assert 1 == unwrap(rtime(1))

        # CLASS
        # same for class, should we map it?
        assert "k" == unwrap(rclass("k"))

        # INTERNAL
        color = omero.Color()
        assert color == unwrap(rinternal(color))

        # OBJECT
        image = omero.model.ImageI()
        assert image == unwrap(robject(image))

        # COLLECTIONS
        # empty
        assert [] == unwrap([])
        assert {} == unwrap({})
        assert set() == unwrap(set())
        # plain in collection
        assert [1] == unwrap([1])
        # rtype in collection
        assert [1] == unwrap([rint(1)])
        assert {"a": 1} == unwrap({"a": 1})
        # plain in rcollection ILLEGAL
        # assert [1] == unwrap(rlist([1]))
        # assert {"a":1} == unwrap(rmap({"a":1}))
        # rtype in rcollection
        assert [1] == unwrap(rlist([rint(1)]))
        assert {"a": 1} == unwrap(rmap({"a": rint(1)}))
        # rtype keys ILLEGAL
        # assert {"a":1} == unwrap(rmap({rstring("a"):rint(1)}))
        # recursion, ticket:1977
        m1 = rmap({"a": rint(1)})
        m1.val["m1"] = m1
        m2 = {"a": 1}
        m2["m1"] = m2
        unwrap(m1)
        assert m2["a"] == unwrap(m1)["a"]
        # Can't compare directly "maximum recursion depth exceeded in cmp"
        assert type(m2["m1"]) == type(unwrap(m1)["m1"])
Example #7
0
 def testPassThroughNoneAndRTypes(self):
     """
     To prevent having to check for isintance(int,...) or
     isintance(RInt,...) all over the place, the static methods
     automatically check for acceptable
     types and simply pass them through. Similarly, the primitive types all
     check for None and return a null RType if necessary.
     """
     # Bool
     assert None == rbool(None)
     assert rbool(True) == rbool(rbool(True))
     assert rbool(True) == rbool(1)
     assert rbool(False) == rbool(0)
     # Double
     assert None == rdouble(None)
     assert rdouble(0.0) == rdouble(rdouble(0.0))
     assert rdouble(0.0) == rdouble(rdouble(0))
     assert rdouble(0.0) == rdouble(rdouble("0.0"))
     pytest.raises(ValueError, lambda: rdouble("string"))
     # Float
     assert None == rfloat(None)
     assert rfloat(0.0) == rfloat(rfloat(0.0))
     assert rfloat(0.0) == rfloat(rfloat(0))
     assert rfloat(0.0) == rfloat(rfloat("0.0"))
     pytest.raises(ValueError, lambda: rfloat("string"))
     # Long
     assert None == rlong(None)
     assert rlong(0) == rlong(rlong(0))
     assert rlong(0) == rlong(rlong(0.0))
     assert rlong(0) == rlong(rlong("0"))
     pytest.raises(ValueError, lambda: rlong("string"))
     # Time
     assert None == rtime(None)
     assert rtime(0) == rtime(rtime(0))
     assert rtime(0) == rtime(rtime(0.0))
     assert rtime(0) == rtime(rtime("0"))
     pytest.raises(ValueError, lambda: rtime("string"))
     # Int
     assert None == rint(None)
     assert rint(0) == rint(rint(0))
     assert rint(0) == rint(rint(0.0))
     assert rint(0) == rint(rint("0"))
     pytest.raises(ValueError, lambda: rint("string"))
     #
     # Starting here handling of null is different.
     #
     # String
     assert rstring("") == rstring(None)
     assert rstring("a") == rstring(rstring("a"))
     assert rstring("0") == rstring(0)
     # Class
     assert rclass("") == rclass(None)
     assert rclass("c") == rclass(rclass("c"))
     pytest.raises(ValueError, lambda: rclass(0))
     # Internal
     internal = omero.Internal()
     assert rinternal(None) == rinternal(None)
     assert rinternal(internal) == rinternal(rinternal(internal))
     pytest.raises(ValueError, lambda: rinternal("string"))
     # Object
     obj = omero.model.ImageI()
     assert robject(None) == robject(None)
     assert robject(obj) == robject(robject(obj))
     pytest.raises(ValueError, lambda: robject("string"))
     #
     # Same does not hold for collections
     #
     # Array
     assert rarray([]) == rarray(None)
     # assert rarray(obj) == rarray(rarray(obj))
     # pytest.raises(ValueError, lambda : rarray("string"))
     # List
     assert rlist([]) == rlist(None)
     # assert rlist(obj) == rlist(rlist(obj))
     # pytest.raises(ValueError, lambda : rlist("string"))
     # Set
     assert rset([]) == rset(None)
     # assert rset(obj) == rset(rset(obj))
     # pytest.raises(ValueError, lambda : rset("string"))
     # Map
     assert rmap({}) == rmap(None)