Exemple #1
0
 def test_0_call_int3(self):
     c = rpc.Client(self._client_sock)
     obj = -sys.maxint - 1
     assert isinstance(obj, int)
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, type(obj))
 def test_0_call_long(self):
     c = rpc.Client(self._client_sock)
     obj = 0xffffffffffffffff  # max value for msgpack
     assert isinstance(obj, numbers.Integral)
     result = c.call('resp', [obj])
     assert result == obj
     assert isinstance(result, numbers.Integral)
Exemple #3
0
 def test_0_call_int3(self):
     c = rpc.Client(self._client_sock)
     obj = - six.MAXSIZE - 1
     assert isinstance(obj, int)
     result = c.call(b'resp', [obj])
     assert result == obj
     assert isinstance(result, type(obj))
Exemple #4
0
 def test_0_call_int2(self):
     c = rpc.Client(self._client_sock)
     obj = six.MAXSIZE
     assert isinstance(obj, int)
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, type(obj))
Exemple #5
0
 def test_2_call_small_binary(self):
     import struct
     c = rpc.Client(self._client_sock)
     obj = struct.pack("100x")
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, bytes)
 def test_0_call_int(self):
     c = rpc.Client(self._client_sock)
     obj = 12345
     assert isinstance(obj, int)
     result = c.call('resp', [obj])
     assert result == obj
     assert isinstance(result, numbers.Integral)
Exemple #7
0
 def test_0_call_long(self):
     c = rpc.Client(self._client_sock)
     obj = 0xffffffffffffffff  # max value for msgpack
     assert isinstance(obj, long)
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, type(obj))
Exemple #8
0
 def test_0_call_long2(self):
     c = rpc.Client(self._client_sock)
     # NOTE: the python type of this value is int for 64-bit arch
     obj = -0x8000000000000000  # min value for msgpack
     assert isinstance(obj, (int, long))
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, type(obj))
Exemple #9
0
 def test_0_call_error(self):
     c = rpc.Client(self._client_sock)
     obj = b'hoge'
     try:
         c.call(b'err', [obj])
         raise Exception("unexpected")
     except rpc.RPCError as e:
         assert e.get_value() == obj
Exemple #10
0
    def test_4_call_large_binary(self):
        import struct

        c = rpc.Client(self._client_sock)
        obj = struct.pack("10000000x")
        result = c.call(b'resp', [obj])
        assert result == obj
        assert isinstance(result, bytes)
Exemple #11
0
 def test_0_call_long(self):
     c = rpc.Client(self._client_sock)
     obj = 0xffffffffffffffff  # max value for msgpack
     _long = int if six.PY3 else long
     assert isinstance(obj, _long)
     result = c.call(b'resp', [obj])
     assert result == obj
     assert isinstance(result, type(obj))
Exemple #12
0
 def test_0_call_error(self):
     c = rpc.Client(self._client_sock)
     obj = "hoge"
     try:
         c.call("err", [obj])
         raise Exception("unexpected")
     except rpc.RPCError, e:
         assert e.get_value() == obj
 def test_0_call_long2(self):
     c = rpc.Client(self._client_sock)
     # Note: the python type of this value is int for 64-bit arch
     obj = -0x8000000000000000  # min value for msgpack
     assert isinstance(obj, numbers.Integral)
     result = c.call('resp', [obj])
     assert result == obj
     assert isinstance(result, numbers.Integral)
 def test_2_call_unicode(self):
     c = rpc.Client(self._client_sock)
     # Note: We use encoding='utf-8' option in msgpack.Packer/Unpacker
     # in order to support Python 3.
     # With this option, utf-8 encoded bytes will be decoded into unicode
     # type in Python 2 and str type in Python 3.
     obj = u"hoge"
     result = c.call('resp', [obj])
     assert result == obj
     assert isinstance(result, six.text_type)
 def test_0_call_bytearray(self):
     c = rpc.Client(self._client_sock)
     obj = bytearray(b'foo')
     # Note: msgpack-python version 0.50 or later supports bytearray
     # objects, here ignores TypeError for the backward compatibility.
     try:
         result = c.call('resp', [obj])
     except TypeError:
         # Case with msgpack-python version 0.4.x or earlier.
         return
     self.assertEqual(obj, result)
     self.assertIsInstance(result, six.binary_type)
