summaryrefslogtreecommitdiff
path: root/tests/test_encoding.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-08-06 15:15:02 -0700
committerGitHub <noreply@github.com>2020-08-06 15:15:02 -0700
commit8c5a41baf0bd2a1388d601e5b49d06b91997ccb8 (patch)
tree89cad14d95927f8ea696706c2b1399dde17fa244 /tests/test_encoding.py
parentc6f13c3b69d32257ab75ba9d824e5b555f91572c (diff)
downloadredis-py-8c5a41baf0bd2a1388d601e5b49d06b91997ccb8.tar.gz
Remove support for end-of-life Python 2.7 (#1318)
Remove support for end-of-life Python 2.7 Python 2.7 is end of life. It is no longer receiving bug fixes, including for security issues. Python 2.7 went EOL on 2020-01-01. For additional details on support Python versions, see: Supported: https://devguide.python.org/#status-of-python-branches EOL: https://devguide.python.org/devcycle/#end-of-life-branches Removing support for EOL Pythons will reduce testing and maintenance resources while allowing the library to move towards a modern Python 3 style. Python 2.7 users can continue to use the previous version of redis-py. Was able to simplify the code: - Removed redis._compat module - Removed __future__ imports - Removed object from class definition (all classes are new style) - Removed long (Python 3 unified numeric types) - Removed deprecated __nonzero__ method - Use simpler Python 3 super() syntax - Use unified OSError exception - Use yield from syntax Co-authored-by: Andy McCurdy <andy@andymccurdy.com>
Diffstat (limited to 'tests/test_encoding.py')
-rw-r--r--tests/test_encoding.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/tests/test_encoding.py b/tests/test_encoding.py
index ea7db7f..706654f 100644
--- a/tests/test_encoding.py
+++ b/tests/test_encoding.py
@@ -1,13 +1,11 @@
-from __future__ import unicode_literals
import pytest
import redis
-from redis._compat import unichr, unicode
from redis.connection import Connection
from .conftest import _get_client
-class TestEncoding(object):
+class TestEncoding:
@pytest.fixture()
def r(self, request):
return _get_client(redis.Redis, request=request, decode_responses=True)
@@ -21,21 +19,21 @@ class TestEncoding(object):
)
def test_simple_encoding(self, r_no_decode):
- unicode_string = unichr(3456) + 'abcd' + unichr(3421)
+ unicode_string = chr(3456) + 'abcd' + chr(3421)
r_no_decode['unicode-string'] = unicode_string.encode('utf-8')
cached_val = r_no_decode['unicode-string']
assert isinstance(cached_val, bytes)
assert unicode_string == cached_val.decode('utf-8')
def test_simple_encoding_and_decoding(self, r):
- unicode_string = unichr(3456) + 'abcd' + unichr(3421)
+ unicode_string = chr(3456) + 'abcd' + chr(3421)
r['unicode-string'] = unicode_string
cached_val = r['unicode-string']
- assert isinstance(cached_val, unicode)
+ assert isinstance(cached_val, str)
assert unicode_string == cached_val
def test_memoryview_encoding(self, r_no_decode):
- unicode_string = unichr(3456) + 'abcd' + unichr(3421)
+ unicode_string = chr(3456) + 'abcd' + chr(3421)
unicode_string_view = memoryview(unicode_string.encode('utf-8'))
r_no_decode['unicode-string-memoryview'] = unicode_string_view
cached_val = r_no_decode['unicode-string-memoryview']
@@ -44,21 +42,21 @@ class TestEncoding(object):
assert unicode_string == cached_val.decode('utf-8')
def test_memoryview_encoding_and_decoding(self, r):
- unicode_string = unichr(3456) + 'abcd' + unichr(3421)
+ unicode_string = chr(3456) + 'abcd' + chr(3421)
unicode_string_view = memoryview(unicode_string.encode('utf-8'))
r['unicode-string-memoryview'] = unicode_string_view
cached_val = r['unicode-string-memoryview']
- assert isinstance(cached_val, unicode)
+ assert isinstance(cached_val, str)
assert unicode_string == cached_val
def test_list_encoding(self, r):
- unicode_string = unichr(3456) + 'abcd' + unichr(3421)
+ unicode_string = chr(3456) + 'abcd' + chr(3421)
result = [unicode_string, unicode_string, unicode_string]
r.rpush('a', *result)
assert r.lrange('a', 0, -1) == result
-class TestEncodingErrors(object):
+class TestEncodingErrors:
def test_ignore(self, request):
r = _get_client(redis.Redis, request=request, decode_responses=True,
encoding_errors='ignore')
@@ -72,7 +70,7 @@ class TestEncodingErrors(object):
assert r.get('a') == 'foo\ufffd'
-class TestMemoryviewsAreNotPacked(object):
+class TestMemoryviewsAreNotPacked:
def test_memoryviews_are_not_packed(self):
c = Connection()
arg = memoryview(b'some_arg')
@@ -84,7 +82,7 @@ class TestMemoryviewsAreNotPacked(object):
assert cmds[3] is arg
-class TestCommandsAreNotEncoded(object):
+class TestCommandsAreNotEncoded:
@pytest.fixture()
def r(self, request):
return _get_client(redis.Redis, request=request, encoding='utf-16')
@@ -93,7 +91,7 @@ class TestCommandsAreNotEncoded(object):
r.set('hello', 'world')
-class TestInvalidUserInput(object):
+class TestInvalidUserInput:
def test_boolean_fails(self, r):
with pytest.raises(redis.DataError):
r.set('a', True)
@@ -103,12 +101,9 @@ class TestInvalidUserInput(object):
r.set('a', None)
def test_user_type_fails(self, r):
- class Foo(object):
+ class Foo:
def __str__(self):
return 'Foo'
- def __unicode__(self):
- return 'Foo'
-
with pytest.raises(redis.DataError):
r.set('a', Foo())