Skip to content
Snippets Groups Projects
Commit 13485ae0 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix tests

parent 03b226ff
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ from __future__ import division
import collections
import struct
import subprocess
from xml.etree import ElementTree
import math
......@@ -42,7 +43,7 @@ Generated automatically by CoolAMQP from AMQP machine-readable specification.
See coolamqp.uplink.framing.compilation for the tool
AMQP is copyright (c) 2016 OASIS
CoolAMQP is copyright (c) 2016-2018 DMS Serwis s.c., 2018-2019 SMOK sp. z o.o.
CoolAMQP is copyright (c) 2016-2018 DMS Serwis s.c., 2018-2020 SMOK sp. z o.o.
###########################################################
......@@ -553,6 +554,6 @@ REPLIES_FOR = {\n''')
if __name__ == '__main__':
compile_definitions()
# proc = subprocess.run(['yapf', 'coolamqp/framing/definitions.py'], stdout=subprocess.PIPE)
# with open('coolamqp/framing/definitions.py', 'wb') as f_out:
# f_out.write(proc.stdout)
proc = subprocess.run(['yapf', 'coolamqp/framing/definitions.py'], stdout=subprocess.PIPE)
with open('coolamqp/framing/definitions.py', 'wb') as f_out:
f_out.write(proc.stdout)
......@@ -175,8 +175,8 @@ class AMQPMethodPayload(AMQPPayload):
"""
raise NotImplementedError()
@staticmethod
def from_buffer(buf, offset): # type: (buffer, int) -> AMQPMethodPayload
@classmethod
def from_buffer(cls, buf, offset): # type: (buffer, int) -> AMQPMethodPayload
"""
Construct this frame from a buffer
......@@ -184,7 +184,7 @@ class AMQPMethodPayload(AMQPPayload):
:type buf: buffer or memoryview
:param offset: offset the argument portion begins at
:type offset: int
:return: tuple of (an instance of %s, amount of bytes consumed as int)
:return: tuple of (an instance of this class, amount of bytes consumed as int)
:raise ValueError: invalid data
"""
raise NotImplementedError('')
This diff is collapsed.
......@@ -3,15 +3,18 @@
Test things
"""
from __future__ import print_function, absolute_import, division
import six
import logging
import monotonic
import os
import time
import unittest
import time, logging, threading, monotonic
from coolamqp.objects import Message, MessageProperties, NodeDefinition, Queue, \
ReceivedMessage, Exchange
from coolamqp.clustering import Cluster, MessageReceived, NothingMuch
import time
import six
from coolamqp.clustering import Cluster, MessageReceived, NothingMuch
from coolamqp.objects import Message, NodeDefinition, Queue, \
ReceivedMessage, Exchange
NODE = NodeDefinition('127.0.0.1', 'guest', 'guest', heartbeat=20)
logging.basicConfig(level=logging.DEBUG)
......@@ -56,7 +59,7 @@ class TestA(unittest.TestCase):
self.assertTrue(monotonic.monotonic() - a >= 4)
def test_set_qos_but_later(self):
con, fut = self.c.consume(Queue(u'hello', exclusive=True))
con, fut = self.c.consume(Queue(u'hello2', exclusive=True))
fut.result()
......@@ -83,10 +86,10 @@ class TestA(unittest.TestCase):
self.assertIsInstance(e, ReceivedMessage)
P['q'] = True
con, fut = self.c.consume(Queue(u'hello', exclusive=True),
con, fut = self.c.consume(Queue(u'hello3', exclusive=True),
on_message=ok, no_ack=True)
fut.result()
self.c.publish(Message(b''), routing_key=u'hello', tx=True).result()
self.c.publish(Message(b''), routing_key=u'hello3', tx=True).result()
time.sleep(1)
......@@ -97,22 +100,22 @@ class TestA(unittest.TestCase):
def ok(e):
self.assertIsInstance(e, ReceivedMessage)
self.assertEquals(e.body, b'hello')
self.assertEquals(e.body, b'hello4')
# bcoz u can compare memoryviews to their providers :D
self.assertEquals(e.properties.content_type, b'text/plain')
self.assertEquals(e.properties.content_encoding, b'utf8')
P['q'] = True
con, fut = self.c.consume(Queue(u'hello', exclusive=True),
con, fut = self.c.consume(Queue(u'hello4', exclusive=True),
on_message=ok, no_ack=True)
fut.result()
self.c.publish(Message(b'hello', properties={
self.c.publish(Message(b'hello4', properties={
'content_type': b'text/plain',
'content_encoding': b'utf8'
}), routing_key=u'hello', confirm=True).result()
self.assertRaises(RuntimeError,
lambda: self.c.publish(Message(b'hello', properties={
lambda: self.c.publish(Message(b'hello4', properties={
'content_type': b'text/plain',
'content_encoding': b'utf8'
}), routing_key=u'hello', confirm=True,
......@@ -127,16 +130,16 @@ class TestA(unittest.TestCase):
def ok(e):
self.assertIsInstance(e, ReceivedMessage)
self.assertEquals(e.body, b'hello')
self.assertEquals(e.body, b'hello5')
# bcoz u can compare memoryviews to their providers :D
self.assertEquals(e.properties.content_type, b'text/plain')
self.assertEquals(e.properties.content_encoding, b'utf8')
P['q'] = True
con, fut = self.c.consume(Queue(u'hello', exclusive=True),
con, fut = self.c.consume(Queue(u'hello5', exclusive=True),
on_message=ok, no_ack=True)
fut.result()
self.c.publish(Message(b'hello', properties={
self.c.publish(Message(b'hello5', properties={
'content_type': b'text/plain',
'content_encoding': b'utf8'
}), routing_key=u'hello', tx=True).result()
......@@ -152,13 +155,13 @@ class TestA(unittest.TestCase):
def ok(e):
self.assertIsInstance(e, ReceivedMessage)
self.assertEquals(e.body, b'hello')
self.assertEquals(e.body, b'hello6')
P['q'] = True
con, fut = self.c.consume(Queue(u'hello', exclusive=True),
con, fut = self.c.consume(Queue(u'hello6', exclusive=True),
on_message=ok, no_ack=True)
fut.result()
self.c.publish(Message(b'hello'), routing_key=u'hello',
self.c.publish(Message(b'hello6'), routing_key=u'hello',
tx=True).result()
time.sleep(1)
......@@ -169,19 +172,19 @@ class TestA(unittest.TestCase):
"""single and multi frame"""
from coolamqp.attaches import BodyReceiveMode
con, fut = self.c.consume(Queue(u'hello', exclusive=True), no_ack=True,
con, fut = self.c.consume(Queue(u'hello7', exclusive=True), no_ack=True,
body_receive_mode=BodyReceiveMode.MEMORYVIEW)
fut.result()
data = b'hello'
self.c.publish(Message(data), routing_key=u'hello', confirm=True)
data = b'hello7'
self.c.publish(Message(data), routing_key=u'hello7', confirm=True)
m = self.c.drain(2)
self.assertIsInstance(m, MessageReceived)
self.assertIsInstance(m.body, memoryview)
self.assertEquals(m.body, data)
data = six.binary_type(os.urandom(512 * 1024))
self.c.publish(Message(data), routing_key=u'hello', confirm=True)
self.c.publish(Message(data), routing_key=u'hello7', confirm=True)
m = self.c.drain(9)
self.assertIsInstance(m, MessageReceived)
self.assertIsInstance(m.body, memoryview)
......@@ -192,19 +195,19 @@ class TestA(unittest.TestCase):
"""single and multi frame"""
from coolamqp.attaches import BodyReceiveMode
con, fut = self.c.consume(Queue(u'hello', exclusive=True), no_ack=True,
con, fut = self.c.consume(Queue(u'hello8', exclusive=True), no_ack=True,
body_receive_mode=BodyReceiveMode.LIST_OF_MEMORYVIEW)
fut.result()
data = b'hello'
self.c.publish(Message(data), routing_key=u'hello', confirm=True)
data = b'hello8'
self.c.publish(Message(data), routing_key=u'hello8', confirm=True)
m = self.c.drain(1)
self.assertIsInstance(m, MessageReceived)
self.assertIsInstance(m.body[0], memoryview)
self.assertEquals(m.body[0], data)
data = six.binary_type(os.urandom(512 * 1024))
self.c.publish(Message(data), routing_key=u'hello', confirm=True)
self.c.publish(Message(data), routing_key=u'hello7', confirm=True)
m = self.c.drain(5)
self.assertIsInstance(m, MessageReceived)
self.assertTrue(all([isinstance(x, memoryview) for x in m.body]))
......@@ -212,16 +215,16 @@ class TestA(unittest.TestCase):
def test_consumer_cancel(self):
con, fut = self.c.consume(
Queue(u'hello', exclusive=True, auto_delete=True))
Queue(u'hello9', exclusive=True, auto_delete=True))
fut.result()
con.cancel().result()
def test_drain_1(self):
con, fut = self.c.consume(
Queue(u'hello', exclusive=True, auto_delete=True))
Queue(u'helloA', exclusive=True, auto_delete=True))
fut.result()
self.c.publish(Message(b'ioi'), routing_key=u'hello')
self.c.publish(Message(b'ioi'), routing_key=u'helloA')
self.assertIsInstance(self.c.drain(2), MessageReceived)
self.assertIsInstance(self.c.drain(1), NothingMuch)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment