Skip to content

Commit 83ff2de

Browse files
committed
ruff format
1 parent b164519 commit 83ff2de

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

examples/conftest.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@
3939
@pytest.fixture(scope="module")
4040
def pglite_manager() -> Generator[PGliteManager, None, None]:
4141
"""Isolated PGlite manager for examples - one per test module.
42-
42+
4343
This overrides the session-scoped fixture from the main package
4444
to provide better isolation when running all tests together.
4545
"""
4646
# Create unique configuration to prevent socket conflicts
4747
config = PGliteConfig()
48-
48+
4949
# Create a unique socket directory for this example module
5050
# PGlite expects socket_path to be the full path including .s.PGSQL.5432
51-
socket_dir = Path(tempfile.gettempdir()) / f"py-pglite-example-{uuid.uuid4().hex[:8]}"
51+
socket_dir = (
52+
Path(tempfile.gettempdir()) / f"py-pglite-example-{uuid.uuid4().hex[:8]}"
53+
)
5254
socket_dir.mkdir(mode=0o700, exist_ok=True) # Restrict to user only
5355
config.socket_path = str(socket_dir / ".s.PGSQL.5432")
54-
56+
5557
manager = PGliteManager(config)
5658
manager.start()
5759
manager.wait_for_ready()
@@ -94,28 +96,32 @@ def pglite_session(pglite_engine: Engine) -> Generator[Any, None, None]:
9496
if table_names:
9597
# Disable foreign key checks for faster cleanup
9698
conn.execute(text("SET session_replication_role = replica;"))
97-
99+
98100
# Truncate all tables
99101
for table_name in table_names:
100102
logger.info(f"Truncating table: {table_name}")
101103
conn.execute(
102-
text(f'TRUNCATE TABLE "{table_name}" RESTART IDENTITY CASCADE;')
104+
text(
105+
f'TRUNCATE TABLE "{table_name}" RESTART IDENTITY CASCADE;'
106+
)
103107
)
104108

105109
# Re-enable foreign key checks
106110
conn.execute(text("SET session_replication_role = DEFAULT;"))
107-
111+
108112
# Commit the cleanup
109113
conn.commit()
110114
logger.info("Database cleanup completed successfully")
111115
else:
112116
logger.info("No tables found to clean")
113117
break # Success, exit retry loop
114-
118+
115119
except Exception as e:
116120
logger.info(f"Database cleanup attempt {attempt + 1} failed: {e}")
117121
if attempt == retry_count - 1:
118-
logger.warning("Database cleanup failed after all retries, continuing anyway")
122+
logger.warning(
123+
"Database cleanup failed after all retries, continuing anyway"
124+
)
119125
else:
120126
time.sleep(0.5) # Brief pause before retry
121127

@@ -144,4 +150,4 @@ def pglite_session(pglite_engine: Engine) -> Generator[Any, None, None]:
144150
try:
145151
session.close()
146152
except Exception as e:
147-
logger.warning(f"Error closing session: {e}")
153+
logger.warning(f"Error closing session: {e}")

examples/quickstart/simple_performance.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ def measure_feature_power():
191191
f" → {result[1]} events/minute, avg score: {result[2]:.1f}",
192192
)
193193

194-
total_feature_time = (
195-
json_time + array_time + window_time + time_series_time
196-
)
194+
total_feature_time = json_time + array_time + window_time + time_series_time
197195

198196
print(f"\n 🚀 Total advanced features: {total_feature_time:.4f}s")
199197
print(" 💥 SQLite equivalent: IMPOSSIBLE ❌")
@@ -263,12 +261,10 @@ def measure_raw_performance():
263261
sqlite_insert = time.time() - start
264262

265263
print(
266-
f" py-pglite: {pglite_insert:.3f}s "
267-
f"({1000 / pglite_insert:,.0f} rec/sec)"
264+
f" py-pglite: {pglite_insert:.3f}s ({1000 / pglite_insert:,.0f} rec/sec)"
268265
)
269266
print(
270-
f" SQLite: {sqlite_insert:.3f}s "
271-
f"({1000 / sqlite_insert:,.0f} rec/sec)"
267+
f" SQLite: {sqlite_insert:.3f}s ({1000 / sqlite_insert:,.0f} rec/sec)"
272268
)
273269

274270
if sqlite_insert < pglite_insert:
@@ -322,8 +318,7 @@ def generate_final_report(boot_times, feature_time, perf_times):
322318
print("\n" + "🎯 THE HONEST TRUTH" + "\n" + "=" * 60)
323319

