Skip to content

Commit ff1861c

Browse files
committed
Replace distutils.version with packaging.version
distutils is going to be deprecated (PEP 632), and packaging is the recommended replacement. This does end up requiring that the redis server version is a valid PEP 440 string, but that's only relevant during the unit tests so if redis does go to a weird versioning scheme it won't affect users directly.
1 parent 5484379 commit ff1861c

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

fakeredis/aioredis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import distutils.version
2-
31
import aioredis
2+
import packaging.version
43

54

6-
if aioredis.__version__ >= distutils.version.StrictVersion('2.0.0a1'):
5+
if packaging.version.Version(aioredis.__version__) >= packaging.version.Version('2.0.0a1'):
76
from ._aioredis2 import FakeConnection, FakeRedis # noqa: F401
87
else:
98
from ._aioredis1 import ( # noqa: F401

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ classifiers =
2222
[options]
2323
packages = fakeredis
2424
install_requires =
25+
packaging
2526
# Minor version updates to redis tend to break fakeredis. If you
2627
# need to use fakeredis with a newer redis, please submit a PR that
2728
# relaxes this restriction and adds it to the Github Actions tests.

test/test_aioredis1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import asyncio
2-
import distutils.version
32

3+
from packaging.version import Version
44
import pytest
55
import aioredis
66
from async_generator import yield_, async_generator
77

88
import fakeredis.aioredis
99

1010

11-
aioredis2 = aioredis.__version__ >= distutils.version.StrictVersion('2.0.0a1')
11+
aioredis2 = Version(aioredis.__version__) >= Version('2.0.0a1')
1212
pytestmark = [
1313
pytest.mark.asyncio,
1414
pytest.mark.skipif(aioredis2, reason="Test is only applicable to aioredis 1.x")

test/test_aioredis2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
2-
import distutils.version
32
import re
43

4+
from packaging.version import Version
55
import pytest
66
import aioredis
77
import async_timeout
@@ -10,7 +10,7 @@
1010
import fakeredis.aioredis
1111

1212

13-
aioredis2 = aioredis.__version__ >= distutils.version.StrictVersion('2.0.0a1')
13+
aioredis2 = Version(aioredis.__version__) >= Version('2.0.0a1')
1414
pytestmark = [
1515
pytest.mark.asyncio,
1616
pytest.mark.skipif(not aioredis2, reason="Test is only applicable to aioredis 2.x")

test/test_fakeredis.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import threading
77
import logging
88
from queue import Queue
9-
import distutils.version
109

1110
import six
11+
from packaging.version import Version
1212
import pytest
1313
import redis
1414
import redis.client
@@ -17,8 +17,8 @@
1717
from datetime import datetime, timedelta
1818

1919

20-
REDIS_VERSION = distutils.version.LooseVersion(redis.__version__)
21-
REDIS3 = REDIS_VERSION >= '3'
20+
REDIS_VERSION = Version(redis.__version__)
21+
REDIS3 = REDIS_VERSION >= Version('3')
2222

2323

2424
redis2_only = pytest.mark.skipif(REDIS3, reason="Test is only applicable to redis-py 2.x")
@@ -99,8 +99,8 @@ def factory(db=0):
9999
min_server_marker = request.node.get_closest_marker('min_server')
100100
if min_server_marker is not None:
101101
server_version = conn.info()['redis_version']
102-
min_version = min_server_marker.args[0]
103-
if distutils.version.LooseVersion(server_version) < min_version:
102+
min_version = Version(min_server_marker.args[0])
103+
if Version(server_version) < min_version:
104104
pytest.skip(
105105
'Redis server {} required but {} found'.format(min_version, server_version)
106106
)
@@ -729,7 +729,7 @@ def test_set_px_using_timedelta(r):
729729
assert r.get('foo') == b'bar'
730730

731731

732-
@pytest.mark.skipif(REDIS_VERSION < '3.5', reason="Test is only applicable to redis-py 3.5+")
732+
@pytest.mark.skipif(REDIS_VERSION < Version('3.5'), reason="Test is only applicable to redis-py 3.5+")
733733
@pytest.mark.min_server('6.0')
734734
def test_set_keepttl(r):
735735
r.set('foo', 'bar', ex=100)
@@ -743,7 +743,7 @@ def test_set_conflicting_expire_options(r):
743743
r.set('foo', 'bar', ex=1, px=1)
744744

745745

746-
@pytest.mark.skipif(REDIS_VERSION < '3.5', reason="Test is only applicable to redis-py 3.5+")
746+
@pytest.mark.skipif(REDIS_VERSION < Version('3.5'), reason="Test is only applicable to redis-py 3.5+")
747747
def test_set_conflicting_expire_options_w_keepttl(r):
748748
with pytest.raises(ResponseError):
749749
r.set('foo', 'bar', ex=1, keepttl=True)
@@ -1682,7 +1682,7 @@ def test_scan_iter_multiple_pages_with_match(r):
16821682
assert actual == set(all_keys)
16831683

16841684

1685-
@pytest.mark.skipif(REDIS_VERSION < '3.5', reason="Test is only applicable to redis-py 3.5+")
1685+
@pytest.mark.skipif(REDIS_VERSION < Version('3.5'), reason="Test is only applicable to redis-py 3.5+")
16861686
@pytest.mark.min_server('6.0')
16871687
def test_scan_iter_multiple_pages_with_type(r):
16881688
all_keys = key_val_dict(size=100)
@@ -2101,7 +2101,7 @@ def test_zadd_with_nx_and_xx(r, ch):
21012101
zadd(r, 'foo', {'four': -4.0, 'three': -3.0}, nx=True, xx=True, ch=ch)
21022102

21032103

2104-
@pytest.mark.skipif(REDIS_VERSION < '3.1', reason="Test is only applicable to redis-py 3.1+")
2104+
@pytest.mark.skipif(REDIS_VERSION < Version('3.1'), reason="Test is only applicable to redis-py 3.1+")
21052105
@pytest.mark.parametrize('ch', [False, True])
21062106
def test_zadd_incr(r, ch):
21072107
zadd(r, 'foo', {'four': 4.0, 'three': 3.0})
@@ -3335,7 +3335,7 @@ def test_pipeline_no_commands(r):
33353335
p = r.pipeline()
33363336
p.watch('foo')
33373337
r.set('foo', '2')
3338-
if REDIS_VERSION >= '3.4':
3338+
if REDIS_VERSION >= Version('3.4'):
33393339
with pytest.raises(redis.WatchError):
33403340
p.execute()
33413341
else:
@@ -3781,7 +3781,7 @@ def test_pubsub_run_in_thread(r):
37813781
pytest.param(
37823782
None,
37833783
marks=pytest.mark.skipif(
3784-
REDIS_VERSION >= "3.2" and REDIS_VERSION < "3.3",
3784+
Version("3.2") <= REDIS_VERSION < Version("3.3"),
37853785
reason="This test is not applicable to redis-py 3.2"
37863786
)
37873787
)
@@ -4694,7 +4694,7 @@ def test_unlink(r):
46944694
assert r.get('foo') is None
46954695

46964696

4697-
@pytest.mark.skipif(REDIS_VERSION < "3.4", reason="Test requires redis-py 3.4+")
4697+
@pytest.mark.skipif(REDIS_VERSION < Version("3.4"), reason="Test requires redis-py 3.4+")
46984698
@pytest.mark.fake
46994699
def test_socket_cleanup_pubsub(fake_server):
47004700
r1 = fakeredis.FakeStrictRedis(server=fake_server)

0 commit comments

Comments
 (0)