diff options
author | Omer Katz <omer.drow@gmail.com> | 2020-07-23 16:33:40 +0300 |
---|---|---|
committer | Omer Katz <omer.drow@gmail.com> | 2020-07-23 16:33:40 +0300 |
commit | 2c75db39e0d91c41384f5c2593ec2e630c8e7420 (patch) | |
tree | a04ab723ddb3fcbf672ae08054fd8515a28f90c7 | |
parent | 7bc0e1d0731123024979aa122a907303e154ade1 (diff) | |
download | kombu-2c75db39e0d91c41384f5c2593ec2e630c8e7420.tar.gz |
Remove five usage from tests.
-rw-r--r-- | t/unit/asynchronous/aws/test_connection.py | 5 | ||||
-rw-r--r-- | t/unit/asynchronous/test_timer.py | 3 | ||||
-rw-r--r-- | t/unit/test_common.py | 3 | ||||
-rw-r--r-- | t/unit/test_connection.py | 3 | ||||
-rw-r--r-- | t/unit/test_serialization.py | 5 | ||||
-rw-r--r-- | t/unit/transport/test_SQS.py | 2 | ||||
-rw-r--r-- | t/unit/transport/test_azureservicebus.py | 2 | ||||
-rw-r--r-- | t/unit/transport/test_base.py | 3 | ||||
-rw-r--r-- | t/unit/transport/test_consul.py | 2 | ||||
-rw-r--r-- | t/unit/transport/test_etcd.py | 3 | ||||
-rw-r--r-- | t/unit/transport/test_mongodb.py | 2 | ||||
-rw-r--r-- | t/unit/transport/test_pyamqp.py | 3 | ||||
-rw-r--r-- | t/unit/transport/test_qpid.py | 10 | ||||
-rw-r--r-- | t/unit/transport/test_redis.py | 7 | ||||
-rw-r--r-- | t/unit/transport/virtual/test_base.py | 4 | ||||
-rw-r--r-- | t/unit/utils/test_compat.py | 9 | ||||
-rw-r--r-- | t/unit/utils/test_debug.py | 5 | ||||
-rw-r--r-- | t/unit/utils/test_encoding.py | 29 | ||||
-rw-r--r-- | t/unit/utils/test_functional.py | 18 | ||||
-rw-r--r-- | t/unit/utils/test_json.py | 9 |
20 files changed, 37 insertions, 90 deletions
diff --git a/t/unit/asynchronous/aws/test_connection.py b/t/unit/asynchronous/aws/test_connection.py index f557bd2e..d297653d 100644 --- a/t/unit/asynchronous/aws/test_connection.py +++ b/t/unit/asynchronous/aws/test_connection.py @@ -1,3 +1,5 @@ +from io import StringIO + import pytest from contextlib import contextmanager @@ -6,7 +8,6 @@ from case import Mock from vine.abstract import Thenable from kombu.exceptions import HttpError -from kombu.five import WhateverIO from kombu.asynchronous import http from kombu.asynchronous.aws.connection import ( @@ -115,7 +116,7 @@ class test_AsyncHTTPSConnection(AWSCase): request = x.getresponse(callback) x.http_client.add_request.assert_called_with(request) - buf = WhateverIO() + buf = StringIO() buf.write('The quick brown fox jumps') headers = http.Headers({'X-Foo': 'Hello', 'X-Bar': 'World'}) diff --git a/t/unit/asynchronous/test_timer.py b/t/unit/asynchronous/test_timer.py index 733e106b..78263c15 100644 --- a/t/unit/asynchronous/test_timer.py +++ b/t/unit/asynchronous/test_timer.py @@ -5,7 +5,6 @@ from datetime import datetime from case import Mock, patch from kombu.asynchronous.timer import Entry, Timer, to_timestamp -from kombu.five import bytes_if_py2 class test_to_timestamp: @@ -98,7 +97,7 @@ class test_Timer: t.schedule.enter_after = Mock() myfun = Mock() - myfun.__name__ = bytes_if_py2('myfun') + myfun.__name__ = 'myfun' t.call_repeatedly(0.03, myfun) assert t.schedule.enter_after.call_count == 1 diff --git a/t/unit/test_common.py b/t/unit/test_common.py index 827b4265..b7584a7d 100644 --- a/t/unit/test_common.py +++ b/t/unit/test_common.py @@ -17,12 +17,11 @@ from t.mocks import MockPool def test_generate_oid(): from uuid import NAMESPACE_OID - from kombu.five import bytes_if_py2 instance = Mock() args = (1, 1001, 2001, id(instance)) - ent = bytes_if_py2('%x-%x-%x-%x' % args) + ent = '%x-%x-%x-%x' % args with patch('kombu.common.uuid3') as mock_uuid3, \ patch('kombu.common.uuid5') as mock_uuid5: diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index 866240cd..a47b2c0d 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -9,7 +9,6 @@ from case import Mock, patch, skip from kombu import Connection, Consumer, Producer, parse_url from kombu.connection import Resource from kombu.exceptions import OperationalError -from kombu.five import items, range from kombu.utils.functional import lazy from t.mocks import Transport @@ -60,7 +59,7 @@ class test_connection_utils: def assert_info(self, conn, **fields): info = conn.info() - for field, expected in items(fields): + for field, expected in fields.items(): assert info[field] == expected @pytest.mark.parametrize('url,expected', [ diff --git a/t/unit/test_serialization.py b/t/unit/test_serialization.py index 02502f11..1442a9f4 100644 --- a/t/unit/test_serialization.py +++ b/t/unit/test_serialization.py @@ -8,7 +8,6 @@ from base64 import b64decode from case import call, mock, patch, skip from kombu.exceptions import ContentDisallowed, EncodeError, DecodeError -from kombu.five import text_t, bytes_t from kombu.serialization import ( registry, register, SerializerNotInstalled, raw_encode, register_yaml, register_msgpack, @@ -123,7 +122,7 @@ class test_Serialization: assert isinstance( loads(unicode_string_as_utf8, content_type='application/data', content_encoding='binary'), - bytes_t) + bytes) assert loads( unicode_string_as_utf8, @@ -202,7 +201,7 @@ class test_Serialization: content_encoding='binary') if sys.version_info[0] < 3: for k, v in res.items(): - if isinstance(v, text_t): + if isinstance(v, str): res[k] = v.encode() if isinstance(v, (list, tuple)): res[k] = [i.encode() for i in v] diff --git a/t/unit/transport/test_SQS.py b/t/unit/transport/test_SQS.py index 84b67a8b..bc763641 100644 --- a/t/unit/transport/test_SQS.py +++ b/t/unit/transport/test_SQS.py @@ -10,6 +10,7 @@ import os import pytest import random import string +from queue import Empty from botocore.exceptions import ClientError from case import Mock, skip @@ -18,7 +19,6 @@ from case.mock import patch from kombu import messaging from kombu import Connection, Exchange, Queue -from kombu.five import Empty from kombu.transport import SQS SQS_Channel_sqs = SQS.Channel.sqs diff --git a/t/unit/transport/test_azureservicebus.py b/t/unit/transport/test_azureservicebus.py index 2dd08c77..045f3ea6 100644 --- a/t/unit/transport/test_azureservicebus.py +++ b/t/unit/transport/test_azureservicebus.py @@ -1,9 +1,9 @@ import pytest +from queue import Empty from case import skip, patch from kombu import messaging from kombu import Connection, Exchange, Queue -from kombu.five import Empty from kombu.transport import azureservicebus try: diff --git a/t/unit/transport/test_base.py b/t/unit/transport/test_base.py index 6d8d2472..94d9b551 100644 --- a/t/unit/transport/test_base.py +++ b/t/unit/transport/test_base.py @@ -3,7 +3,6 @@ import pytest from case import Mock from kombu import Connection, Consumer, Exchange, Producer, Queue -from kombu.five import text_t from kombu.message import Message from kombu.transport.base import ( StdChannel, Transport, Management, to_rabbitmq_queue_arguments, @@ -58,7 +57,7 @@ class test_Message: self.message = Message(channel=self.channel, delivery_tag=313) def test_postencode(self): - m = Message(text_t('FOO'), channel=self.channel, postencode='ccyzz') + m = Message('FOO', channel=self.channel, postencode='ccyzz') with pytest.raises(LookupError): m._reraise_error() m.ack() diff --git a/t/unit/transport/test_consul.py b/t/unit/transport/test_consul.py index 9e1a19c7..cd3a8916 100644 --- a/t/unit/transport/test_consul.py +++ b/t/unit/transport/test_consul.py @@ -1,8 +1,8 @@ import pytest +from queue import Empty from case import Mock, skip -from kombu.five import Empty from kombu.transport.consul import Channel, Transport diff --git a/t/unit/transport/test_etcd.py b/t/unit/transport/test_etcd.py index d40c2101..59815e5f 100644 --- a/t/unit/transport/test_etcd.py +++ b/t/unit/transport/test_etcd.py @@ -1,9 +1,8 @@ import pytest +from queue import Empty from case import Mock, patch, skip -from kombu.five import Empty - from kombu.transport.etcd import Channel, Transport diff --git a/t/unit/transport/test_mongodb.py b/t/unit/transport/test_mongodb.py index 5d978764..fe7dc03c 100644 --- a/t/unit/transport/test_mongodb.py +++ b/t/unit/transport/test_mongodb.py @@ -1,10 +1,10 @@ import datetime import pytest +from queue import Empty from case import MagicMock, call, patch, skip from kombu import Connection -from kombu.five import Empty def _create_mock_connection(url='', **kwargs): diff --git a/t/unit/transport/test_pyamqp.py b/t/unit/transport/test_pyamqp.py index 8e2e2eea..124eb0fa 100644 --- a/t/unit/transport/test_pyamqp.py +++ b/t/unit/transport/test_pyamqp.py @@ -5,7 +5,6 @@ from itertools import count from case import Mock, mock, patch from kombu import Connection -from kombu.five import nextfun from kombu.transport import pyamqp @@ -41,7 +40,7 @@ class test_Channel: pass self.conn = Mock() - self.conn._get_free_channel_id.side_effect = nextfun(count(0)) + self.conn._get_free_channel_id.side_effect = count(0).__next__ self.conn.channels = {} self.channel = Channel(self.conn, 0) diff --git a/t/unit/transport/test_qpid.py b/t/unit/transport/test_qpid.py index d322baf2..42f1b90a 100644 --- a/t/unit/transport/test_qpid.py +++ b/t/unit/transport/test_qpid.py @@ -8,16 +8,12 @@ import uuid from collections import OrderedDict -try: - from collections.abc import Callable -except ImportError: - from collections import Callable +from collections.abc import Callable from itertools import count from case import Mock, call, patch, skip -from kombu.five import Empty, range, monotonic from kombu.transport.qpid import (AuthenticationFailure, Channel, Connection, ConnectionError, Message, NotFound, QoS, Transport) @@ -1393,12 +1389,12 @@ class test_Transport_drain_events: def test_timeout_returns_no_earlier_then_asked_for(self): self.transport.session.next_receiver = self.mock_next_receiver - start_time = monotonic() + start_time = time.monotonic() try: self.transport.drain_events(self.mock_conn, timeout=1) except socket.timeout: pass - elapsed_time_in_s = monotonic() - start_time + elapsed_time_in_s = time.monotonic() - start_time assert elapsed_time_in_s >= 1.0 def test_callback_is_called(self): diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py index 05cef4b9..91443ff7 100644 --- a/t/unit/transport/test_redis.py +++ b/t/unit/transport/test_redis.py @@ -4,12 +4,11 @@ import types from collections import defaultdict from itertools import count - +from queue import Empty, Queue as _Queue from case import ANY, ContextMock, Mock, call, mock, skip, patch from kombu import Connection, Exchange, Queue, Consumer, Producer from kombu.exceptions import InconsistencyError, VersionMismatch -from kombu.five import Empty, Queue as _Queue, bytes_if_py2 from kombu.transport import virtual from kombu.utils import eventio # patch poll from kombu.utils.json import dumps @@ -1066,7 +1065,7 @@ def _redis_modules(): class ResponseError(Exception): pass - exceptions = types.ModuleType(bytes_if_py2('redis.exceptions')) + exceptions = types.ModuleType('redis.exceptions') exceptions.ConnectionError = ConnectionError exceptions.AuthenticationError = AuthenticationError exceptions.InvalidData = InvalidData @@ -1076,7 +1075,7 @@ def _redis_modules(): class Redis: pass - myredis = types.ModuleType(bytes_if_py2('redis')) + myredis = types.ModuleType('redis') myredis.exceptions = exceptions myredis.Redis = Redis diff --git a/t/unit/transport/virtual/test_base.py b/t/unit/transport/virtual/test_base.py index ad426ae0..9eb26f38 100644 --- a/t/unit/transport/virtual/test_base.py +++ b/t/unit/transport/virtual/test_base.py @@ -2,6 +2,7 @@ import io import pytest import warnings import socket +from time import monotonic from case import MagicMock, Mock, patch @@ -10,9 +11,8 @@ from kombu.compression import compress from kombu.exceptions import ResourceError, ChannelError from kombu.transport import virtual from kombu.utils.uuid import uuid -from kombu.five import PY3, monotonic -PRINT_FQDN = 'builtins.print' if PY3 else '__builtin__.print' +PRINT_FQDN = 'builtins.print' def client(**kwargs): diff --git a/t/unit/utils/test_compat.py b/t/unit/utils/test_compat.py index c4557ce2..d307c9e2 100644 --- a/t/unit/utils/test_compat.py +++ b/t/unit/utils/test_compat.py @@ -4,7 +4,6 @@ import types from case import Mock, mock, patch -from kombu.five import bytes_if_py2 from kombu.utils import compat from kombu.utils.compat import entrypoints, maybe_fileno @@ -64,17 +63,15 @@ class test_detect_environment: def test_detect_environment_no_eventlet_or_gevent(self): try: - sys.modules['eventlet'] = types.ModuleType( - bytes_if_py2('eventlet')) - sys.modules['eventlet.patcher'] = types.ModuleType( - bytes_if_py2('patcher')) + sys.modules['eventlet'] = types.ModuleType('eventlet') + sys.modules['eventlet.patcher'] = types.ModuleType('patcher') assert compat._detect_environment() == 'default' finally: sys.modules.pop('eventlet.patcher', None) sys.modules.pop('eventlet', None) compat._detect_environment() try: - sys.modules['gevent'] = types.ModuleType(bytes_if_py2('gevent')) + sys.modules['gevent'] = types.ModuleType('gevent') assert compat._detect_environment() == 'default' finally: sys.modules.pop('gevent', None) diff --git a/t/unit/utils/test_debug.py b/t/unit/utils/test_debug.py index d78d7032..2439f449 100644 --- a/t/unit/utils/test_debug.py +++ b/t/unit/utils/test_debug.py @@ -2,7 +2,6 @@ import logging from case import Mock, patch -from kombu.five import bytes_if_py2 from kombu.utils.debug import Logwrapped, setup_logging @@ -30,12 +29,12 @@ class test_Logwrapped: assert W.instance is not None assert W.logger is logger - W.instance.__repr__ = lambda s: bytes_if_py2('foo') + W.instance.__repr__ = lambda s: 'foo' assert repr(W) == 'foo' W.instance.some_attr = 303 assert W.some_attr == 303 - W.instance.some_method.__name__ = bytes_if_py2('some_method') + W.instance.some_method.__name__ = 'some_method' W.some_method(1, 2, kw=1) W.instance.some_method.assert_called_with(1, 2, kw=1) diff --git a/t/unit/utils/test_encoding.py b/t/unit/utils/test_encoding.py index 8454909a..51fc5786 100644 --- a/t/unit/utils/test_encoding.py +++ b/t/unit/utils/test_encoding.py @@ -2,9 +2,8 @@ import sys from contextlib import contextmanager -from case import patch, skip +from case import patch -from kombu.five import bytes_t, string_t, string from kombu.utils.encoding import ( get_default_encoding_file, safe_str, set_default_encoding_file, default_encoding, @@ -44,24 +43,6 @@ class test_default_encoding: getdefaultencoding.assert_called_with() -@skip.if_python3() -def test_str_to_bytes(): - with clean_encoding() as e: - assert isinstance(e.str_to_bytes('foobar'), bytes_t) - - -@skip.if_python3() -def test_from_utf8(): - with clean_encoding() as e: - assert isinstance(e.from_utf8('foobar'), bytes_t) - - -@skip.if_python3() -def test_default_encode(): - with clean_encoding() as e: - assert e.default_encode(b'foo') - - class newbytes(bytes): """Mock class to simulate python-future newbytes class""" def __repr__(self): @@ -71,7 +52,7 @@ class newbytes(bytes): return 'b' + f"'{super().__str__()}'" -class newstr(string): +class newstr(str): """Mock class to simulate python-future newstr class""" def encode(self, encoding=None, errors=None): @@ -92,20 +73,20 @@ class test_safe_str: assert str(safe_str(newstr('foo'))) == 'foo' def test_when_unicode(self): - assert isinstance(safe_str('foo'), string_t) + assert isinstance(safe_str('foo'), str) def test_when_encoding_utf8(self): self._encoding.return_value = 'utf-8' assert default_encoding() == 'utf-8' s = 'The quiæk fåx jømps øver the lazy dåg' res = safe_str(s) - assert isinstance(res, string_t) + assert isinstance(res, str) def test_when_containing_high_chars(self): self._encoding.return_value = 'ascii' s = 'The quiæk fåx jømps øver the lazy dåg' res = safe_str(s) - assert isinstance(res, string_t) + assert isinstance(res, str) assert len(s) == len(res) def test_when_not_string(self): diff --git a/t/unit/utils/test_functional.py b/t/unit/utils/test_functional.py index d2a4d817..ab3852db 100644 --- a/t/unit/utils/test_functional.py +++ b/t/unit/utils/test_functional.py @@ -4,11 +4,8 @@ import pytest from itertools import count -from case import Mock, mock, skip +from case import Mock, mock -from kombu.five import ( - items, PY3, -) from kombu.utils import functional as utils from kombu.utils.functional import ( ChannelPromise, LRUCache, fxrange, fxrangemax, memoize, lazy, @@ -102,7 +99,7 @@ class test_LRUCache: def test_items(self): c = LRUCache() c.update(a=1, b=2, c=3) - assert list(items(c)) + assert list(c.items()) def test_incr(self): c = LRUCache() @@ -136,11 +133,6 @@ class test_lazy: def test__repr__(self): assert repr(lazy(lambda: 'fi fa fo')).strip('u') == "'fi fa fo'" - @skip.if_python3() - def test__cmp__(self): - assert lazy(lambda: 10).__cmp__(lazy(lambda: 20)) == -1 - assert lazy(lambda: 10).__cmp__(5) == 1 - def test_evaluate(self): assert lazy(lambda: 2 + 2)() == 4 assert lazy(lambda x: x * 4, 2) == 8 @@ -324,13 +316,7 @@ class test_accepts_arg: def test_invalid_argument(self): assert not accepts_argument(self.function, 'random_argument') - if PY3: - assert not accepts_argument(test_accepts_arg, 'foo') def test_raise_exception(self): with pytest.raises(Exception): accepts_argument(None, 'foo') - - if not PY3: - with pytest.raises(Exception): - accepts_argument(test_accepts_arg, 'foo') diff --git a/t/unit/utils/test_json.py b/t/unit/utils/test_json.py index ef559a72..c5651d75 100644 --- a/t/unit/utils/test_json.py +++ b/t/unit/utils/test_json.py @@ -7,7 +7,6 @@ from uuid import uuid4 from case import MagicMock, Mock, skip -from kombu.five import text_t from kombu.utils.encoding import str_to_bytes from kombu.utils.json import _DecodeError, dumps, loads @@ -42,11 +41,11 @@ class test_JSONEncoder: def test_Decimal(self): d = Decimal('3314132.13363235235324234123213213214134') - assert loads(dumps({'d': d})), {'d': text_t(d)} + assert loads(dumps({'d': d})), {'d': str(d)} def test_UUID(self): id = uuid4() - assert loads(dumps({'u': id})), {'u': text_t(id)} + assert loads(dumps({'u': id})), {'u': str(id)} def test_default(self): with pytest.raises(TypeError): @@ -79,10 +78,6 @@ class test_dumps_loads: str_to_bytes(dumps({'x': 'z'})), decode_bytes=True) == {'x': 'z'} - @skip.if_python3() - def test_loads_buffer(self): - assert loads(buffer(dumps({'x': 'z'}))) == {'x': 'z'} - def test_loads_DecodeError(self): _loads = Mock(name='_loads') _loads.side_effect = _DecodeError( |