20
20
21
21
REDIS_PY_VERSION = get_package_version_tuple ("redis" )
22
22
23
+ # Call to `get_connection` function with the usage of the command
24
+ # name as an input argument has been deprecated since v5.3.0.
25
+ _select_command_as_arg = [
26
+ (pytest .param (None , marks = pytest .mark .skipif (REDIS_PY_VERSION < (5 , 3 ), reason = "Deprecated after v5.3" ))),
27
+ (pytest .param ("SELECT" , marks = pytest .mark .skipif (REDIS_PY_VERSION >= (5 , 3 ), reason = "Needed until v5.3" ))),
28
+ ]
29
+
23
30
_instance_info_tests = [
24
31
((), {}, ("localhost" , "6379" , "0" )),
25
32
((), {"host" : None }, ("localhost" , "6379" , "0" )),
@@ -71,11 +78,12 @@ def test_redis_connection_instance_info(args, kwargs, expected):
71
78
r .connection_pool .release (connection )
72
79
73
80
81
+ @pytest .mark .parametrize ("command_name" , _select_command_as_arg )
74
82
@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_tests )
75
- def test_strict_redis_connection_instance_info (args , kwargs , expected ):
83
+ def test_strict_redis_connection_instance_info (args , kwargs , expected , command_name ):
76
84
r = redis .StrictRedis (* args , ** kwargs )
77
85
r .connection_pool .connection_class = DisabledConnection
78
- connection = r .connection_pool .get_connection ("SELECT" )
86
+ connection = r .connection_pool .get_connection (command_name )
79
87
try :
80
88
conn_kwargs = _conn_attrs_to_dict (connection )
81
89
assert _instance_info (conn_kwargs ) == expected
@@ -93,49 +101,35 @@ def test_strict_redis_connection_instance_info(args, kwargs, expected):
93
101
(("redis://:1234/" ,), {}, ("localhost" , "1234" , "0" )),
94
102
(("redis://@:1234/" ,), {}, ("localhost" , "1234" , "0" )),
95
103
(("redis://localhost:1234/garbage" ,), {}, ("localhost" , "1234" , "0" )),
104
+ (("redis://localhost:6379/2/" ,), {}, ("localhost" , "6379" , "2" )),
105
+ (("redis://localhost:6379" ,), {"host" : "someotherhost" }, ("localhost" , "6379" , "0" )),
106
+ (("redis://localhost:6379/2" ,), {"db" : 3 }, ("localhost" , "6379" , "2" )),
107
+ (("redis://localhost:6379/2/?db=111" ,), {}, ("localhost" , "6379" , "111" )),
108
+ (("redis://localhost:6379?db=2" ,), {}, ("localhost" , "6379" , "2" )),
109
+ (("redis://localhost:6379/2?db=111" ,), {}, ("localhost" , "6379" , "111" )),
110
+ (("unix:///path/to/socket.sock" ,), {}, ("localhost" , "/path/to/socket.sock" , "0" )),
111
+ (("unix:///path/to/socket.sock?db=2" ,), {}, ("localhost" , "/path/to/socket.sock" , "2" )),
112
+ (("unix:///path/to/socket.sock" ,), {"db" : 2 }, ("localhost" , "/path/to/socket.sock" , "2" )),
96
113
]
97
114
98
- # Behavior to default port to 6379 was added in v2.7.5
99
- # (https://github.com/redis/redis-py/commit/cfe1041bbb8a8887531810429879bffbe705b03a)
100
- # and removed in v4.0.0b1 (https://github.com/redis/redis-py/blame/v4.0.0b1/redis/connection.py#L997)
101
- if (3 , 5 , 3 ) >= REDIS_PY_VERSION >= (2 , 7 , 5 ):
102
- _instance_info_from_url_tests .append ((("redis://127.0.0.1" ,), {}, ("127.0.0.1" , "6379" , "0" )))
103
-
104
- if REDIS_PY_VERSION >= (2 , 10 ):
105
- _instance_info_from_url_tests .extend (
106
- [
107
- (("rediss://localhost:6379/2/" ,), {}, ("localhost" , "6379" , "2" )),
108
- (("redis://localhost:6379" ,), {"host" : "someotherhost" }, ("localhost" , "6379" , "0" )),
109
- (("redis://localhost:6379/2" ,), {"db" : 3 }, ("localhost" , "6379" , "2" )),
110
- (("redis://localhost:6379/2/?db=111" ,), {}, ("localhost" , "6379" , "111" )),
111
- (("redis://localhost:6379?db=2" ,), {}, ("localhost" , "6379" , "2" )),
112
- (("redis://localhost:6379/2?db=111" ,), {}, ("localhost" , "6379" , "111" )),
113
- (("unix:///path/to/socket.sock" ,), {}, ("localhost" , "/path/to/socket.sock" , "0" )),
114
- (("unix:///path/to/socket.sock?db=2" ,), {}, ("localhost" , "/path/to/socket.sock" , "2" )),
115
- (("unix:///path/to/socket.sock" ,), {"db" : 2 }, ("localhost" , "/path/to/socket.sock" , "2" )),
116
- ]
117
- )
118
-
119
-
120
- @pytest .mark .skipif (REDIS_PY_VERSION < (2 , 6 ), reason = "from_url not yet implemented in this redis-py version" )
115
+
121
116
@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_from_url_tests )
122
117
def test_redis_client_from_url (args , kwargs , expected ):
123
118
r = redis .Redis .from_url (* args , ** kwargs )
124
119
conn_kwargs = r .connection_pool .connection_kwargs
125
120
assert _instance_info (conn_kwargs ) == expected
126
121
127
122
128
- @pytest .mark .skipif (REDIS_PY_VERSION < (2 , 6 ), reason = "from_url not yet implemented in this redis-py version" )
129
123
@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_from_url_tests )
130
124
def test_strict_redis_client_from_url (args , kwargs , expected ):
131
125
r = redis .StrictRedis .from_url (* args , ** kwargs )
132
126
conn_kwargs = r .connection_pool .connection_kwargs
133
127
assert _instance_info (conn_kwargs ) == expected
134
128
135
129
136
- @pytest .mark .skipif ( REDIS_PY_VERSION < ( 2 , 6 ), reason = "from_url not yet implemented in this redis-py version" )
130
+ @pytest .mark .parametrize ( "command_name" , _select_command_as_arg )
137
131
@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_from_url_tests )
138
- def test_redis_connection_from_url (args , kwargs , expected ):
132
+ def test_redis_connection_from_url (args , kwargs , expected , command_name ):
139
133
r = redis .Redis .from_url (* args , ** kwargs )
140
134
if r .connection_pool .connection_class is redis .Connection :
141
135
r .connection_pool .connection_class = DisabledConnection
@@ -145,17 +139,17 @@ def test_redis_connection_from_url(args, kwargs, expected):
145
139
r .connection_pool .connection_class = DisabledSSLConnection
146
140
else :
147
141
raise AssertionError (r .connection_pool .connection_class )
148
- connection = r .connection_pool .get_connection ("SELECT" )
142
+ connection = r .connection_pool .get_connection (command_name )
149
143
try :
150
144
conn_kwargs = _conn_attrs_to_dict (connection )
151
145
assert _instance_info (conn_kwargs ) == expected
152
146
finally :
153
147
r .connection_pool .release (connection )
154
148
155
149
156
- @pytest .mark .skipif ( REDIS_PY_VERSION < ( 2 , 6 ), reason = "from_url not yet implemented in this redis-py version" )
150
+ @pytest .mark .parametrize ( "command_name" , _select_command_as_arg )
157
151
@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_from_url_tests )
158
- def test_strict_redis_connection_from_url (args , kwargs , expected ):
152
+ def test_strict_redis_connection_from_url (args , kwargs , expected , command_name ):
159
153
r = redis .StrictRedis .from_url (* args , ** kwargs )
160
154
if r .connection_pool .connection_class is redis .Connection :
161
155
r .connection_pool .connection_class = DisabledConnection
@@ -165,7 +159,7 @@ def test_strict_redis_connection_from_url(args, kwargs, expected):
165
159
r .connection_pool .connection_class = DisabledSSLConnection
166
160
else :
167
161
raise AssertionError (r .connection_pool .connection_class )
168
- connection = r .connection_pool .get_connection ("SELECT" )
162
+ connection = r .connection_pool .get_connection (command_name )
169
163
try :
170
164
conn_kwargs = _conn_attrs_to_dict (connection )
171
165
assert _instance_info (conn_kwargs ) == expected
0 commit comments