Skip to content

Commit

Permalink
test(sqlite): ensure remaining sqlite tests close their connections
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 20, 2024
1 parent b5cd69f commit d22dd77
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
5 changes: 3 additions & 2 deletions ibis/backends/sqlite/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def total(x) -> float:
)
def test_connect(url, ext, tmp_path):
path = os.path.abspath(tmp_path / f"test.{ext}")
with sqlite3.connect(path):
pass

sqlite3.connect(path).close()

con = ibis.connect(url(path))
one = ibis.literal(1)
assert con.execute(one) == 1
Expand Down
42 changes: 24 additions & 18 deletions ibis/backends/sqlite/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,30 @@
@pytest.fixture(scope="session")
def db(tmp_path_factory):
path = str(tmp_path_factory.mktemp("databases") / "formats.db")
with sqlite3.connect(path) as con:
con.execute("CREATE TABLE timestamps (ts TIMESTAMP)")
con.execute("CREATE TABLE timestamps_tz (ts TIMESTAMPTZ)")
con.execute("CREATE TABLE weird (str_col STRING, date_col ITSADATE)")
con.execute("CREATE TABLE basic (a INTEGER, b REAL, c BOOLEAN, d BLOB)")
con.executemany("INSERT INTO timestamps VALUES (?)", [(t,) for t in TIMESTAMPS])
con.executemany(
"INSERT INTO timestamps_tz VALUES (?)", [(t,) for t in TIMESTAMPS_TZ]
)
con.executemany(
"INSERT INTO weird VALUES (?, ?)",
[
("a", "2022-01-01"),
("b", "2022-01-02"),
("c", "2022-01-03"),
("d", "2022-01-04"),
],
)
con = sqlite3.connect(path)
try:
with con:
con.execute("CREATE TABLE timestamps (ts TIMESTAMP)")
con.execute("CREATE TABLE timestamps_tz (ts TIMESTAMPTZ)")
con.execute("CREATE TABLE weird (str_col STRING, date_col ITSADATE)")
con.execute("CREATE TABLE basic (a INTEGER, b REAL, c BOOLEAN, d BLOB)")
con.executemany(
"INSERT INTO timestamps VALUES (?)", [(t,) for t in TIMESTAMPS]
)
con.executemany(
"INSERT INTO timestamps_tz VALUES (?)", [(t,) for t in TIMESTAMPS_TZ]
)
con.executemany(
"INSERT INTO weird VALUES (?, ?)",
[
("a", "2022-01-01"),
("b", "2022-01-02"),
("c", "2022-01-03"),
("d", "2022-01-04"),
],
)
finally:
con.close()
return path


Expand Down

0 comments on commit d22dd77

Please sign in to comment.