Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit d07c13c

Browse files
test: Add end-to-end SQL test (#12)
* test: Add end-to-end SQL test * Make black happy * Remove unnecessary `commit` * Select `id` column * XFail on windows * Add `pytest-github-actions-annotate-failures` to test env
1 parent fd4556c commit d07c13c

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ Source = "https://github.com/edgarrmondragon/sqlean-driver"
5656
source = "vcs"
5757

5858
[tool.hatch.envs.default]
59-
dependencies = ["coverage[toml]>=6.5", "pytest", "sqlalchemy=={env:SQLALCHEMY_VERSION:2.*}"]
59+
dependencies = [
60+
"coverage[toml]>=6.5",
61+
"pytest",
62+
"pytest-github-actions-annotate-failures",
63+
"sqlalchemy=={env:SQLALCHEMY_VERSION:2.*}",
64+
]
6065
[tool.hatch.envs.default.scripts]
6166
test = "pytest {args:tests}"
6267
test-cov = "coverage run -m pytest {args:tests}"

tests/test_driver.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from types import ModuleType
99

1010
import pytest
11-
from sqlalchemy import column, create_engine, func, select
11+
from sqlalchemy import Column, MetaData, Table, column, create_engine, func, insert, literal, select
1212
from sqlalchemy.exc import OperationalError
13+
from sqlalchemy.types import Integer, String
1314

1415
if t.TYPE_CHECKING:
1516
from sqlalchemy.engine import Engine
@@ -119,3 +120,50 @@ def test_extensions(extensions: str, query: Select, expected: tuple):
119120
with engine.connect() as conn:
120121
result = conn.execute(query)
121122
assert result.fetchone() == expected
123+
124+
125+
@pytest.mark.xfail(
126+
sys.platform == "win32",
127+
reason="'ipaddr' extension not available on Windows",
128+
)
129+
def test_e2e_sql():
130+
"""Test that the SQL works."""
131+
url = "sqlite+sqlean:///:memory:?extensions=all"
132+
engine = create_engine(url)
133+
134+
metadata = MetaData()
135+
table = Table(
136+
"example",
137+
metadata,
138+
Column("id", Integer, primary_key=True),
139+
Column("ip", String),
140+
Column("network", String),
141+
Column("family", Integer),
142+
)
143+
144+
metadata.create_all(engine)
145+
146+
with engine.connect() as conn:
147+
insert_sql = insert(table).from_select(
148+
[
149+
table.c.ip,
150+
table.c.network,
151+
table.c.family,
152+
],
153+
select(
154+
literal("192.168.1.1"),
155+
func.ipnetwork("192.168.1.1").label("network"),
156+
func.ipfamily("192.168.1.1").label("family"),
157+
),
158+
)
159+
conn.execute(insert_sql)
160+
161+
select_sql = select(
162+
table.c.id,
163+
table.c.ip,
164+
table.c.network,
165+
table.c.family,
166+
)
167+
result = conn.execute(select_sql)
168+
169+
assert result.fetchone() == (1, "192.168.1.1", "192.168.1.1/32", 4)

0 commit comments

Comments
 (0)