324320
print("📊 PERFORMANCE COMPARISON:")
325-
print(f" Boot Time: SQLite {sqlite_boot:.3f}s vs "
326-
f"py-pglite {pglite_boot:.2f}s")
321+
print(f" Boot Time: SQLite {sqlite_boot:.3f}s vs py-pglite {pglite_boot:.2f}s")
327322
print(
328323
f" Insert Speed: SQLite {1000 / sqlite_insert:,.0f}/s vs "
329324
f"py-pglite {1000 / pglite_insert:,.0f}/s"

examples/test_basic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Example model
77
class BasicUser(SQLModel, table=True):
8-
__table_args__ = {'extend_existing': True}
8+
__table_args__ = {"extend_existing": True}
99
id: int | None = Field(default=None, primary_key=True)
1010
name: str
1111
email: str
@@ -60,7 +60,9 @@ def test_user_update(pglite_session: Session):
6060
pglite_session.commit()
6161

6262
# Verify the update
63-
updated_user = pglite_session.exec(select(BasicUser).where(BasicUser.name == "David")).first()
63+
updated_user = pglite_session.exec(
64+
select(BasicUser).where(BasicUser.name == "David")
65+
).first()
6466
assert updated_user is not None
6567
assert updated_user.email == "david@new.com"
6668

examples/test_utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_database_cleanup_utils(pglite_engine):
4242
title="Python Testing Guide",
4343
author_id=author.id,
4444
isbn="978-0123456789",
45-
published_year=2024
45+
published_year=2024,
4646
)
4747
session.add(book)
4848
session.commit()
@@ -138,7 +138,7 @@ def test_partial_cleanup(pglite_engine):
138138
title="Temporary Book",
139139
author_id=author.id,
140140
isbn="978-0987654321",
141-
published_year=2024
141+
published_year=2024,
142142
)
143143
session.add(book)
144144
session.commit()
@@ -153,7 +153,9 @@ def test_partial_cleanup(pglite_engine):
153153

154154
# Verify with exclude list in verification
155155
assert utils.verify_database_empty(pglite_engine, exclude_tables=["author"])
156-
assert not utils.verify_database_empty(pglite_engine) # Should be False due to author
156+
assert not utils.verify_database_empty(
157+
pglite_engine
158+
) # Should be False due to author
157159

158160

159161
def test_schema_operations(pglite_engine):
@@ -167,8 +169,10 @@ def test_schema_operations(pglite_engine):
167169
with Session(pglite_engine) as session:
168170
with session.connection() as conn:
169171
result = conn.execute(
170-
text("SELECT schema_name FROM information_schema.schemata WHERE schema_name = :name"),
171-
{"name": test_schema}
172+
text(
173+
"SELECT schema_name FROM information_schema.schemata WHERE schema_name = :name"
174+
),
175+
{"name": test_schema},
172176
)
173177
schemas = result.fetchall()
174178
assert len(schemas) == 1
@@ -180,8 +184,10 @@ def test_schema_operations(pglite_engine):
180184
with Session(pglite_engine) as session:
181185
with session.connection() as conn:
182186
result = conn.execute(
183-
text("SELECT schema_name FROM information_schema.schemata WHERE schema_name = :name"),
184-
{"name": test_schema}
187+
text(
188+
"SELECT schema_name FROM information_schema.schemata WHERE schema_name = :name"
189+
),
190+
{"name": test_schema},
185191
)
186192
schemas = result.fetchall()
187193
assert len(schemas) == 0
@@ -198,8 +204,8 @@ def test_combined_cleanup_fixture(pglite_session: Session):
198204
# Clean all tables manually to ensure fresh state
199205
conn.execute(text('DELETE FROM "book"'))
200206
conn.execute(text('DELETE FROM "author"'))
201-
conn.execute(text('ALTER SEQUENCE author_id_seq RESTART WITH 1'))
202-
conn.execute(text('ALTER SEQUENCE book_id_seq RESTART WITH 1'))
207+
conn.execute(text("ALTER SEQUENCE author_id_seq RESTART WITH 1"))
208+
conn.execute(text("ALTER SEQUENCE book_id_seq RESTART WITH 1"))
203209
pglite_session.commit()
204210

205211
# Add test data directly using the existing session
@@ -213,7 +219,7 @@ def test_combined_cleanup_fixture(pglite_session: Session):
213219
title="Test Book",
214220
author_id=author.id,
215221
isbn="978-0111111111",
216-
published_year=2024
222+
published_year=2024,
217223
)
218224
pglite_session.add(book)
219225
pglite_session.commit()

0 commit comments

Comments
 (0)