2020
2121REDIS_PY_VERSION = get_package_version_tuple ("redis" )
2222
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+
2330_instance_info_tests = [
2431 ((), {}, ("localhost" , "6379" , "0" )),
2532 ((), {"host" : None }, ("localhost" , "6379" , "0" )),
@@ -71,11 +78,12 @@ def test_redis_connection_instance_info(args, kwargs, expected):
7178 r .connection_pool .release (connection )
7279
7380
81+ @pytest .mark .parametrize ("command_name" , _select_command_as_arg )
7482@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 ):
7684 r = redis .StrictRedis (* args , ** kwargs )
7785 r .connection_pool .connection_class = DisabledConnection
78- connection = r .connection_pool .get_connection ("SELECT" )
86+ connection = r .connection_pool .get_connection (command_name )
7987 try :
8088 conn_kwargs = _conn_attrs_to_dict (connection )
8189 assert _instance_info (conn_kwargs ) == expected
@@ -93,49 +101,35 @@ def test_strict_redis_connection_instance_info(args, kwargs, expected):
93101 (("redis://:1234/" ,), {}, ("localhost" , "1234" , "0" )),
94102 (("redis://@:1234/" ,), {}, ("localhost" , "1234" , "0" )),
95103 (("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" )),
96113]
97114
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+
121116@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_from_url_tests )
122117def test_redis_client_from_url (args , kwargs , expected ):
123118 r = redis .Redis .from_url (* args , ** kwargs )
124119 conn_kwargs = r .connection_pool .connection_kwargs
125120 assert _instance_info (conn_kwargs ) == expected
126121
127122
128- @pytest .mark .skipif (REDIS_PY_VERSION < (2 , 6 ), reason = "from_url not yet implemented in this redis-py version" )
129123@pytest .mark .parametrize ("args,kwargs,expected" , _instance_info_from_url_tests )
130124def test_strict_redis_client_from_url (args , kwargs , expected ):
131125 r = redis .StrictRedis .from_url (* args , ** kwargs )
132126 conn_kwargs = r .connection_pool .connection_kwargs
133127 assert _instance_info (conn_kwargs ) == expected
134128
135129
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 )
137131@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 ):
139133 r = redis .Redis .from_url (* args , ** kwargs )
140134 if r .connection_pool .connection_class is redis .Connection :
141135 r .connection_pool .connection_class = DisabledConnection
@@ -145,17 +139,17 @@ def test_redis_connection_from_url(args, kwargs, expected):
145139 r .connection_pool .connection_class = DisabledSSLConnection
146140 else :
147141 raise AssertionError (r .connection_pool .connection_class )
148- connection = r .connection_pool .get_connection ("SELECT" )
142+ connection = r .connection_pool .get_connection (command_name )
149143 try :
150144 conn_kwargs = _conn_attrs_to_dict (connection )
151145 assert _instance_info (conn_kwargs ) == expected
152146 finally :
153147 r .connection_pool .release (connection )
154148
155149
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 )
157151@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 ):
159153 r = redis .StrictRedis .from_url (* args , ** kwargs )
160154 if r .connection_pool .connection_class is redis .Connection :
161155 r .connection_pool .connection_class = DisabledConnection
@@ -165,7 +159,7 @@ def test_strict_redis_connection_from_url(args, kwargs, expected):
165159 r .connection_pool .connection_class = DisabledSSLConnection
166160 else :
167161 raise AssertionError (r .connection_pool .connection_class )
168- connection = r .connection_pool .get_connection ("SELECT" )
162+ connection = r .connection_pool .get_connection (command_name )
169163 try :
170164 conn_kwargs = _conn_attrs_to_dict (connection )
171165 assert _instance_info (conn_kwargs ) == expected
0 commit comments