Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create():
server = yield from aiozmq.rpc.serve_rpc(
MyHandler(),
bind='tcp://127.0.0.1:{}'.format(port),
loop=self.loop)
client = yield from aiozmq.rpc.connect_rpc(
connect='tcp://127.0.0.1:{}'.format(port),
loop=self.loop)
return client, server
def communicate():
ret = yield from client.call.single_param(1)
self.assertEqual(ret, 2)
ret = yield from client.call.single_param('1')
self.assertEqual(ret, 2)
ret = yield from client.call.single_param(1.0)
self.assertEqual(ret, 2)
msg = "Invalid value for argument 'arg'"
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param('1.0')
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param('bad value')
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param({})
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param(None)
if sys.version_info >= (3, 5):
msg = "TypeError.*missing a required argument: 'arg'"
else:
msg = "TypeError.*'arg' parameter lacking default value"
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param()
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
def create():
server = yield from aiozmq.rpc.serve_rpc(
MyHandler(),
bind='tcp://127.0.0.1:{}'.format(port),
loop=self.loop)
client = yield from aiozmq.rpc.connect_rpc(
connect='tcp://127.0.0.1:{}'.format(port),
loop=self.loop)
return client, server
@aiozmq.rpc.method
def test2() -> 'bad annotation':
pass
@aiozmq.rpc.method
@asyncio.coroutine
def custom_annotation(self, arg: my_checker):
return arg
yield
def test_override_translators(self):
translators = {
125: (Point, partial(dumps, protocol=HIGHEST_PROTOCOL), loads),
}
packer = _Packer(translators=translators)
pt = Point(3, 4)
data = dumps(pt, protocol=HIGHEST_PROTOCOL)
dt = datetime.time(15, 2)
self.assertEqual(ExtType(125, data), packer.ext_type_pack_hook(pt))
with self.assertRaisesRegex(TypeError, "Unknown type: "):
packer.ext_type_pack_hook(dt)
def test_ext_type__timedelta(self, ExtTypeMock):
packer = _Packer()
CODE = 124
td = datetime.timedelta(days=1, hours=2, minutes=3, seconds=4)
data = dumps(td, protocol=HIGHEST_PROTOCOL)
self.assertEqual(td, packer.ext_type_unpack_hook(CODE, data))
packer.ext_type_pack_hook(td)
ExtTypeMock.assert_called_once_with(CODE, data)
def test_packb_simple(self):
packer = _Packer()
self.assertEqual(packb('test'), packer.packb('test'))
self.assertEqual(packb([123]), packer.packb([123]))
self.assertEqual(packb((123,)), packer.packb([123]))
def test_ext_type_errors(self):
packer = _Packer()
with self.assertRaisesRegex(TypeError, "Unknown type: "):
packer.ext_type_pack_hook(packer)
self.assertIn(_Packer, packer._pack_cache)
self.assertIsNone(packer._pack_cache[_Packer])
# lets try again just for good coverage
with self.assertRaisesRegex(TypeError, "Unknown type: "):
packer.ext_type_pack_hook(packer)
self.assertEqual(ExtType(1, b''), packer.ext_type_unpack_hook(1, b''))
# TODO: should be more specific errors
with self.assertRaises(Exception):
packer.ext_type_unpack_hook(127, b'bad data')
def test_unpackb_simple(self):
packer = _Packer()
self.assertEqual('test', packer.unpackb(packb('test')))
self.assertEqual((123,), packer.unpackb(packb([123])))
self.assertEqual((123,), packer.unpackb(packb((123,))))