mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-24 03:34:18 +01:00
Format Python bindings code using Ruff
- Use double quotes (Ruff/Black default) - Configure some set of linters to use with Ruff
This commit is contained in:
@@ -14,16 +14,16 @@ from ._limbo import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'__version__',
|
"__version__",
|
||||||
'Connection',
|
"Connection",
|
||||||
'Cursor',
|
"Cursor",
|
||||||
'InterfaceError',
|
"InterfaceError",
|
||||||
'DatabaseError',
|
"DatabaseError",
|
||||||
'DataError',
|
"DataError",
|
||||||
'OperationalError',
|
"OperationalError",
|
||||||
'IntegrityError',
|
"IntegrityError",
|
||||||
'InternalError',
|
"InternalError",
|
||||||
'ProgrammingError',
|
"ProgrammingError",
|
||||||
'NotSupportedError',
|
"NotSupportedError",
|
||||||
'connect',
|
"connect",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -51,9 +51,7 @@ class Cursor:
|
|||||||
]
|
]
|
||||||
rowcount: int
|
rowcount: int
|
||||||
|
|
||||||
def execute(
|
def execute(self, sql: str, parameters: Optional[Tuple[Any, ...]] = None) -> "Cursor":
|
||||||
self, sql: str, parameters: Optional[Tuple[Any, ...]] = None
|
|
||||||
) -> "Cursor":
|
|
||||||
"""
|
"""
|
||||||
Prepares and executes a SQL statement using the connection.
|
Prepares and executes a SQL statement using the connection.
|
||||||
|
|
||||||
@@ -65,9 +63,7 @@ class Cursor:
|
|||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
def executemany(
|
def executemany(self, sql: str, parameters: Optional[List[Tuple[Any, ...]]] = None) -> None:
|
||||||
self, sql: str, parameters: Optional[List[Tuple[Any, ...]]] = None
|
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
Executes a SQL command against all parameter sequences or mappings found in the sequence `parameters`.
|
Executes a SQL command against all parameter sequences or mappings found in the sequence `parameters`.
|
||||||
|
|
||||||
@@ -136,12 +132,17 @@ class DatabaseError(Error):
|
|||||||
...
|
...
|
||||||
|
|
||||||
class DataError(DatabaseError):
|
class DataError(DatabaseError):
|
||||||
"""Exception raised for errors due to problems with the processed data like division by zero, numeric value out of range, etc."""
|
"""
|
||||||
|
Exception raised for errors due to problems with the processed data like division by zero, numeric value out of
|
||||||
|
range, etc.
|
||||||
|
"""
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
class OperationalError(DatabaseError):
|
class OperationalError(DatabaseError):
|
||||||
"""Exception raised for errors related to the database’s operation, not necessarily under the programmer's control."""
|
"""
|
||||||
|
Exception raised for errors related to the database’s operation, not necessarily under the programmer's control.
|
||||||
|
"""
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -151,12 +152,18 @@ class IntegrityError(DatabaseError):
|
|||||||
...
|
...
|
||||||
|
|
||||||
class InternalError(DatabaseError):
|
class InternalError(DatabaseError):
|
||||||
"""Exception raised when the database encounters an internal error, e.g., cursor is not valid anymore, transaction out of sync."""
|
"""
|
||||||
|
Exception raised when the database encounters an internal error, e.g., cursor is not valid anymore, transaction out
|
||||||
|
of sync.
|
||||||
|
"""
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
class ProgrammingError(DatabaseError):
|
class ProgrammingError(DatabaseError):
|
||||||
"""Exception raised for programming errors, e.g., table not found, syntax error in SQL, wrong number of parameters specified."""
|
"""
|
||||||
|
Exception raised for programming errors, e.g., table not found, syntax error in SQL, wrong number of parameters
|
||||||
|
specified.
|
||||||
|
"""
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|||||||
@@ -52,16 +52,14 @@ features = ["pyo3/extension-module"]
|
|||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
extend-select = ['Q', 'RUF100', 'C90', 'I']
|
extend-select = [
|
||||||
extend-ignore = [
|
"E", # pycodestyle errors
|
||||||
'E721', # using type() instead of isinstance() - we use this in tests
|
"W", # pycodestyle warings
|
||||||
|
"F", # pyflakes
|
||||||
|
'Q', # flake8-quotes
|
||||||
|
'C90', # mccabe
|
||||||
|
'I', # isort
|
||||||
]
|
]
|
||||||
flake8-quotes = { inline-quotes = 'single', multiline-quotes = 'double' }
|
|
||||||
mccabe = { max-complexity = 13 }
|
|
||||||
isort = { known-first-party = ['pydantic_core', 'tests'] }
|
|
||||||
|
|
||||||
[tool.ruff.format]
|
|
||||||
quote-style = 'single'
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
testpaths = 'tests'
|
testpaths = 'tests'
|
||||||
|
|||||||
@@ -5,54 +5,48 @@ import pytest
|
|||||||
import limbo
|
import limbo
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('provider', ['sqlite3', 'limbo'])
|
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
||||||
def test_fetchall_select_all_users(provider):
|
def test_fetchall_select_all_users(provider):
|
||||||
conn = connect(provider, 'tests/database.db')
|
conn = connect(provider, "tests/database.db")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT * FROM users')
|
cursor.execute("SELECT * FROM users")
|
||||||
|
|
||||||
users = cursor.fetchall()
|
users = cursor.fetchall()
|
||||||
assert users
|
assert users
|
||||||
assert users == [(1, 'alice'), (2, 'bob')]
|
assert users == [(1, "alice"), (2, "bob")]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
||||||
'provider',
|
|
||||||
[
|
|
||||||
'sqlite3',
|
|
||||||
'limbo'
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_fetchall_select_user_ids(provider):
|
def test_fetchall_select_user_ids(provider):
|
||||||
conn = connect(provider, 'tests/database.db')
|
conn = connect(provider, "tests/database.db")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT id FROM users')
|
cursor.execute("SELECT id FROM users")
|
||||||
|
|
||||||
user_ids = cursor.fetchall()
|
user_ids = cursor.fetchall()
|
||||||
assert user_ids
|
assert user_ids
|
||||||
assert user_ids == [(1,), (2,)]
|
assert user_ids == [(1,), (2,)]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('provider', ['sqlite3', 'limbo'])
|
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
||||||
def test_fetchone_select_all_users(provider):
|
def test_fetchone_select_all_users(provider):
|
||||||
conn = connect(provider, 'tests/database.db')
|
conn = connect(provider, "tests/database.db")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT * FROM users')
|
cursor.execute("SELECT * FROM users")
|
||||||
|
|
||||||
alice = cursor.fetchone()
|
alice = cursor.fetchone()
|
||||||
assert alice
|
assert alice
|
||||||
assert alice == (1, 'alice')
|
assert alice == (1, "alice")
|
||||||
|
|
||||||
bob = cursor.fetchone()
|
bob = cursor.fetchone()
|
||||||
assert bob
|
assert bob
|
||||||
assert bob == (2, 'bob')
|
assert bob == (2, "bob")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('provider', ['sqlite3', 'limbo'])
|
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
||||||
def test_fetchone_select_max_user_id(provider):
|
def test_fetchone_select_max_user_id(provider):
|
||||||
conn = connect(provider, 'tests/database.db')
|
conn = connect(provider, "tests/database.db")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT MAX(id) FROM users')
|
cursor.execute("SELECT MAX(id) FROM users")
|
||||||
|
|
||||||
max_id = cursor.fetchone()
|
max_id = cursor.fetchone()
|
||||||
assert max_id
|
assert max_id
|
||||||
@@ -60,8 +54,8 @@ def test_fetchone_select_max_user_id(provider):
|
|||||||
|
|
||||||
|
|
||||||
def connect(provider, database):
|
def connect(provider, database):
|
||||||
if provider == 'limbo':
|
if provider == "limbo":
|
||||||
return limbo.connect(database)
|
return limbo.connect(database)
|
||||||
if provider == 'sqlite3':
|
if provider == "sqlite3":
|
||||||
return sqlite3.connect(database)
|
return sqlite3.connect(database)
|
||||||
raise Exception(f'Provider `{provider}` is not supported')
|
raise Exception(f"Provider `{provider}` is not supported")
|
||||||
|
|||||||
Reference in New Issue
Block a user