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:
Lauri Virtanen
2024-08-31 13:43:49 +03:00
parent 4738d16c6f
commit 6bd1d28e26
4 changed files with 54 additions and 55 deletions

View File

@@ -14,16 +14,16 @@ from ._limbo import (
)
__all__ = [
'__version__',
'Connection',
'Cursor',
'InterfaceError',
'DatabaseError',
'DataError',
'OperationalError',
'IntegrityError',
'InternalError',
'ProgrammingError',
'NotSupportedError',
'connect',
"__version__",
"Connection",
"Cursor",
"InterfaceError",
"DatabaseError",
"DataError",
"OperationalError",
"IntegrityError",
"InternalError",
"ProgrammingError",
"NotSupportedError",
"connect",
]

View File

@@ -51,9 +51,7 @@ class Cursor:
]
rowcount: int
def execute(
self, sql: str, parameters: Optional[Tuple[Any, ...]] = None
) -> "Cursor":
def execute(self, sql: str, parameters: Optional[Tuple[Any, ...]] = None) -> "Cursor":
"""
Prepares and executes a SQL statement using the connection.
@@ -65,9 +63,7 @@ class Cursor:
"""
...
def executemany(
self, sql: str, parameters: Optional[List[Tuple[Any, ...]]] = None
) -> None:
def executemany(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`.
@@ -136,12 +132,17 @@ class DatabaseError(Error):
...
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):
"""Exception raised for errors related to the databases operation, not necessarily under the programmer's control."""
"""
Exception raised for errors related to the databases operation, not necessarily under the programmer's control.
"""
...
@@ -151,12 +152,18 @@ class IntegrityError(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):
"""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.
"""
...

View File

@@ -52,16 +52,14 @@ features = ["pyo3/extension-module"]
line-length = 120
[tool.ruff.lint]
extend-select = ['Q', 'RUF100', 'C90', 'I']
extend-ignore = [
'E721', # using type() instead of isinstance() - we use this in tests
extend-select = [
"E", # pycodestyle errors
"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]
testpaths = 'tests'

View File

@@ -5,54 +5,48 @@ import pytest
import limbo
@pytest.mark.parametrize('provider', ['sqlite3', 'limbo'])
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
def test_fetchall_select_all_users(provider):
conn = connect(provider, 'tests/database.db')
conn = connect(provider, "tests/database.db")
cursor = conn.cursor()
cursor.execute('SELECT * FROM users')
cursor.execute("SELECT * FROM users")
users = cursor.fetchall()
assert users
assert users == [(1, 'alice'), (2, 'bob')]
assert users == [(1, "alice"), (2, "bob")]
@pytest.mark.parametrize(
'provider',
[
'sqlite3',
'limbo'
],
)
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
def test_fetchall_select_user_ids(provider):
conn = connect(provider, 'tests/database.db')
conn = connect(provider, "tests/database.db")
cursor = conn.cursor()
cursor.execute('SELECT id FROM users')
cursor.execute("SELECT id FROM users")
user_ids = cursor.fetchall()
assert user_ids
assert user_ids == [(1,), (2,)]
@pytest.mark.parametrize('provider', ['sqlite3', 'limbo'])
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
def test_fetchone_select_all_users(provider):
conn = connect(provider, 'tests/database.db')
conn = connect(provider, "tests/database.db")
cursor = conn.cursor()
cursor.execute('SELECT * FROM users')
cursor.execute("SELECT * FROM users")
alice = cursor.fetchone()
assert alice
assert alice == (1, 'alice')
assert alice == (1, "alice")
bob = cursor.fetchone()
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):
conn = connect(provider, 'tests/database.db')
conn = connect(provider, "tests/database.db")
cursor = conn.cursor()
cursor.execute('SELECT MAX(id) FROM users')
cursor.execute("SELECT MAX(id) FROM users")
max_id = cursor.fetchone()
assert max_id
@@ -60,8 +54,8 @@ def test_fetchone_select_max_user_id(provider):
def connect(provider, database):
if provider == 'limbo':
if provider == "limbo":
return limbo.connect(database)
if provider == 'sqlite3':
if provider == "sqlite3":
return sqlite3.connect(database)
raise Exception(f'Provider `{provider}` is not supported')
raise Exception(f"Provider `{provider}` is not supported")