Skip to content

Commit e302a21

Browse files
committed
fix several deprecation warnings
adding -Werror flag to pytest configuration so we can flush all of those with the test we have so we won't have user of the driver running into those and get them fixed address as soon as we support new python versions
1 parent 44f012c commit e302a21

22 files changed

+85
-43
lines changed

cassandra/cqlengine/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def setup(
324324
:param int consistency: The global default :class:`~.ConsistencyLevel` - default is the same as :attr:`.Session.default_consistency_level`
325325
:param bool lazy_connect: True if should not connect until first use
326326
:param bool retry_connect: True if we should retry to connect even if there was a connection failure initially
327-
:param \*\*kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
327+
:param kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
328328
"""
329329

330330
from cassandra.cqlengine import models

cassandra/cqlengine/query.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def add_callback(self, fn, *args, **kwargs):
206206
207207
:param fn: Callable object
208208
:type fn: callable
209-
:param \*args: Positional arguments to be passed to the callback at the time of execution
210-
:param \*\*kwargs: Named arguments to be passed to the callback at the time of execution
209+
:param args: Positional arguments to be passed to the callback at the time of execution
210+
:param kwargs: Named arguments to be passed to the callback at the time of execution
211211
"""
212212
if not callable(fn):
213213
raise ValueError("Value for argument 'fn' is {0} and is not a callable object.".format(type(fn)))
@@ -277,8 +277,8 @@ class ContextQuery(object):
277277
A Context manager to allow a Model to switch context easily. Presently, the context only
278278
specifies a keyspace for model IO.
279279
280-
:param \*args: One or more models. A model should be a class type, not an instance.
281-
:param \*\*kwargs: (optional) Context parameters: can be *keyspace* or *connection*
280+
:param args: One or more models. A model should be a class type, not an instance.
281+
:param kwargs: (optional) Context parameters: can be *keyspace* or *connection*
282282
283283
For example:
284284

cassandra/datastax/cloud/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
_HAS_SSL = True
2525
try:
26-
from ssl import SSLContext, PROTOCOL_TLS, CERT_REQUIRED
26+
from ssl import SSLContext, PROTOCOL_TLS_CLIENT, CERT_REQUIRED
2727
except:
2828
_HAS_SSL = False
2929

@@ -170,7 +170,7 @@ def parse_metadata_info(config, http_data):
170170

171171

172172
def _ssl_context_from_cert(ca_cert_location, cert_location, key_location):
173-
ssl_context = SSLContext(PROTOCOL_TLS)
173+
ssl_context = SSLContext(PROTOCOL_TLS_CLIENT)
174174
ssl_context.load_verify_locations(ca_cert_location)
175175
ssl_context.verify_mode = CERT_REQUIRED
176176
ssl_context.load_cert_chain(certfile=cert_location, keyfile=key_location)

cassandra/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from cassandra import DriverException
3535

3636
DATETIME_EPOC = datetime.datetime(1970, 1, 1)
37-
UTC_DATETIME_EPOC = datetime.datetime.utcfromtimestamp(0)
37+
UTC_DATETIME_EPOC = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
3838

3939
_nan = float('nan')
4040

pytest.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ log_format = %(asctime)s.%(msecs)03d %(levelname)s [%(module)s:%(lineno)s]: %(me
33
log_level = DEBUG
44
log_date_format = %Y-%m-%d %H:%M:%S
55
xfail_strict=true
6+
7+
filterwarnings =
8+
error
9+
ignore::pytest.PytestCollectionWarning
10+
ignore::ResourceWarning
11+
ignore:distutils Version classes are deprecated:DeprecationWarning:eventlet.support.greenlets
12+
ignore:X509Extension support in pyOpenSSL is deprecated.:DeprecationWarning
13+
ignore:CRL support in pyOpenSSL is deprecated:DeprecationWarning
14+
ignore:sign\(\) is deprecated:DeprecationWarning
15+
ignore:verify\(\) is deprecated:DeprecationWarning

tests/integration/cqlengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def wrapped_function(*args, **kwargs):
7777
# DeMonkey Patch our code
7878
cassandra.cqlengine.connection.execute = original_function
7979
# Check to see if we have a pre-existing test case to work from.
80-
if len(args) is 0:
80+
if len(args) == 0:
8181
test_case = unittest.TestCase("__init__")
8282
else:
8383
test_case = args[0]

tests/integration/cqlengine/query/test_queryoperators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ def test_named_table_pk_token_function(self):
154154
query = named.all().limit(1)
155155
first_page = list(query)
156156
last = first_page[-1]
157-
self.assertTrue(len(first_page) is 1)
157+
self.assertTrue(len(first_page) == 1)
158158
next_page = list(query.filter(pk__token__gt=functions.Token(last.key)))
159-
self.assertTrue(len(next_page) is 1)
159+
self.assertTrue(len(next_page) == 1)

tests/integration/standard/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def wait_for_no_connections(self, host, cluster):
191191
while(retry < 100):
192192
retry += 1
193193
connections = self.fetch_connections(host, cluster)
194-
if len(connections) is 0:
194+
if len(connections) == 0:
195195
return
196196
time.sleep(.5)
197197
self.fail("Connections never cleared")

tests/unit/advanced/test_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def test_with_graph_protocol(self):
257257

258258
def test_init_unknown_kwargs(self):
259259
with warnings.catch_warnings(record=True) as w:
260+
warnings.simplefilter("always")
260261
GraphOptions(unknown_param=42)
261262
self.assertEqual(len(w), 1)
262263
self.assertRegex(str(w[0].message), r"^Unknown keyword.*GraphOptions.*")

tests/unit/advanced/test_insights.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
import unittest
17+
import pytest
1718

1819
import logging
1920
from mock import sentinel
@@ -103,6 +104,7 @@ def superclass_sentinel_serializer(obj):
103104
class TestConfigAsDict(unittest.TestCase):
104105

105106
# graph/query.py
107+
@pytest.mark.filterwarnings("ignore:Unknown keyword argument received for GraphOptions:UserWarning")
106108
def test_graph_options(self):
107109
self.maxDiff = None
108110

tests/unit/advanced/test_policies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import unittest
15+
import pytest
1516

1617
from mock import Mock
1718

@@ -29,6 +30,7 @@ def get_host(self, addr):
2930
return self.hosts.get(addr)
3031

3132

33+
@pytest.mark.filterwarnings("ignore:DSELoadBalancingPolicy will be removed:DeprecationWarning")
3234
class DSELoadBalancingPolicyTest(unittest.TestCase):
3335

3436
def test_no_target(self):

tests/unit/cython/bytesio_testhelper.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# cython: language_level=3
16+
1517
from cassandra.bytesio cimport BytesIOReader
1618

1719
def test_read1(assert_equal, assert_raises):

tests/unit/cython/types_testhelper.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# cython: language_level=3
16+
1517
import calendar
1618
import datetime
1719
import time

tests/unit/cython/utils_testhelper.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# cython: language_level=3
16+
1517
import datetime
1618

1719
from cassandra.cython_utils cimport datetime_from_timestamp

tests/unit/io/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def submit_and_wait_for_completion(unit_test, create_timer, start, end, incremen
123123
pending_callbacks.append(callback)
124124

125125
# wait for all the callbacks associated with the timers to be invoked
126-
while len(pending_callbacks) is not 0:
126+
while len(pending_callbacks) != 0:
127127
for callback in pending_callbacks:
128128
if callback.was_invoked():
129129
pending_callbacks.remove(callback)
@@ -233,7 +233,7 @@ def make_error_body(self, code, msg):
233233
def make_msg(self, header, body=binary_type()):
234234
return header + uint32_pack(len(body)) + body
235235

236-
def test_successful_connection(self):
236+
def _test_successful_connection(self):
237237
c = self.make_connection()
238238

239239
# let it write the OptionsMessage
@@ -255,6 +255,9 @@ def test_successful_connection(self):
255255
self.assertTrue(c.connected_event.is_set())
256256
return c
257257

258+
def test_successful_connection(self):
259+
self._test_successful_connection()
260+
258261
def test_eagain_on_buffer_size(self):
259262
self._check_error_recovery_on_buffer_size(errno.EAGAIN)
260263

@@ -272,7 +275,7 @@ def test_sslwantwrite_on_buffer_size(self):
272275
error_class=ssl.SSLError)
273276

274277
def _check_error_recovery_on_buffer_size(self, error_code, error_class=socket_error):
275-
c = self.test_successful_connection()
278+
c = self._test_successful_connection()
276279

277280
# current data, used by the recv side_effect
278281
message_chunks = None

tests/unit/test_cluster.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import unittest
15+
import pytest
1516

1617
import logging
1718
import six
@@ -275,6 +276,9 @@ def test_default_exec_parameters(self):
275276
self.assertEqual(cluster.profile_manager.default.row_factory, named_tuple_factory)
276277

277278
@mock_session_pools
279+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
280+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed in 4.0:DeprecationWarning")
281+
@pytest.mark.filterwarnings("ignore:Setting the consistency level at the session level will be removed in 4.0:DeprecationWarning")
278282
def test_default_legacy(self):
279283
cluster = Cluster(load_balancing_policy=RoundRobinPolicy(), default_retry_policy=DowngradingConsistencyRetryPolicy())
280284
self.assertEqual(cluster._config_mode, _ConfigMode.LEGACY)
@@ -322,6 +326,8 @@ def test_serial_consistency_level_validation(self):
322326
ep = ExecutionProfile(RoundRobinPolicy(), serial_consistency_level=42)
323327

324328
@mock_session_pools
329+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
330+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed in 4.0:DeprecationWarning")
325331
def test_statement_params_override_legacy(self):
326332
cluster = Cluster(load_balancing_policy=RoundRobinPolicy(), default_retry_policy=DowngradingConsistencyRetryPolicy())
327333
self.assertEqual(cluster._config_mode, _ConfigMode.LEGACY)
@@ -343,6 +349,7 @@ def test_statement_params_override_legacy(self):
343349
self._verify_response_future_profile(rf, expected_profile)
344350

345351
@mock_session_pools
352+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
346353
def test_statement_params_override_profile(self):
347354
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(2)])
348355
cluster = Cluster(execution_profiles={'non-default': non_default_profile})
@@ -367,6 +374,9 @@ def test_statement_params_override_profile(self):
367374
self._verify_response_future_profile(rf, expected_profile)
368375

