From 20b8710ec383b88174003fd62aabe7b6ac575a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 18 Oct 2024 17:59:11 +0200 Subject: [PATCH] fixes #3 --- .gitlab-ci.yml | 14 +++++++------- coolamqp/objects.py | 11 ++++++----- tests/test_objects.py | 9 +++++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a6b9921..9f427e0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,18 +60,18 @@ unittest_select: unittest_epoll_python27: - extends: .before_test + stage: unittest image: python:2.7 + variables: + AMQP_HOST: "rabbitmq" before_script: - - pip install nose2 nose2[coverage_plugin] + - pip install nose2 coverage requests yapf nose2[coverage_plugin] - python setup.py install script: - nose2 -F -vv - variables: - AMQP_HOST: "rabbitmq" - after_script: - - mv .coverage .coverage.python27epoll - + services: + - name: rabbitmq:3.10-management + alias: rabbitmq unittest_epoll: extends: .before_test diff --git a/coolamqp/objects.py b/coolamqp/objects.py index 22fd796..52482a5 100644 --- a/coolamqp/objects.py +++ b/coolamqp/objects.py @@ -27,6 +27,8 @@ def toutf8(q): def tobytes(q): + if isinstance(q, memoryview): + return q.tobytes() return q.encode('utf-8') if isinstance(q, six.text_type) else q @@ -287,8 +289,7 @@ class Queue(object): if name is None: self.name = None else: - name = uuid.uuid4().hex if not name else name - self.name = tobytes(name) + self.name = tobytes(uuid.uuid4().hex if not name else name) self.durable = durable self.exchange = exchange @@ -303,9 +304,9 @@ class Queue(object): if self.anonymous and (not self.auto_delete or self.durable): raise ValueError('Zero sense to make a anonymous non-auto-delete or durable queue') - if not self.anonymous: - if self.auto_delete or self.exclusive: - warnings.warn('This may cause unpredictable behaviour', UserWarning) + if not self.anonymous and (self.auto_delete or self.exclusive): + warnings.warn('This may cause unpredictable behaviour', UserWarning) + elif self.durable: raise ValueError('Cannot declare an anonymous durable queue') diff --git a/tests/test_objects.py b/tests/test_objects.py index b7fa700..830967c 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -1,5 +1,6 @@ # coding=UTF-8 from __future__ import print_function, absolute_import, division +import sys import logging import unittest import io @@ -13,6 +14,8 @@ from coolamqp.objects import NodeDefinition, MessageProperties, Queue, argumenti logger = logging.getLogger(__name__) logging.getLogger('coolamqp').setLevel(logging.DEBUG) +IS_PY3 = sys.version.startswith('3') + class TestObjects(unittest.TestCase): @@ -26,9 +29,11 @@ class TestObjects(unittest.TestCase): with warnings.catch_warnings(record=True) as w: Queue('test', auto_delete=True, exclusive=True) Queue(auto_delete=True, exclusive=False) - self.assertEqual(len(w), 2) + logger.warning(repr(w)) + self.assertEqual(len(w), 2 if IS_PY3 else 1) self.assertTrue(issubclass(w[0].category, UserWarning)) - self.assertTrue(issubclass(w[1].category, DeprecationWarning)) + if IS_PY3: + self.assertTrue(issubclass(w[1].category, DeprecationWarning)) def test_queue_declare(self): args = argumentify({'x-dead-letter-exchange': 'deadletter', -- GitLab