Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test_sqlalchemy sqlalchemy 2.0 warnings #291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions _appmap/test/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
String,
Table,
create_engine,
text,
)

import appmap.sqlalchemy # pylint: disable=unused-import
Expand All @@ -23,10 +24,8 @@
class TestSQLAlchemy(AppMapTestBase):
@staticmethod
def test_sql_capture(connection, events):
connection.execute("SELECT 1")
assert events[0].sql_query == DictIncluding(
{"sql": "SELECT 1", "database_type": "sqlite"}
)
connection.execute(text("SELECT 1"))
assert events[0].sql_query == DictIncluding({"sql": "SELECT 1", "database_type": "sqlite"})
assert events[0].sql_query["server_version"].startswith("3.")
assert Metadata()["frameworks"] == [{"name": "SQLAlchemy", "version": version("sqlalchemy")}]

Expand All @@ -38,27 +37,26 @@ def test_capture_ddl(events, schema):
# pylint: disable=unused-argument
def test_capture_insert(self, connection, schema, events):
ins = self.users.insert().values(name="jack", fullname="Jack Jones")
connection.execute(ins)
assert (
events[-2].sql_query["sql"]
== "INSERT INTO users (name, fullname) VALUES (?, ?)"
)
with connection.begin():
connection.execute(ins)
assert events[-2].sql_query["sql"] == "INSERT INTO users (name, fullname) VALUES (?, ?)"

# pylint: disable=unused-argument
def test_capture_insert_many(self, connection, schema, events):
connection.execute(
self.addresses.insert(),
[
{"user_id": 1, "email_address": "[email protected]"},
{"user_id": 1, "email_address": "[email protected]"},
{"user_id": 2, "email_address": "[email protected]"},
{"user_id": 2, "email_address": "[email protected]"},
],
)
assert (
events[-2].sql_query["sql"]
== "-- 4 times\nINSERT INTO addresses (user_id, email_address) VALUES (?, ?)"
)
with connection.begin():
connection.execute(
self.addresses.insert(),
[
{"user_id": 1, "email_address": "[email protected]"},
{"user_id": 1, "email_address": "[email protected]"},
{"user_id": 2, "email_address": "[email protected]"},
{"user_id": 2, "email_address": "[email protected]"},
],
)
assert (
events[-2].sql_query["sql"]
== "-- 4 times\nINSERT INTO addresses (user_id, email_address) VALUES (?, ?)"
)

@staticmethod
@pytest.fixture
Expand Down