示例#1
0
def test_unmarshall():
    from riffle.cumin import unmarshall

    # types set to None just returns the arguments
    assert unmarshall([42], None) == (42, )

    assert unmarshall([1, 2], [int, int]) == (1, 2)
    assert unmarshall([1, "a"], [int, str]) == (1, "a")
示例#2
0
def test_unmarshall_object():
    from riffle.cumin import unmarshall
    from riffle.model import ModelObject

    class Person(ModelObject):
        name = str

    dale = Person(name="Dale")
    dale_s = dale._serialize()

    lance = Person(name="Lance")
    lance_s = lance._serialize()

    # Person objects as arguments
    assert unmarshall([dale_s], [Person]) == (dale, )
    assert unmarshall([dale_s, lance_s], [Person, Person]) == (dale, lance)

    # List of Person objects as an argument
    assert unmarshall([[]], [[Person]]) == ([], )
    assert unmarshall([[dale_s]], [[Person]]) == ([dale], )
    assert unmarshall([[dale_s, lance_s]], [[Person]]) == ([dale, lance], )
示例#3
0
文件: crust.py 项目: abdelali-m/Exis
    def wait(self, *types):
        ''' Wait until the results of this invocation are resolved '''

        # if canReturn then this is a call. We need to retroactively inform the core of our types
        if self.canReturn:
            self.mantleDomain.CallExpects(self.cb, cumin.prepareSchema(types))

        # Get our current greenlet. If we're not running in a greenlet, someone screwed up bad
        self.green = greenlet.getcurrent()

        # Switch back to the parent greenlet: block until the parent has time to resolve us
        results = self.green.parent.switch(self)

        if isinstance(results, Exception):
            raise results

        r = cumin.unmarshall(results, types)

        # Actually, this cant happen. A return from a function should always come back as
        # a list. Unless you mean a return from... any other thing. In which case, bleh.
        if r is None:
            return r

        return r[0] if len(r) == 1 else r
示例#4
0
    def wait(self, *types):
        ''' Wait until the results of this invocation are resolved '''

        # if canReturn then this is a call. We need to retroactively inform the core of our types
        if self.canReturn:
            self.mantleDomain.CallExpects(self.cb, cumin.prepareSchema(types))

        # Get our current greenlet. If we're not running in a greenlet, someone screwed up bad
        self.green = greenlet.getcurrent()

        # Switch back to the parent greenlet: block until the parent has time to resolve us
        results = self.green.parent.switch(self)

        if isinstance(results, Exception):
            raise results

        r = cumin.unmarshall(results, types)

        # Actually, this cant happen. A return from a function should always come back as
        # a list. Unless you mean a return from... any other thing. In which case, bleh.
        if r is None:
            return r

        return r[0] if len(r) == 1 else r