@@ -23,25 +23,29 @@ def target(tmp_path) -> SqlAlchemyPersistence:
2323
2424
2525def test_ctor_creates_schema (target ):
26- cursor = target .engine .execute ("SELECT sql FROM sqlite_master WHERE type = 'table'" )
27- assert len (cursor .fetchall ()) == 3
26+ with target .engine .connect () as connection :
27+ cursor = connection .execute (
28+ text ("SELECT sql FROM sqlite_master WHERE type = 'table'" )
29+ )
30+ assert len (cursor .fetchall ()) == 3
2831
2932
3033def test_ctor_stamps_head (target ):
31- cursor = target .engine .execute ("SELECT version_num FROM alembic_version" )
32- assert cursor .first () == ("000c6a88457f" ,)
34+ with target .engine .connect () as connection :
35+ cursor = connection .execute (text ("SELECT version_num FROM alembic_version" ))
36+ assert cursor .first () == ("000c6a88457f" ,)
3337
3438
3539""" get_commit """
3640
3741
3842def test_get_commit_when_commit_id_exists_then_commit_is_returned (target ):
3943 commit_id = "f74c808e-2388-4b0a-a051-17eb9eb14339"
40- with target .engine .connect () as connection :
44+ with target .engine .begin () as connection :
4145 connection .execute (
4246 text (
4347 "INSERT INTO 'commit' VALUES "
44- f"('{ commit_id } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0');"
48+ f"('{ UUID ( commit_id ). hex } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0');"
4549 )
4650 )
4751 actual = target .get_commit (commit_id )
@@ -50,20 +54,20 @@ def test_get_commit_when_commit_id_exists_then_commit_is_returned(target):
5054
5155def test_get_commit_when_commit_id_does_not_exist_then_error_is_raised (target ):
5256 with pytest .raises (EntropyError ):
53- target .get_commit ("foo " )
57+ target .get_commit ("f74c808e-2388-4b0a-a051-17eb9eb14339 " )
5458
5559
5660def test_get_commit_when_commit_num_exists_then_commit_is_returned (target ):
5761 commit_id1 = "f74c808e-2388-4b0a-a051-17eb9eb11111"
5862 commit_id2 = "f74c808e-2388-4b0a-a051-17eb9eb22222"
5963 commit_id3 = "f74c808e-2388-4b0a-a051-17eb9eb33333"
60- with target .engine .connect () as connection :
64+ with target .engine .begin () as connection :
6165 connection .execute (
6266 text (
6367 "INSERT INTO 'commit' VALUES "
64- f"('{ commit_id1 } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0'),"
65- f"('{ commit_id2 } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0'),"
66- f"('{ commit_id3 } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0');"
68+ f"('{ UUID ( commit_id1 ). hex } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0'),"
69+ f"('{ UUID ( commit_id2 ). hex } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0'),"
70+ f"('{ UUID ( commit_id3 ). hex } ', '{ pd .Timestamp .now ()} ', 'bar', '0', '0');"
6771 )
6872 )
6973 actual = target .get_commit (commit_num = 2 )
0 commit comments