This repository has been archived by the owner on May 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Laura <[email protected]>
- Loading branch information
Showing
5 changed files
with
140 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# .coveragerc to control coverage.py | ||
[run] | ||
branch = True | ||
|
||
[report] | ||
# Regexes for lines to exclude from consideration | ||
exclude_lines = | ||
# Have to re-enable the standard pragma | ||
pragma: no cover | ||
|
||
# Don't complain about missing debug-only code: | ||
def __repr__ | ||
if self\.debug | ||
|
||
# Don't complain if tests don't hit defensive assertion code: | ||
raise AssertionError | ||
raise NotImplementedError | ||
|
||
# Don't complain if non-runnable code isn't run: | ||
if 0: | ||
if __name__ == .__main__.: | ||
|
||
ignore_errors = True | ||
omit = | ||
# migration tool is uncovered | ||
asyncqlio/orm/ddl/migration_tool.py | ||
|
||
[html] | ||
directory = coverage_html_report |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[aliases] | ||
test=pytest | ||
|
||
[tool:pytest] | ||
addopts = --verbose --cov=asyncqlio | ||
python_files = tests/*.py |
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
py.test configuration | ||
""" | ||
import asyncio | ||
import os | ||
|
||
import pytest | ||
|
||
from asyncqlio import DatabaseInterface | ||
|
||
# set the iface as a global so it can be closed later | ||
iface = DatabaseInterface() | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
async def db() -> DatabaseInterface: | ||
await iface.connect(dsn=os.environ["ASQL_DSN"]) | ||
return iface | ||
|
||
|
||
# override for a module scope | ||
@pytest.fixture(scope="module") | ||
def event_loop(): | ||
return asyncio.get_event_loop() | ||
|
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Tests the low-level API. | ||
""" | ||
|
||
import pytest | ||
|
||
from asyncqlio import BaseTransaction, DatabaseInterface | ||
|
||
# mark all test_ functions as coroutines | ||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_db_connected(db: DatabaseInterface): | ||
assert db.connected | ||
assert db.connector is not None | ||
|
||
|
||
async def test_acquire_transaction(db: DatabaseInterface): | ||
tr = db.get_transaction() | ||
|
||
assert isinstance(tr, BaseTransaction) | ||
|
||
|
||
async def test_transaction_use(db: DatabaseInterface): | ||
tr = db.get_transaction() | ||
await tr.begin() | ||
|
||
# this just ensures the connection doesn't error | ||
await tr.execute("SELECT 1 + 1;") | ||
await tr.rollback() | ||
await tr.close() | ||
|
||
async def test_transaction_fetch_one(db: DatabaseInterface): | ||
tr = db.get_transaction() | ||
await tr.begin() | ||
|
||
cursor = await tr.cursor("SELECT 1 + 1;") | ||
async with cursor: | ||
row = await cursor.fetch_row() | ||
# rowdict | ||
assert row[0] == 2 | ||
await tr.rollback() | ||
await tr.close() | ||
|
||
|
||
async def test_transaction_fetch_multiple(db: DatabaseInterface): | ||
tr = db.get_transaction() | ||
await tr.begin() | ||
|
||
cursor = await tr.cursor('SELECT 1 AS result UNION ALL SELECT 2;') | ||
previous = 0 | ||
async with cursor: | ||
async for row in cursor: | ||
assert row["result"] > previous | ||
previous = row["result"] | ||
|
||
await tr.rollback() | ||
await tr.close() | ||
|
||
|
||
async def test_transaction_fetch_many(db: DatabaseInterface): | ||
tr = db.get_transaction() | ||
await tr.begin() | ||
|
||
cursor = await tr.cursor('SELECT 1 AS result UNION ALL SELECT 2;') | ||
async with cursor: | ||
rows = await cursor.fetch_many(n=2) | ||
|
||
assert rows[0]["result"] == 1 | ||
assert rows[1]["result"] == 2 | ||
|
||
await tr.rollback() | ||
await tr.close() |