369376
@mock_session_pools
377+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
378+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed in 4.0:DeprecationWarning")
379+
@pytest.mark.filterwarnings("ignore:Setting the consistency level at the session level will be removed in 4.0:DeprecationWarning")
370380
def test_no_profile_with_legacy(self):
371381
# don't construct with both
372382
self.assertRaises(ValueError, Cluster, load_balancing_policy=RoundRobinPolicy(), execution_profiles={'a': ExecutionProfile()})
@@ -393,6 +403,7 @@ def test_no_profile_with_legacy(self):
393403
self.assertRaises(ValueError, session.execute_async, "query", execution_profile='some name here')
394404

395405
@mock_session_pools
406+
@pytest.mark.filterwarnings("ignore:Setting the consistency level at the session level will be removed in 4.0:DeprecationWarning")
396407
def test_no_legacy_with_profile(self):
397408
cluster_init = Cluster(execution_profiles={'name': ExecutionProfile()})
398409
cluster_add = Cluster()
@@ -513,6 +524,7 @@ def _check_warning_on_no_lbp_with_contact_points(self, cluster_kwargs):
513524
self.assertIn('please specify a load-balancing policy', warning_message)
514525
self.assertIn("contact_points = ['127.0.0.1']", warning_message)
515526

527+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed in 4.0:DeprecationWarning")
516528
def test_no_warning_on_contact_points_with_lbp_legacy_mode(self):
517529
"""
518530
Test that users aren't warned when they instantiate a Cluster object

tests/unit/test_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def extract_consistency(self, msg):
2929
:param msg: message with consistency value
3030
:return: String representing consistency value
3131
"""
32-
match = re.search("'consistency':\s+'([\w\s]+)'", msg)
32+
match = re.search(r"'consistency':\s+'([\w\s]+)'", msg)
3333
return match and match.group(1)
3434

