Skip to content

Commit c6e7946

Browse files
committed
update
1 parent 2e4d05f commit c6e7946

2 files changed

Lines changed: 56 additions & 55 deletions

File tree

src/sapling/database.py

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING
66

77
from pydantic import BaseModel
8-
from tryke import expect, test
8+
from tryke import describe, expect, test
99

1010
from sapling import MemoryBackend, SQLiteBackend
1111
from sapling.errors import NotFoundError
@@ -290,34 +290,6 @@ def test_all_empty() -> None:
290290
expect(all_hellos).to_equal([])
291291

292292

293-
@test
294-
def test_sqlite_backend_memory() -> None:
295-
backend = SQLiteBackend()
296-
db = Database(backend=backend)
297-
with db.transaction() as txn:
298-
txn.put(_TestModel, "test", _TestModel(hello="world"))
299-
doc = txn.fetch(_TestModel, "test")
300-
expect(doc.model.hello).to_equal("world")
301-
302-
303-
@test
304-
def test_sqlite_backend_file() -> None:
305-
with tempfile.TemporaryDirectory() as tmp_dir:
306-
db_path = Path(tmp_dir) / "test.db"
307-
settings = SaplingSettings(sqlite_path=str(db_path))
308-
backend = SQLiteBackend(settings=settings)
309-
db = Database(backend=backend)
310-
311-
with db.transaction() as txn:
312-
txn.put(_TestModel, "persistent", _TestModel(hello="saved"))
313-
314-
settings2 = SaplingSettings(sqlite_path=str(db_path))
315-
db2 = Database(backend=SQLiteBackend(settings=settings2))
316-
with db2.transaction() as txn:
317-
doc = txn.fetch(_TestModel, "persistent")
318-
expect(doc.model.hello).to_equal("saved")
319-
320-
321293
@test
322294
def test_backend_all_method() -> None:
323295
backend = SQLiteBackend()
@@ -355,39 +327,68 @@ def test_memory_backend() -> None:
355327
expect(lambda: txn.fetch(_TestModel, "test")).to_raise(NotFoundError)
356328

357329

358-
@test
359-
def test_deferred_initialization() -> None:
360-
backend = SQLiteBackend()
361-
db = Database(backend=backend, initialize=False)
330+
with describe("sqlite"):
331+
332+
@test
333+
def test_sqlite_backend_memory() -> None:
334+
backend = SQLiteBackend()
335+
db = Database(backend=backend)
336+
with db.transaction() as txn:
337+
txn.put(_TestModel, "test", _TestModel(hello="world"))
338+
doc = txn.fetch(_TestModel, "test")
339+
expect(doc.model.hello).to_equal("world")
362340

363-
db.initialize()
341+
@test
342+
def test_sqlite_backend_file() -> None:
343+
with tempfile.TemporaryDirectory() as tmp_dir:
344+
db_path = Path(tmp_dir) / "test.db"
345+
settings = SaplingSettings(sqlite_path=str(db_path))
346+
backend = SQLiteBackend(settings=settings)
347+
db = Database(backend=backend)
364348

365-
with db.transaction() as txn:
366-
txn.put(_TestModel, "test", _TestModel(hello="world"))
367-
doc = txn.fetch(_TestModel, "test")
368-
expect(doc.model.hello).to_equal("world")
349+
with db.transaction() as txn:
350+
txn.put(_TestModel, "persistent", _TestModel(hello="saved"))
369351

352+
settings2 = SaplingSettings(sqlite_path=str(db_path))
353+
db2 = Database(backend=SQLiteBackend(settings=settings2))
354+
with db2.transaction() as txn:
355+
doc = txn.fetch(_TestModel, "persistent")
356+
expect(doc.model.hello).to_equal("saved")
370357

371-
@test
372-
def test_idempotent_initialization() -> None:
373-
backend = SQLiteBackend()
374-
db = Database(backend=backend, initialize=False)
375358

376-
db.initialize()
377-
db.initialize()
378-
db.initialize()
359+
with describe("initialization"):
379360

380-
with db.transaction() as txn:
381-
txn.put(_TestModel, "test", _TestModel(hello="world"))
361+
@test
362+
def test_deferred_initialization() -> None:
363+
backend = SQLiteBackend()
364+
db = Database(backend=backend, initialize=False)
382365

366+
db.initialize()
383367

384-
@test
385-
def test_uninitialized_error() -> None:
386-
backend = SQLiteBackend()
387-
db = Database(backend=backend, initialize=False)
368+
with db.transaction() as txn:
369+
txn.put(_TestModel, "test", _TestModel(hello="world"))
370+
doc = txn.fetch(_TestModel, "test")
371+
expect(doc.model.hello).to_equal("world")
372+
373+
@test
374+
def test_idempotent_initialization() -> None:
375+
backend = SQLiteBackend()
376+
db = Database(backend=backend, initialize=False)
377+
378+
db.initialize()
379+
db.initialize()
380+
db.initialize()
388381

389-
def try_uninitialized() -> None:
390382
with db.transaction() as txn:
391383
txn.put(_TestModel, "test", _TestModel(hello="world"))
392384

393-
expect(try_uninitialized).to_raise(ValueError, match="not initialized")
385+
@test
386+
def test_uninitialized_error() -> None:
387+
backend = SQLiteBackend()
388+
db = Database(backend=backend, initialize=False)
389+
390+
def try_uninitialized() -> None:
391+
with db.transaction() as txn:
392+
txn.put(_TestModel, "test", _TestModel(hello="world"))
393+
394+
expect(try_uninitialized).to_raise(ValueError, match="not initialized")

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)