Skip to content

Commit 519ba06

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 7e0b02d commit 519ba06

26 files changed

+100
-50
lines changed

cassandra/cqlengine/connection.py

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

329329
from cassandra.cqlengine import models

cassandra/cqlengine/query.py

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

cassandra/datastax/cloud/__init__.py

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

2323
_HAS_SSL = True
2424
try:
25-
from ssl import SSLContext, PROTOCOL_TLS, CERT_REQUIRED
25+
from ssl import SSLContext, PROTOCOL_TLS_CLIENT, CERT_REQUIRED
2626
except:
2727
_HAS_SSL = False
2828

@@ -169,7 +169,7 @@ def parse_metadata_info(config, http_data):
169169

170170

171171
def _ssl_context_from_cert(ca_cert_location, cert_location, key_location):
172-
ssl_context = SSLContext(PROTOCOL_TLS)
172+
ssl_context = SSLContext(PROTOCOL_TLS_CLIENT)
173173
ssl_context.load_verify_locations(ca_cert_location)
174174
ssl_context.verify_mode = CERT_REQUIRED
175175
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
@@ -40,7 +40,7 @@
4040
from cassandra import DriverException
4141

4242
DATETIME_EPOC = datetime.datetime(1970, 1, 1)
43-
UTC_DATETIME_EPOC = datetime.datetime.utcfromtimestamp(0)
43+
UTC_DATETIME_EPOC = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
4444

4545
_nan = float('nan')
4646

pytest.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,17 @@ 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
16+
ignore:pkg_resources is deprecated as an API:DeprecationWarning:gevent.events
17+
ignore:.*pkg_resources.declare_namespace.*:DeprecationWarning
18+
ignore:"@coroutine" decorator is deprecated since Python 3.8:DeprecationWarning:asynctest.*
19+
ignore:The asyncore module is deprecated and will be removed in Python 3.12:DeprecationWarning:asyncore.*

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_cluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Copyright DataStax, Inc.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -150,7 +151,7 @@ def test_raise_error_on_control_connection_timeout(self):
150151
get_node(1).pause()
151152
cluster = TestCluster(contact_points=['127.0.0.1'], connect_timeout=1)
152153

153-
with self.assertRaisesRegex(NoHostAvailable, "OperationTimedOut\('errors=Timed out creating connection \(1 seconds\)"):
154+
with self.assertRaisesRegex(NoHostAvailable, r"OperationTimedOut\('errors=Timed out creating connection \(1 seconds\)"):
154155
cluster.connect()
155156
cluster.shutdown()
156157

tests/integration/standard/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def wait_for_connections(self, host, cluster):
180180
while(retry < 300):
181181
retry += 1
182182
connections = self.fetch_connections(host, cluster)
183-
if len(connections) is not 0:
183+
if len(connections) != 0:
184184
return connections
185185
time.sleep(.1)
186186
self.fail("No new connections found")
@@ -190,7 +190,7 @@ def wait_for_no_connections(self, host, cluster):
190190
while(retry < 100):
191191
retry += 1
192192
connections = self.fetch_connections(host, cluster)
193-
if len(connections) is 0:
193+
if len(connections) == 0:
194194
return
195195
time.sleep(.5)
196196
self.fail("Connections never cleared")

tests/integration/standard/test_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ def test_function_no_parameters(self):
16401640

16411641
with self.VerifiedFunction(self, **kwargs) as vf:
16421642
fn_meta = self.keyspace_function_meta[vf.signature]
1643-
self.assertRegex(fn_meta.as_cql_query(), "CREATE FUNCTION.*%s\(\) .*" % kwargs['name'])
1643+
self.assertRegex(fn_meta.as_cql_query(), r"CREATE FUNCTION.*%s\(\) .*" % kwargs['name'])
16441644

16451645
def test_functions_follow_keyspace_alter(self):
16461646
"""
@@ -1688,12 +1688,12 @@ def test_function_cql_called_on_null(self):
16881688
kwargs['called_on_null_input'] = True
16891689
with self.VerifiedFunction(self, **kwargs) as vf:
16901690
fn_meta = self.keyspace_function_meta[vf.signature]
1691-
self.assertRegex(fn_meta.as_cql_query(), "CREATE FUNCTION.*\) CALLED ON NULL INPUT RETURNS .*")
1691+
self.assertRegex(fn_meta.as_cql_query(), r"CREATE FUNCTION.*\) CALLED ON NULL INPUT RETURNS .*")
16921692

16931693
kwargs['called_on_null_input'] = False
16941694
with self.VerifiedFunction(self, **kwargs) as vf:
16951695
fn_meta = self.keyspace_function_meta[vf.signature]
1696-
self.assertRegex(fn_meta.as_cql_query(), "CREATE FUNCTION.*\) RETURNS NULL ON NULL INPUT RETURNS .*")
1696+
self.assertRegex(fn_meta.as_cql_query(), r"CREATE FUNCTION.*\) RETURNS NULL ON NULL INPUT RETURNS .*")
16971697

16981698

16991699
@requires_java_udf

tests/integration/standard/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_client_ip_in_trace(self):
167167
client_ip = trace.client
168168

169169
# Ip address should be in the local_host range
170-
pat = re.compile("127.0.0.\d{1,3}")
170+
pat = re.compile(r"127.0.0.\d{1,3}")
171171

172172
# Ensure that ip is set
173173
self.assertIsNotNone(client_ip, "Client IP was not set in trace with C* >= 2.2")

tests/integration/standard/test_scylla_cloud.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import warnings
23
import os.path
34
from unittest import TestCase
45
from ccmlib.utils.ssl_utils import generate_ssl_stores
@@ -11,7 +12,9 @@
1112
from cassandra.io.libevreactor import LibevConnection
1213
supported_connection_classes = [LibevConnection, TwistedConnection]
1314
try:
14-
from cassandra.io.asyncorereactor import AsyncoreConnection
15+
with warnings.catch_warnings():
16+
warnings.filterwarnings("ignore", category=DeprecationWarning, message="The asyncore module is deprecated")
17+
from cassandra.io.asyncorereactor import AsyncoreConnection
1518
supported_connection_classes += [AsyncoreConnection]
1619
except ImportError:
1720
pass

tests/unit/advanced/test_graph.py

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

256256
def test_init_unknown_kwargs(self):
257257
with warnings.catch_warnings(record=True) as w:
258+
warnings.simplefilter("always")
258259
GraphOptions(unknown_param=42)
259260
self.assertEqual(len(w), 1)
260261
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
@@ -122,7 +122,7 @@ def submit_and_wait_for_completion(unit_test, create_timer, start, end, incremen
122122
pending_callbacks.append(callback)
123123

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

235-
def test_successful_connection(self):
235+
def _test_successful_connection(self):
236236
c = self.make_connection()
237237

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

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

@@ -271,7 +274,7 @@ def test_sslwantwrite_on_buffer_size(self):
271274
error_class=ssl.SSLError)
272275

273276
def _check_error_recovery_on_buffer_size(self, error_code, error_class=socket_error):
274-
c = self.test_successful_connection()
277+
c = self._test_successful_connection()
275278

276279
# current data, used by the recv side_effect
277280
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

@@ -274,6 +275,9 @@ def test_default_exec_parameters(self):
274275
self.assertEqual(cluster.profile_manager.default.row_factory, named_tuple_factory)
275276

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

323327
@mock_session_pools
328+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
329+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed in 4.0:DeprecationWarning")
324330
def test_statement_params_override_legacy(self):
325331
cluster = Cluster(load_balancing_policy=RoundRobinPolicy(), default_retry_policy=DowngradingConsistencyRetryPolicy())
326332
self.assertEqual(cluster._config_mode, _ConfigMode.LEGACY)
@@ -342,6 +348,7 @@ def test_statement_params_override_legacy(self):
342348
self._verify_response_future_profile(rf, expected_profile)
343349

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

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

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

526+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed in 4.0:DeprecationWarning")
515527
def test_no_warning_on_contact_points_with_lbp_legacy_mode(self):
516528
"""
517529
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
@@ -848,9 +848,9 @@ def test_strip_frozen(self):
848848
argument_to_expected_results = [
849849
('int', 'int'),
850850
('tuple<text>', 'tuple<text>'),
851-
(r'map<"!@#$%^&*()[]\ frozen >>>", int>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'), # A valid UDT name
851+
(r'map<"!@#$%^&*()[]\\ frozen >>>", int>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'), # A valid UDT name
852852
('frozen<tuple<text>>', 'tuple<text>'),
853-
(r'frozen<map<"!@#$%^&*()[]\ frozen >>>", int>>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'),
853+
(r'frozen<map<"!@#$%^&*()[]\\ frozen >>>", int>>', r'map<"!@#$%^&*()[]\ frozen >>>", int>'),
854854
('frozen<map<frozen<tuple<int, frozen<list<text>>, int>>, frozen<map<int, frozen<tuple<int>>>>>>',
855855
'map<tuple<int, list<text>, int>, map<int, tuple<int>>>'),
856856
]

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
@@ -1179,6 +1180,7 @@ def test_unavailable(self):
11791180
self.assertEqual(consistency, None)
11801181

11811182

1183+
@pytest.mark.filterwarnings("ignore:DowngradingConsistencyRetryPolicy:DeprecationWarning")
11821184
class DowngradingConsistencyRetryPolicyTest(unittest.TestCase):
11831185

11841186
def test_read_timeout(self):

0 commit comments

Comments
 (0)