3535
def test_timeout_consistency(self):

tests/unit/test_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,9 @@ def test_strip_frozen(self):
849849
argument_to_expected_results = [
850850
('int', 'int'),
851851
('tuple<text>', 'tuple<text>'),
852-
(r'map<"!@#$%^&*()[]\ frozen >>>", int>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'), # A valid UDT name
852+
(r'map<"!@#$%^&*()[]\\ frozen >>>", int>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'), # A valid UDT name
853853
('frozen<tuple<text>>', 'tuple<text>'),
854-
(r'frozen<map<"!@#$%^&*()[]\ frozen >>>", int>>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'),
854+
(r'frozen<map<"!@#$%^&*()[]\\ frozen >>>", int>>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'),
855855
('frozen<map<frozen<tuple<int, frozen<list<text>>, int>>, frozen<map<int, frozen<tuple<int>>>>>>',
856856
'map<tuple<int, list<text>, int>, map<int, tuple<int>>>'),
857857
]

tests/unit/test_policies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import unittest
16+
import pytest
1617

1718
from itertools import islice, cycle
1819
from mock import Mock, patch, call
@@ -1134,6 +1135,7 @@ def test_unavailable(self):
11341135
self.assertEqual(consistency, None)
11351136

11361137

1138+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
11371139
class DowngradingConsistencyRetryPolicyTest(unittest.TestCase):
11381140

