19
19
# limitations under the License.
20
20
21
21
22
+ from contextlib import contextmanager
23
+ import warnings
24
+
22
25
import pytest
23
26
24
27
from neo4j .exceptions import (
72
75
config_function_names = ["consume_chain" , "consume" ]
73
76
74
77
78
+ @contextmanager
79
+ def _pool_config_deprecations ():
80
+ with pytest .warns (DeprecationWarning ,
81
+ match = "update_routing_table_timeout" ) as warnings :
82
+ yield warnings
83
+
84
+
85
+ @contextmanager
86
+ def _session_config_deprecations ():
87
+ with pytest .warns (DeprecationWarning ,
88
+ match = "session_connection_timeout" ) as warnings :
89
+ yield warnings
90
+
91
+
75
92
def test_pool_config_consume ():
76
93
77
94
test_config = dict (test_pool_config )
78
95
79
- consumed_pool_config = PoolConfig .consume (test_config )
96
+ with _pool_config_deprecations ():
97
+ consumed_pool_config = PoolConfig .consume (test_config )
80
98
81
99
assert isinstance (consumed_pool_config , PoolConfig )
82
100
@@ -89,7 +107,8 @@ def test_pool_config_consume():
89
107
if key not in config_function_names :
90
108
assert test_pool_config [key ] == consumed_pool_config [key ]
91
109
92
- assert len (consumed_pool_config ) - len (config_function_names ) == len (test_pool_config )
110
+ assert (len (consumed_pool_config ) - len (config_function_names )
111
+ == len (test_pool_config ))
93
112
94
113
95
114
def test_pool_config_consume_default_values ():
@@ -114,7 +133,11 @@ def test_pool_config_consume_key_not_valid():
114
133
test_config ["not_valid_key" ] = "test"
115
134
116
135
with pytest .raises (ConfigurationError ) as error :
117
- consumed_pool_config = PoolConfig .consume (test_config )
136
+ # might or might not warn DeprecationWarning, but we're only
137
+ # interested in the error
138
+ with warnings .catch_warnings ():
139
+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
140
+ _ = PoolConfig .consume (test_config )
118
141
119
142
error .match ("Unexpected config keys: not_valid_key" )
120
143
@@ -123,7 +146,8 @@ def test_pool_config_set_value():
123
146
124
147
test_config = dict (test_pool_config )
125
148
126
- consumed_pool_config = PoolConfig .consume (test_config )
149
+ with _pool_config_deprecations ():
150
+ consumed_pool_config = PoolConfig .consume (test_config )
127
151
128
152
assert consumed_pool_config .get ("encrypted" ) is False
129
153
assert consumed_pool_config ["encrypted" ] is False
@@ -141,28 +165,37 @@ def test_pool_config_set_value():
141
165
def test_pool_config_consume_and_then_consume_again ():
142
166
143
167
test_config = dict (test_pool_config )
144
- consumed_pool_config = PoolConfig .consume (test_config )
168
+ with _pool_config_deprecations ():
169
+ consumed_pool_config = PoolConfig .consume (test_config )
145
170
assert consumed_pool_config .encrypted is False
146
171
consumed_pool_config .encrypted = "test"
147
172
148
173
with pytest .raises (AttributeError ):
149
- consumed_pool_config = PoolConfig .consume (consumed_pool_config )
174
+ _ = PoolConfig .consume (consumed_pool_config )
150
175
151
- consumed_pool_config = PoolConfig .consume (dict (consumed_pool_config .items ()))
152
- consumed_pool_config = PoolConfig .consume (dict (consumed_pool_config .items ()))
176
+ with _pool_config_deprecations ():
177
+ consumed_pool_config = PoolConfig .consume (
178
+ dict (consumed_pool_config .items ())
179
+ )
180
+ with _pool_config_deprecations ():
181
+ consumed_pool_config = PoolConfig .consume (
182
+ dict (consumed_pool_config .items ())
183
+ )
153
184
154
185
assert consumed_pool_config .encrypted == "test"
155
186
156
187
157
188
def test_config_consume_chain ():
158
189
159
190
test_config = {}
160
-
161
191
test_config .update (test_pool_config )
162
-
163
192
test_config .update (test_session_config )
164
193
165
- consumed_pool_config , consumed_session_config = Config .consume_chain (test_config , PoolConfig , SessionConfig )
194
+ with warnings .catch_warnings ():
195
+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
196
+ consumed_pool_config , consumed_session_config = Config .consume_chain (
197
+ test_config , PoolConfig , SessionConfig
198
+ )
166
199
167
200
assert isinstance (consumed_pool_config , PoolConfig )
168
201
assert isinstance (consumed_session_config , SessionConfig )
@@ -176,9 +209,11 @@ def test_config_consume_chain():
176
209
if key not in config_function_names :
177
210
assert test_pool_config [key ] == val
178
211
179
- assert len (consumed_pool_config ) - len (config_function_names ) == len (test_pool_config )
212
+ assert (len (consumed_pool_config ) - len (config_function_names )
213
+ == len (test_pool_config ))
180
214
181
- assert len (consumed_session_config ) - len (config_function_names ) == len (test_session_config )
215
+ assert (len (consumed_session_config ) - len (config_function_names )
216
+ == len (test_session_config ))
182
217
183
218
184
219
def test_init_session_config_merge ():
@@ -226,3 +261,21 @@ def test_init_session_config_with_not_valid_key():
226
261
_ = SessionConfig .consume (test_config_b )
227
262
228
263
assert session_config .connection_acquisition_timeout == 333
264
+
265
+
266
+ def test_pool_config_deprecated_update_routing_table_timeout ():
267
+ with _pool_config_deprecations ():
268
+ _ = PoolConfig .consume ({"update_routing_table_timeout" : 1 })
269
+
270
+ with warnings .catch_warnings ():
271
+ warnings .simplefilter ("error" )
272
+ _ = PoolConfig .consume ({})
273
+
274
+
275
+ def test_session_config_deprecated_session_connection_timeout ():
276
+ with _session_config_deprecations ():
277
+ _ = SessionConfig .consume ({"session_connection_timeout" : 1 })
278
+
279
+ with warnings .catch_warnings ():
280
+ warnings .simplefilter ("error" )
281
+ _ = SessionConfig .consume ({})
0 commit comments