crate 0.35.2__py2.py3-none-any.whl → 1.0.0.dev0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crate/client/__init__.py +1 -1
- crate/testing/test_datetime_old.py +90 -0
- crate-1.0.0.dev0-py3.11-nspkg.pth +1 -0
- {crate-0.35.2.dist-info → crate-1.0.0.dev0.dist-info}/METADATA +15 -19
- crate-1.0.0.dev0.dist-info/RECORD +26 -0
- {crate-0.35.2.dist-info → crate-1.0.0.dev0.dist-info}/WHEEL +1 -1
- crate/client/sqlalchemy/__init__.py +0 -50
- crate/client/sqlalchemy/compat/__init__.py +0 -0
- crate/client/sqlalchemy/compat/api13.py +0 -156
- crate/client/sqlalchemy/compat/core10.py +0 -264
- crate/client/sqlalchemy/compat/core14.py +0 -359
- crate/client/sqlalchemy/compat/core20.py +0 -447
- crate/client/sqlalchemy/compiler.py +0 -318
- crate/client/sqlalchemy/dialect.py +0 -369
- crate/client/sqlalchemy/predicates/__init__.py +0 -99
- crate/client/sqlalchemy/sa_version.py +0 -28
- crate/client/sqlalchemy/support.py +0 -62
- crate/client/sqlalchemy/tests/__init__.py +0 -59
- crate/client/sqlalchemy/tests/array_test.py +0 -111
- crate/client/sqlalchemy/tests/bulk_test.py +0 -256
- crate/client/sqlalchemy/tests/compiler_test.py +0 -434
- crate/client/sqlalchemy/tests/connection_test.py +0 -129
- crate/client/sqlalchemy/tests/create_table_test.py +0 -313
- crate/client/sqlalchemy/tests/datetime_test.py +0 -90
- crate/client/sqlalchemy/tests/dialect_test.py +0 -156
- crate/client/sqlalchemy/tests/dict_test.py +0 -460
- crate/client/sqlalchemy/tests/function_test.py +0 -47
- crate/client/sqlalchemy/tests/insert_from_select_test.py +0 -85
- crate/client/sqlalchemy/tests/match_test.py +0 -137
- crate/client/sqlalchemy/tests/query_caching.py +0 -143
- crate/client/sqlalchemy/tests/update_test.py +0 -115
- crate/client/sqlalchemy/tests/warnings_test.py +0 -64
- crate/client/sqlalchemy/types.py +0 -277
- crate/client/tests.py +0 -416
- crate/testing/tests.py +0 -34
- crate-0.35.2-py3.11-nspkg.pth +0 -1
- crate-0.35.2.dist-info/RECORD +0 -55
- crate-0.35.2.dist-info/entry_points.txt +0 -2
- {crate-0.35.2.dist-info → crate-1.0.0.dev0.dist-info}/LICENSE +0 -0
- {crate-0.35.2.dist-info → crate-1.0.0.dev0.dist-info}/NOTICE +0 -0
- {crate-0.35.2.dist-info → crate-1.0.0.dev0.dist-info}/namespace_packages.txt +0 -0
- {crate-0.35.2.dist-info → crate-1.0.0.dev0.dist-info}/top_level.txt +0 -0
@@ -1,137 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8; -*-
|
2
|
-
#
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
8
|
-
# obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
-
# License for the specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
#
|
18
|
-
# However, if you have executed another commercial license agreement
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
21
|
-
|
22
|
-
|
23
|
-
from unittest import TestCase
|
24
|
-
from unittest.mock import MagicMock
|
25
|
-
|
26
|
-
import sqlalchemy as sa
|
27
|
-
from sqlalchemy.orm import Session
|
28
|
-
try:
|
29
|
-
from sqlalchemy.orm import declarative_base
|
30
|
-
except ImportError:
|
31
|
-
from sqlalchemy.ext.declarative import declarative_base
|
32
|
-
|
33
|
-
from crate.client.sqlalchemy.types import ObjectType
|
34
|
-
from crate.client.sqlalchemy.predicates import match
|
35
|
-
from crate.client.cursor import Cursor
|
36
|
-
|
37
|
-
|
38
|
-
fake_cursor = MagicMock(name='fake_cursor')
|
39
|
-
FakeCursor = MagicMock(name='FakeCursor', spec=Cursor)
|
40
|
-
FakeCursor.return_value = fake_cursor
|
41
|
-
|
42
|
-
|
43
|
-
class SqlAlchemyMatchTest(TestCase):
|
44
|
-
|
45
|
-
def setUp(self):
|
46
|
-
self.engine = sa.create_engine('crate://')
|
47
|
-
metadata = sa.MetaData()
|
48
|
-
self.quotes = sa.Table('quotes', metadata,
|
49
|
-
sa.Column('author', sa.String),
|
50
|
-
sa.Column('quote', sa.String))
|
51
|
-
self.session, self.Character = self.set_up_character_and_session()
|
52
|
-
self.maxDiff = None
|
53
|
-
|
54
|
-
def assertSQL(self, expected_str, actual_expr):
|
55
|
-
self.assertEqual(expected_str, str(actual_expr).replace('\n', ''))
|
56
|
-
|
57
|
-
def set_up_character_and_session(self):
|
58
|
-
Base = declarative_base()
|
59
|
-
|
60
|
-
class Character(Base):
|
61
|
-
__tablename__ = 'characters'
|
62
|
-
name = sa.Column(sa.String, primary_key=True)
|
63
|
-
info = sa.Column(ObjectType)
|
64
|
-
|
65
|
-
session = Session(bind=self.engine)
|
66
|
-
return session, Character
|
67
|
-
|
68
|
-
def test_simple_match(self):
|
69
|
-
query = self.session.query(self.Character.name) \
|
70
|
-
.filter(match(self.Character.name, 'Trillian'))
|
71
|
-
self.assertSQL(
|
72
|
-
"SELECT characters.name AS characters_name FROM characters " +
|
73
|
-
"WHERE match(characters.name, ?)",
|
74
|
-
query
|
75
|
-
)
|
76
|
-
|
77
|
-
def test_match_boost(self):
|
78
|
-
query = self.session.query(self.Character.name) \
|
79
|
-
.filter(match({self.Character.name: 0.5}, 'Trillian'))
|
80
|
-
self.assertSQL(
|
81
|
-
"SELECT characters.name AS characters_name FROM characters " +
|
82
|
-
"WHERE match((characters.name 0.5), ?)",
|
83
|
-
query
|
84
|
-
)
|
85
|
-
|
86
|
-
def test_muli_match(self):
|
87
|
-
query = self.session.query(self.Character.name) \
|
88
|
-
.filter(match({self.Character.name: 0.5,
|
89
|
-
self.Character.info['race']: 0.9},
|
90
|
-
'Trillian'))
|
91
|
-
self.assertSQL(
|
92
|
-
"SELECT characters.name AS characters_name FROM characters " +
|
93
|
-
"WHERE match(" +
|
94
|
-
"(characters.info['race'] 0.9, characters.name 0.5), ?" +
|
95
|
-
")",
|
96
|
-
query
|
97
|
-
)
|
98
|
-
|
99
|
-
def test_match_type_options(self):
|
100
|
-
query = self.session.query(self.Character.name) \
|
101
|
-
.filter(match({self.Character.name: 0.5,
|
102
|
-
self.Character.info['race']: 0.9},
|
103
|
-
'Trillian',
|
104
|
-
match_type='phrase',
|
105
|
-
options={'fuzziness': 3, 'analyzer': 'english'}))
|
106
|
-
self.assertSQL(
|
107
|
-
"SELECT characters.name AS characters_name FROM characters " +
|
108
|
-
"WHERE match(" +
|
109
|
-
"(characters.info['race'] 0.9, characters.name 0.5), ?" +
|
110
|
-
") using phrase with (analyzer=english, fuzziness=3)",
|
111
|
-
query
|
112
|
-
)
|
113
|
-
|
114
|
-
def test_score(self):
|
115
|
-
query = self.session.query(self.Character.name,
|
116
|
-
sa.literal_column('_score')) \
|
117
|
-
.filter(match(self.Character.name, 'Trillian'))
|
118
|
-
self.assertSQL(
|
119
|
-
"SELECT characters.name AS characters_name, _score " +
|
120
|
-
"FROM characters WHERE match(characters.name, ?)",
|
121
|
-
query
|
122
|
-
)
|
123
|
-
|
124
|
-
def test_options_without_type(self):
|
125
|
-
query = self.session.query(self.Character.name).filter(
|
126
|
-
match({self.Character.name: 0.5, self.Character.info['race']: 0.9},
|
127
|
-
'Trillian',
|
128
|
-
options={'boost': 10.0})
|
129
|
-
)
|
130
|
-
err = None
|
131
|
-
try:
|
132
|
-
str(query)
|
133
|
-
except ValueError as e:
|
134
|
-
err = e
|
135
|
-
msg = "missing match_type. " + \
|
136
|
-
"It's not allowed to specify options without match_type"
|
137
|
-
self.assertEqual(str(err), msg)
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8; -*-
|
2
|
-
#
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
8
|
-
# obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
-
# License for the specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
#
|
18
|
-
# However, if you have executed another commercial license agreement
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
21
|
-
|
22
|
-
from __future__ import absolute_import
|
23
|
-
from unittest import TestCase, skipIf
|
24
|
-
|
25
|
-
import sqlalchemy as sa
|
26
|
-
from sqlalchemy.orm import Session
|
27
|
-
from sqlalchemy.sql.operators import eq
|
28
|
-
|
29
|
-
from crate.client.sqlalchemy import SA_VERSION, SA_1_4
|
30
|
-
from crate.testing.settings import crate_host
|
31
|
-
|
32
|
-
try:
|
33
|
-
from sqlalchemy.orm import declarative_base
|
34
|
-
except ImportError:
|
35
|
-
from sqlalchemy.ext.declarative import declarative_base
|
36
|
-
|
37
|
-
from crate.client.sqlalchemy.types import ObjectType, ObjectArray
|
38
|
-
|
39
|
-
|
40
|
-
class SqlAlchemyQueryCompilationCaching(TestCase):
|
41
|
-
|
42
|
-
def setUp(self):
|
43
|
-
self.engine = sa.create_engine(f"crate://{crate_host}")
|
44
|
-
self.metadata = sa.MetaData(schema="testdrive")
|
45
|
-
self.session = Session(bind=self.engine)
|
46
|
-
self.Character = self.setup_entity()
|
47
|
-
|
48
|
-
def setup_entity(self):
|
49
|
-
"""
|
50
|
-
Define ORM entity.
|
51
|
-
"""
|
52
|
-
Base = declarative_base(metadata=self.metadata)
|
53
|
-
|
54
|
-
class Character(Base):
|
55
|
-
__tablename__ = 'characters'
|
56
|
-
name = sa.Column(sa.String, primary_key=True)
|
57
|
-
age = sa.Column(sa.Integer)
|
58
|
-
data = sa.Column(ObjectType)
|
59
|
-
data_list = sa.Column(ObjectArray)
|
60
|
-
|
61
|
-
return Character
|
62
|
-
|
63
|
-
def setup_data(self):
|
64
|
-
"""
|
65
|
-
Insert two records into the `characters` table.
|
66
|
-
"""
|
67
|
-
self.metadata.drop_all(self.engine)
|
68
|
-
self.metadata.create_all(self.engine)
|
69
|
-
|
70
|
-
Character = self.Character
|
71
|
-
char1 = Character(name='Trillian', data={'x': 1}, data_list=[{'foo': 1, 'bar': 10}])
|
72
|
-
char2 = Character(name='Slartibartfast', data={'y': 2}, data_list=[{'bar': 2}])
|
73
|
-
self.session.add(char1)
|
74
|
-
self.session.add(char2)
|
75
|
-
self.session.commit()
|
76
|
-
self.session.execute(sa.text("REFRESH TABLE testdrive.characters;"))
|
77
|
-
|
78
|
-
@skipIf(SA_VERSION < SA_1_4, "On SA13, the 'ResultProxy' object has no attribute 'scalar_one'")
|
79
|
-
def test_object_multiple_select_legacy(self):
|
80
|
-
"""
|
81
|
-
The SQLAlchemy implementation of CrateDB's `OBJECT` type offers indexed
|
82
|
-
access to the instance's content in form of a dictionary. Thus, it must
|
83
|
-
not use `cache_ok = True` on its implementation, i.e. this part of the
|
84
|
-
compiled SQL clause must not be cached.
|
85
|
-
|
86
|
-
This test verifies that two subsequent `SELECT` statements are translated
|
87
|
-
well, and don't trip on incorrect SQL compiled statement caching.
|
88
|
-
|
89
|
-
This variant uses direct value matching on the `OBJECT`s attribute.
|
90
|
-
"""
|
91
|
-
self.setup_data()
|
92
|
-
Character = self.Character
|
93
|
-
|
94
|
-
selectable = sa.select(Character).where(Character.data['x'] == 1)
|
95
|
-
result = self.session.execute(selectable).scalar_one().data
|
96
|
-
self.assertEqual({"x": 1}, result)
|
97
|
-
|
98
|
-
selectable = sa.select(Character).where(Character.data['y'] == 2)
|
99
|
-
result = self.session.execute(selectable).scalar_one().data
|
100
|
-
self.assertEqual({"y": 2}, result)
|
101
|
-
|
102
|
-
@skipIf(SA_VERSION < SA_1_4, "On SA13, the 'ResultProxy' object has no attribute 'scalar_one'")
|
103
|
-
def test_object_multiple_select_modern(self):
|
104
|
-
"""
|
105
|
-
The SQLAlchemy implementation of CrateDB's `OBJECT` type offers indexed
|
106
|
-
access to the instance's content in form of a dictionary. Thus, it must
|
107
|
-
not use `cache_ok = True` on its implementation, i.e. this part of the
|
108
|
-
compiled SQL clause must not be cached.
|
109
|
-
|
110
|
-
This test verifies that two subsequent `SELECT` statements are translated
|
111
|
-
well, and don't trip on incorrect SQL compiled statement caching.
|
112
|
-
|
113
|
-
This variant uses comparator method matching on the `OBJECT`s attribute.
|
114
|
-
"""
|
115
|
-
self.setup_data()
|
116
|
-
Character = self.Character
|
117
|
-
|
118
|
-
selectable = sa.select(Character).where(Character.data['x'].as_integer() == 1)
|
119
|
-
result = self.session.execute(selectable).scalar_one().data
|
120
|
-
self.assertEqual({"x": 1}, result)
|
121
|
-
|
122
|
-
selectable = sa.select(Character).where(Character.data['y'].as_integer() == 2)
|
123
|
-
result = self.session.execute(selectable).scalar_one().data
|
124
|
-
self.assertEqual({"y": 2}, result)
|
125
|
-
|
126
|
-
@skipIf(SA_VERSION < SA_1_4, "On SA13, the 'ResultProxy' object has no attribute 'scalar_one'")
|
127
|
-
def test_objectarray_multiple_select(self):
|
128
|
-
"""
|
129
|
-
The SQLAlchemy implementation of CrateDB's `ARRAY` type in form of the
|
130
|
-
`ObjectArray`, does *not* offer indexed access to the instance's content.
|
131
|
-
Thus, using `cache_ok = True` on that type should be sane, and not mess
|
132
|
-
up SQLAlchemy's SQL compiled statement caching.
|
133
|
-
"""
|
134
|
-
self.setup_data()
|
135
|
-
Character = self.Character
|
136
|
-
|
137
|
-
selectable = sa.select(Character).where(Character.data_list['foo'].any(1, operator=eq))
|
138
|
-
result = self.session.execute(selectable).scalar_one().data
|
139
|
-
self.assertEqual({"x": 1}, result)
|
140
|
-
|
141
|
-
selectable = sa.select(Character).where(Character.data_list['bar'].any(2, operator=eq))
|
142
|
-
result = self.session.execute(selectable).scalar_one().data
|
143
|
-
self.assertEqual({"y": 2}, result)
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8; -*-
|
2
|
-
#
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
8
|
-
# obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
-
# License for the specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
#
|
18
|
-
# However, if you have executed another commercial license agreement
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
21
|
-
|
22
|
-
from datetime import datetime
|
23
|
-
from unittest import TestCase
|
24
|
-
from unittest.mock import patch, MagicMock
|
25
|
-
|
26
|
-
from crate.client.sqlalchemy.types import ObjectType
|
27
|
-
|
28
|
-
import sqlalchemy as sa
|
29
|
-
from sqlalchemy.orm import Session
|
30
|
-
try:
|
31
|
-
from sqlalchemy.orm import declarative_base
|
32
|
-
except ImportError:
|
33
|
-
from sqlalchemy.ext.declarative import declarative_base
|
34
|
-
|
35
|
-
from crate.client.cursor import Cursor
|
36
|
-
|
37
|
-
|
38
|
-
fake_cursor = MagicMock(name='fake_cursor')
|
39
|
-
fake_cursor.rowcount = 1
|
40
|
-
FakeCursor = MagicMock(name='FakeCursor', spec=Cursor)
|
41
|
-
FakeCursor.return_value = fake_cursor
|
42
|
-
|
43
|
-
|
44
|
-
class SqlAlchemyUpdateTest(TestCase):
|
45
|
-
|
46
|
-
def setUp(self):
|
47
|
-
self.engine = sa.create_engine('crate://')
|
48
|
-
self.base = declarative_base()
|
49
|
-
|
50
|
-
class Character(self.base):
|
51
|
-
__tablename__ = 'characters'
|
52
|
-
|
53
|
-
name = sa.Column(sa.String, primary_key=True)
|
54
|
-
age = sa.Column(sa.Integer)
|
55
|
-
obj = sa.Column(ObjectType)
|
56
|
-
ts = sa.Column(sa.DateTime, onupdate=datetime.utcnow)
|
57
|
-
|
58
|
-
self.character = Character
|
59
|
-
self.session = Session(bind=self.engine)
|
60
|
-
|
61
|
-
@patch('crate.client.connection.Cursor', FakeCursor)
|
62
|
-
def test_onupdate_is_triggered(self):
|
63
|
-
char = self.character(name='Arthur')
|
64
|
-
self.session.add(char)
|
65
|
-
self.session.commit()
|
66
|
-
now = datetime.utcnow()
|
67
|
-
|
68
|
-
fake_cursor.fetchall.return_value = [('Arthur', None)]
|
69
|
-
fake_cursor.description = (
|
70
|
-
('characters_name', None, None, None, None, None, None),
|
71
|
-
('characters_ts', None, None, None, None, None, None),
|
72
|
-
)
|
73
|
-
|
74
|
-
char.age = 40
|
75
|
-
self.session.commit()
|
76
|
-
|
77
|
-
expected_stmt = ("UPDATE characters SET age = ?, "
|
78
|
-
"ts = ? WHERE characters.name = ?")
|
79
|
-
args, kwargs = fake_cursor.execute.call_args
|
80
|
-
stmt = args[0]
|
81
|
-
args = args[1]
|
82
|
-
self.assertEqual(expected_stmt, stmt)
|
83
|
-
self.assertEqual(40, args[0])
|
84
|
-
dt = datetime.strptime(args[1], '%Y-%m-%dT%H:%M:%S.%fZ')
|
85
|
-
self.assertIsInstance(dt, datetime)
|
86
|
-
self.assertGreater(dt, now)
|
87
|
-
self.assertEqual('Arthur', args[2])
|
88
|
-
|
89
|
-
@patch('crate.client.connection.Cursor', FakeCursor)
|
90
|
-
def test_bulk_update(self):
|
91
|
-
"""
|
92
|
-
Checks whether bulk updates work correctly
|
93
|
-
on native types and Crate types.
|
94
|
-
"""
|
95
|
-
before_update_time = datetime.utcnow()
|
96
|
-
|
97
|
-
self.session.query(self.character).update({
|
98
|
-
# change everyone's name to Julia
|
99
|
-
self.character.name: 'Julia',
|
100
|
-
self.character.obj: {'favorite_book': 'Romeo & Juliet'}
|
101
|
-
})
|
102
|
-
|
103
|
-
self.session.commit()
|
104
|
-
|
105
|
-
expected_stmt = ("UPDATE characters SET "
|
106
|
-
"name = ?, obj = ?, ts = ?")
|
107
|
-
args, kwargs = fake_cursor.execute.call_args
|
108
|
-
stmt = args[0]
|
109
|
-
args = args[1]
|
110
|
-
self.assertEqual(expected_stmt, stmt)
|
111
|
-
self.assertEqual('Julia', args[0])
|
112
|
-
self.assertEqual({'favorite_book': 'Romeo & Juliet'}, args[1])
|
113
|
-
dt = datetime.strptime(args[2], '%Y-%m-%dT%H:%M:%S.%fZ')
|
114
|
-
self.assertIsInstance(dt, datetime)
|
115
|
-
self.assertGreater(dt, before_update_time)
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8; -*-
|
2
|
-
import sys
|
3
|
-
import warnings
|
4
|
-
from unittest import TestCase, skipIf
|
5
|
-
|
6
|
-
from crate.client.sqlalchemy import SA_1_4, SA_VERSION
|
7
|
-
from crate.testing.util import ExtraAssertions
|
8
|
-
|
9
|
-
|
10
|
-
class SqlAlchemyWarningsTest(TestCase, ExtraAssertions):
|
11
|
-
"""
|
12
|
-
Verify a few `DeprecationWarning` spots.
|
13
|
-
|
14
|
-
https://docs.python.org/3/library/warnings.html#testing-warnings
|
15
|
-
"""
|
16
|
-
|
17
|
-
@skipIf(SA_VERSION >= SA_1_4, "There is no deprecation warning for "
|
18
|
-
"SQLAlchemy 1.3 on higher versions")
|
19
|
-
def test_sa13_deprecation_warning(self):
|
20
|
-
"""
|
21
|
-
Verify that a `DeprecationWarning` is issued when running SQLAlchemy 1.3.
|
22
|
-
"""
|
23
|
-
with warnings.catch_warnings(record=True) as w:
|
24
|
-
|
25
|
-
# Cause all warnings to always be triggered.
|
26
|
-
warnings.simplefilter("always")
|
27
|
-
|
28
|
-
# Trigger a warning by importing the SQLAlchemy dialect module.
|
29
|
-
# Because it already has been loaded, unload it beforehand.
|
30
|
-
del sys.modules["crate.client.sqlalchemy"]
|
31
|
-
import crate.client.sqlalchemy # noqa: F401
|
32
|
-
|
33
|
-
# Verify details of the SA13 EOL/deprecation warning.
|
34
|
-
self.assertEqual(len(w), 1)
|
35
|
-
self.assertIsSubclass(w[-1].category, DeprecationWarning)
|
36
|
-
self.assertIn("SQLAlchemy 1.3 is effectively EOL.", str(w[-1].message))
|
37
|
-
|
38
|
-
def test_craty_object_deprecation_warning(self):
|
39
|
-
"""
|
40
|
-
Verify that a `DeprecationWarning` is issued when accessing the deprecated
|
41
|
-
module variables `Craty`, and `Object`. The new type is called `ObjectType`.
|
42
|
-
"""
|
43
|
-
|
44
|
-
with warnings.catch_warnings(record=True) as w:
|
45
|
-
|
46
|
-
# Import the deprecated symbol.
|
47
|
-
from crate.client.sqlalchemy.types import Craty # noqa: F401
|
48
|
-
|
49
|
-
# Verify details of the deprecation warning.
|
50
|
-
self.assertEqual(len(w), 1)
|
51
|
-
self.assertIsSubclass(w[-1].category, DeprecationWarning)
|
52
|
-
self.assertIn("Craty is deprecated and will be removed in future releases. "
|
53
|
-
"Please use ObjectType instead.", str(w[-1].message))
|
54
|
-
|
55
|
-
with warnings.catch_warnings(record=True) as w:
|
56
|
-
|
57
|
-
# Import the deprecated symbol.
|
58
|
-
from crate.client.sqlalchemy.types import Object # noqa: F401
|
59
|
-
|
60
|
-
# Verify details of the deprecation warning.
|
61
|
-
self.assertEqual(len(w), 1)
|
62
|
-
self.assertIsSubclass(w[-1].category, DeprecationWarning)
|
63
|
-
self.assertIn("Object is deprecated and will be removed in future releases. "
|
64
|
-
"Please use ObjectType instead.", str(w[-1].message))
|