11391141
def test_read_timeout(self):

tests/unit/test_response_future.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_result_message(self):
8282

8383
expected_result = (object(), object())
8484
rf._set_result(None, None, None, self.make_mock_response(expected_result[0], expected_result[1]))
85-
result = rf.result()[0]
85+
result = rf.result().one()
8686
self.assertEqual(result, expected_result)
8787

8888
def test_unknown_result_class(self):
@@ -128,7 +128,7 @@ def test_other_result_message_kind(self):
128128
rf.send_request()
129129
result = Mock(spec=ResultMessage, kind=999, results=[1, 2, 3])
130130
rf._set_result(None, None, None, result)
131-
self.assertEqual(rf.result()[0], result)
131+
self.assertEqual(rf.result().one(), result)
132132

133133
def test_heartbeat_defunct_deadlock(self):
134134
"""
@@ -396,7 +396,7 @@ def test_first_pool_shutdown(self):
396396
expected_result = (object(), object())
397397
rf._set_result(None, None, None, self.make_mock_response(expected_result[0], expected_result[1]))
398398

399-
result = rf.result()[0]
399+
result = rf.result().one()
400400
self.assertEqual(result, expected_result)
401401

402402
def test_timeout_getting_connection_from_pool(self):
@@ -420,7 +420,7 @@ def test_timeout_getting_connection_from_pool(self):
420420

421421
expected_result = (object(), object())
422422
rf._set_result(None, None, None, self.make_mock_response(expected_result[0], expected_result[1]))
423-
self.assertEqual(rf.result()[0], expected_result)
423+
self.assertEqual(rf.result().one(), expected_result)
424424

425425
# make sure the exception is recorded correctly
426426
self.assertEqual(rf._errors, {'ip1': exc})
@@ -438,7 +438,7 @@ def test_callback(self):
438438

439439
rf._set_result(None, None, None, self.make_mock_response(expected_result[0], expected_result[1]))
440440

441-
result = rf.result()[0]
441+
result = rf.result().one()
442442
self.assertEqual(result, expected_result)
443443

444444
callback.assert_called_once_with([expected_result], arg, **kwargs)
@@ -488,7 +488,7 @@ def test_multiple_callbacks(self):
488488

489489
rf._set_result(None, None, None, self.make_mock_response(expected_result[0], expected_result[1]))
490490

491-
result = rf.result()[0]
491+
result = rf.result().one()
492492
self.assertEqual(result, expected_result)
493493

494494
callback.assert_called_once_with([expected_result], arg, **kwargs)
@@ -561,7 +561,7 @@ def test_add_callbacks(self):
561561
errback=self.assertIsInstance, errback_args=(Exception,))
562562

563563
rf._set_result(None, None, None, self.make_mock_response(expected_result[0], expected_result[1]))
564-
self.assertEqual(rf.result()[0], expected_result)
564+
self.assertEqual(rf.result().one(), expected_result)
565565

566566
callback.assert_called_once_with([expected_result], arg, **kwargs)
567567

0 commit comments

Comments
 (0)