-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configure setup and teardown process for tests
- Loading branch information
Showing
2 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
import os | ||
import pytest | ||
import aiosqlite | ||
import litequery | ||
import pytest_asyncio | ||
|
||
DATABASE_PATH = "test.db" | ||
QUERIES_PATH = "queries.sql" | ||
|
||
@pytest.mark.asyncio | ||
async def test_queries(): | ||
lq = litequery.create("users.db", "queries.sql") | ||
|
||
@pytest_asyncio.fixture | ||
async def setup_database(): | ||
async with aiosqlite.connect(DATABASE_PATH) as conn: | ||
await conn.execute( | ||
"create table users (id integer primary key autoincrement, name text)" | ||
) | ||
await conn.commit() | ||
yield | ||
os.remove(DATABASE_PATH) | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def lq(setup_database): | ||
lq = litequery.create(DATABASE_PATH, QUERIES_PATH) | ||
await lq.connect() | ||
yield lq | ||
await lq.disconnect() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_queries(lq): | ||
print(await lq.users_delete_all()) | ||
print(await lq.users_insert(name="kocia")) | ||
print(await lq.users_insert(name="kot")) | ||
print(await lq.users_insert(name="simba")) | ||
print(await lq.users_insert(name="bunchik")) | ||
print(await lq.users_all()) | ||
print(await lq.users_first()) | ||
await lq.disconnect() |