Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ classifiers = [
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Database :: Database Engines/Servers',
]
dependencies = ['typing-extensions >=4.6.0,!=4.7.0']
dependencies = ['typing-extensions >=4.6.0,!=4.7.0', 'anyio >=4.0.0']
dynamic = ['readme', 'version']

[project.optional-dependencies]
uvloop = ['uvloop >=0.19.0; sys_platform != "win32"']
dev = [
"mypy==1.11.0",
"pytest==8.3.1",
Expand All @@ -56,7 +57,7 @@ upgrade = false
[tool.pytest.ini_options]
testpaths = 'tests'
log_format = '%(name)s %(levelname)s: %(message)s'
asyncio_default_fixture_loop_scope = "function"
# Backends configured in tests/conftest.py (asyncio, trio, asyncio+uvloop)

[tool.coverage.run]
source = ['turso']
Expand All @@ -80,9 +81,10 @@ dev = [
"mypy-extensions>=1.1.0",
"pluggy>=1.6.0",
"pytest>=8.3.1",
"pytest-asyncio>=1.3.0",
"anyio[trio]>=4.0.0",
"pytest-cov>=5.0.0",
"requests>=2.32.5",
"ruff>=0.5.4",
"typing-extensions>=4.13.0",
"uvloop>=0.19.0; sys_platform != 'win32'",
]
2 changes: 2 additions & 0 deletions bindings/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
typing-extensions==4.12.2
# via pyturso (pyproject.toml)
anyio>=4.0.0
# via pyturso (pyproject.toml)
43 changes: 43 additions & 0 deletions bindings/python/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Pytest configuration for anyio backend testing.

Configures tests to run on:
- asyncio (standard library)
- asyncio + uvloop (fast event loop, Unix only)
- trio (alternative async framework)
"""

import sys

import pytest


def pytest_addoption(parser):
"""Add --uvloop option to enable uvloop testing."""
parser.addoption(
"--uvloop",
action="store_true",
default=False,
help="Include uvloop in asyncio backend tests",
)


@pytest.fixture(
params=[
pytest.param("asyncio", id="asyncio"),
pytest.param("trio", id="trio"),
]
+ ([pytest.param(("asyncio", {"use_uvloop": True}), id="asyncio+uvloop")] if sys.platform != "win32" else [])
)
def anyio_backend(request):
"""Fixture that parameterizes tests across all anyio backends.

This overrides the default anyio_backend fixture to include uvloop.
"""
# Only include uvloop if requested and available
backend = request.param
if isinstance(backend, tuple) and backend[1].get("use_uvloop"):
try:
import uvloop # noqa: F401
except ImportError:
pytest.skip("uvloop not available")
return backend
8 changes: 6 additions & 2 deletions bindings/python/tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s", force=True)


def connect(provider, database):
if provider == "turso":
return turso.connect(database)
Expand Down Expand Up @@ -1464,14 +1465,18 @@ def test_connection_exception_attributes_present(provider):
assert issubclass(conn.ProgrammingError, Exception)
conn.close()


@pytest.mark.parametrize("provider", ["sqlite3", "turso"])
def test_insert_returning_single_and_multiple_commit_without_consuming(provider):
# turso.setup_logging(level=logging.DEBUG)
conn = connect(provider, ":memory:")
try:
cur = conn.cursor()
cur.execute("CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)")
cur.execute("INSERT INTO t(name) VALUES (?), (?) RETURNING id", ("bob", "alice"),)
cur.execute(
"INSERT INTO t(name) VALUES (?), (?) RETURNING id",
("bob", "alice"),
)
cur.fetchone()
with pytest.raises(Exception):
conn.commit()
Expand All @@ -1494,4 +1499,3 @@ def test_pragma_integrity_check(provider):
assert row == ("ok",)

conn.close()

Loading
Loading