Skip to content

Commit d498fa9

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 c53ff5c commit d498fa9

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
@@ -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: 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
@@ -181,7 +181,7 @@ def wait_for_connections(self, host, cluster):
181181
while(retry < 300):
182182
retry += 1
183183
connections = self.fetch_connections(host, cluster)
184-
if len(connections) is not 0:
184+
if len(connections) != 0:
185185
return connections
186186
time.sleep(.1)
187187
self.fail("No new connections found")
@@ -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/integration/standard/test_metadata.py

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

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

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

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

16991699

17001700
@requires_java_udf

0 commit comments

Comments
 (0)