Exemple #16
0
 def test_2_call_unicode(self):
     c = rpc.Client(self._client_sock)
     # note: on-wire msgpack has no notion of encoding.
     # the msgpack library implicitly converts unicode to
     # utf-8 encoded bytes by default.
     # we don't want to rely on the behaviour though because
     # it seems to be going to change.
     # https://gist.github.com/methane/5022403
     obj = u"hoge"
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, bytes)
Exemple #17
0
 def test_0_call_int2(self):
     c = rpc.Client(self._client_sock)
     obj = six.MAXSIZE
     assert isinstance(obj, int)
     result = c.call(b'resp', [obj])
     assert result == obj
     import sys
     # note: on PyPy, result will be a long type value.
     sv = getattr(sys, 'subversion', None)
     if sv is not None and sv[0] == 'PyPy':
         assert isinstance(result, long)
     else:
         assert isinstance(result, type(obj))
Exemple #18
0
    def test_4_call_large_binary(self):
        import struct
        import sys
        # note: on PyPy, this test case may hang up.
        sv = getattr(sys, 'subversion', None)
        if sv is not None and sv[0] == 'PyPy':
            return

        c = rpc.Client(self._client_sock)
        obj = struct.pack("10000000x")
        result = c.call(b'resp', [obj])
        assert result == obj
        assert isinstance(result, bytes)
Exemple #19
0
    def test_0_call_error_notification(self):
        l = []

        def callback(n):
            l.append(n)

        c = rpc.Client(self._client_sock, notification_callback=callback)
        c.send_notification("notify2", ["notify_foo", []])
        hub.sleep(0.5)  # give the peer a chance to run
        obj = "hoge"
        try:
            c.call("err", [obj])
            raise Exception("unexpected")
        except rpc.RPCError, e:
            assert e.get_value() == obj
Exemple #20
0
    def test_0_notification2(self):
        l = []

        def callback(n):
            l.append(n)
        c = rpc.Client(self._client_sock, notification_callback=callback)
        obj = "hogehogehoge"
        c.send_notification("notify2", ["notify_hoge", [obj]])
        c.receive_notification()
        assert len(l) == 1
        n = l.pop(0)
        assert n is not None
        method, params = n
        assert method == "notify_hoge"
        assert params[0] == obj
Exemple #21
0
    def test_0_notification1(self):
        l = []

        def callback(n):
            l.append(n)
        c = rpc.Client(self._client_sock, notification_callback=callback)
        obj = "hogehoge"
        robj = "fugafuga"
        assert c.call("notify1", [robj, "notify_hoge", [obj]]) == robj
        c.receive_notification()
        assert len(l) == 1
        n = l.pop(0)
        assert n is not None
        method, params = n
        assert method == "notify_hoge"
        assert params[0] == obj
Exemple #22
0
    def test_0_call_error_notification(self):
        l = []

        def callback(n):
            l.append(n)
        c = rpc.Client(self._client_sock, notification_callback=callback)
        c.send_notification(b'notify2', [b'notify_foo', []])
        hub.sleep(0.5)  # give the peer a chance to run
        obj = b'hoge'
        try:
            c.call(b'err', [obj])
            raise Exception("unexpected")
        except rpc.RPCError as e:
            assert e.get_value() == obj
        assert len(l) == 1
        n = l.pop(0)
        method, params = n
        assert method == b'notify_foo'
        assert params == []
Exemple #23
0
 def connect(self):
     self.client = None
     s = socket.create_connection(self._addr)
     self.client = rpc.Client(s, notification_callback=self.notification)
Exemple #24
0
 def test_0_call_str(self):
     c = rpc.Client(self._client_sock)
     obj = "hoge"
     result = c.call("resp", [obj])
     assert result == obj
     assert isinstance(result, bytes)
Exemple #25
0
 def test_3_call_complex(self):
     c = rpc.Client(self._client_sock)
     obj = [1, "hoge", {"foo": 1, 3: "bar"}]
     assert c.call("resp", [obj]) == list(obj)
Exemple #26
0
 def test_2_call_tuple(self):
     c = rpc.Client(self._client_sock)
     # note: msgpack library implicitly convert a tuple into a list
     obj = (1, 2, 3)
     assert c.call("resp", [obj]) == list(obj)
Exemple #27
0
 def test_2_call_empty_array(self):
     c = rpc.Client(self._client_sock)
     obj = []
     assert c.call("resp", [obj]) == obj
Exemple #28
0
 def test_2_call_empty_dict(self):
     c = rpc.Client(self._client_sock)
     obj = {}
     assert c.call("resp", [obj]) == obj
Exemple #29
0
 def test_2_call_dict(self):
     c = rpc.Client(self._client_sock)
     obj = {"hoge": 1, "fuga": 2}
     assert c.call("resp", [obj]) == obj
Exemple #30
0
 def test_2_call_False(self):
     c = rpc.Client(self._client_sock)
     obj = False
     assert c.call("resp", [obj]) == obj