Skip to content

Commit 787f97c

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 c3c8b89 commit 787f97c

30 files changed

+117
-58
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
@@ -41,7 +41,7 @@
4141
from cassandra import DriverException
4242

4343
DATETIME_EPOC = datetime.datetime(1970, 1, 1)
44-
UTC_DATETIME_EPOC = datetime.datetime.utcfromtimestamp(0)
44+
UTC_DATETIME_EPOC = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
4545

4646
_nan = float('nan')
4747

pytest.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,20 @@ 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
20+
ignore:CSR support in pyOpenSSL is deprecated.*:DeprecationWarning
21+
ignore:get_elliptic_curves is deprecated:DeprecationWarning
22+
ignore:get_elliptic_curve 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/columns/test_counter_column.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def tearDownClass(cls):
7878

7979
def test_updates(self):
8080
""" Tests that counter updates work as intended """
81-
instance = TestCounterModel.create()
81+
instance = TestCounterModel()
8282
instance.counter += 5
83-
instance.save()
83+
instance.update()
8484

8585
actual = TestCounterModel.get(partition=instance.partition)
8686
assert actual.counter == 5
@@ -103,7 +103,7 @@ def test_update_from_none(self):
103103
""" Tests that updating from None uses a create statement """
104104
instance = TestCounterModel()
105105
instance.counter += 1
106-
instance.save()
106+
instance.update()
107107

108108
new = TestCounterModel.get(partition=instance.partition)
109109
assert new.counter == 1
@@ -115,15 +115,15 @@ def test_new_instance_defaults_to_zero(self):
115115

116116
def test_save_after_no_update(self):
117117
expected_value = 15
118-
instance = TestCounterModel.create()
118+
instance = TestCounterModel()
119119
instance.update(counter=expected_value)
120120

121121
# read back
122122
instance = TestCounterModel.get(partition=instance.partition)
123123
self.assertEqual(instance.counter, expected_value)
124124

125125
# save after doing nothing
126-
instance.save()
126+
instance.update()
127127
self.assertEqual(instance.counter, expected_value)
128128

129129
# make sure there was no increment

tests/integration/cqlengine/connections/test_connection.py

Lines changed: 3 additions & 1 deletion
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

1819
from cassandra import ConsistencyLevel
@@ -130,7 +131,8 @@ class ConnectionModel(Model):
130131
key = columns.Integer(primary_key=True)
131132
some_data = columns.Text()
132133

133-
134+
@pytest.mark.filterwarnings("ignore:Setting the consistency level at the session level will be removed")
135+
@pytest.mark.filterwarnings("ignore:Legacy execution parameters will be removed")
134136
class ConnectionInitTest(unittest.TestCase):
135137
def test_default_connection_uses_legacy(self):
136138
connection.default()

tests/integration/cqlengine/management/test_management.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
import mock
1718
import logging
@@ -382,6 +383,7 @@ class TestIndexSetModel(Model):
382383
mixed_tuple = columns.Tuple(columns.Text, columns.Integer, columns.Text, index=True)
383384

384385

386+
@pytest.mark.filterwarnings("ignore:Model __table_name_case_sensitive__ will be removed")
385387
class IndexTests(BaseCassEngTestCase):
386388

387389
def setUp(self):

tests/integration/cqlengine/model/test_model.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 patch
1718

@@ -125,6 +126,7 @@ class TestModel(Model):
125126
# .. but we can still get the bare CF name
126127
self.assertEqual(TestModel.column_family_name(include_keyspace=False), "test_model")
127128

129+
@pytest.mark.filterwarnings("ignore:__table_name_case_sensitive__ will be removed")
128130
def test_column_family_case_sensitive(self):
129131
"""
130132
Test to ensure case sensitivity is honored when __table_name_case_sensitive__ flag is set

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: 4 additions & 3 deletions
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

@@ -1566,7 +1567,7 @@ def test_deprecation_warnings_legacy_parameters(self):
15661567
15671568
@test_category logs
15681569
"""
1569-
with warnings.catch_warnings(record=True) as w:
1570+
with warnings.catch_warnings(record=True, action='once') as w:
15701571
TestCluster(load_balancing_policy=RoundRobinPolicy())
15711572
logging.info(w)
15721573
self.assertGreaterEqual(len(w), 1)
@@ -1585,7 +1586,7 @@ def test_deprecation_warnings_meta_refreshed(self):
15851586
15861587
@test_category logs
15871588
"""
1588-
with warnings.catch_warnings(record=True) as w:
1589+
with warnings.catch_warnings(record=True, action='once') as w:
15891590
cluster = TestCluster()
15901591
cluster.set_meta_refresh_enabled(True)
15911592
logging.info(w)

tests/integration/standard/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def wait_for_connections(self, host, cluster):
182182
while(retry < 300):
183183
retry += 1
184184
connections = self.fetch_connections(host, cluster)
185-
if len(connections) is not 0:
185+
if len(connections) != 0:
186186
return connections
187187
time.sleep(.1)
188188
self.fail("No new connections found")
@@ -192,7 +192,7 @@ def wait_for_no_connections(self, host, cluster):
192192
while(retry < 100):
193193
retry += 1
194194
connections = self.fetch_connections(host, cluster)
195-
if len(connections) is 0:
195+
if len(connections) == 0:
196196
return
197197
time.sleep(.5)
198198
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
@@ -1677,7 +1677,7 @@ def test_function_no_parameters(self):
16771677

16781678
with self.VerifiedFunction(self, **kwargs) as vf:
16791679
fn_meta = self.keyspace_function_meta[vf.signature]
1680-
self.assertRegex(fn_meta.as_cql_query(), "CREATE FUNCTION.*%s\(\) .*" % kwargs['name'])
1680+
self.assertRegex(fn_meta.as_cql_query(), r"CREATE FUNCTION.*%s\(\) .*" % kwargs['name'])
16811681

16821682
def test_functions_follow_keyspace_alter(self):
16831683
"""
@@ -1725,12 +1725,12 @@ def test_function_cql_called_on_null(self):
17251725
kwargs['called_on_null_input'] = True
17261726
with self.VerifiedFunction(self, **kwargs) as vf:
17271727
fn_meta = self.keyspace_function_meta[vf.signature]
1728-
self.assertRegex(fn_meta.as_cql_query(), "CREATE FUNCTION.*\) CALLED ON NULL INPUT RETURNS .*")
1728+
self.assertRegex(fn_meta.as_cql_query(), r"CREATE FUNCTION.*\) CALLED ON NULL INPUT RETURNS .*")
17291729

17301730
kwargs['called_on_null_input'] = False
17311731
with self.VerifiedFunction(self, **kwargs) as vf:
17321732
fn_meta = self.keyspace_function_meta[vf.signature]
1733-
self.assertRegex(fn_meta.as_cql_query(), "CREATE FUNCTION.*\) RETURNS NULL ON NULL INPUT RETURNS .*")
1733+
self.assertRegex(fn_meta.as_cql_query(), r"CREATE FUNCTION.*\) RETURNS NULL ON NULL INPUT RETURNS .*")
17341734

17351735

17361736
@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

0 commit comments

Comments
 (0)