-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to use Engine subclass in tests
- Loading branch information
1 parent
936d8c6
commit 87167db
Showing
10 changed files
with
112 additions
and
79 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
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
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
Empty file.
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,20 @@ | ||
import typing as t | ||
|
||
import pytest | ||
|
||
from asyncpg_engine import Engine | ||
|
||
pytestmark = [pytest.mark.asyncio] | ||
|
||
|
||
class MyPrettyEngine(Engine): | ||
pass | ||
|
||
|
||
@pytest.fixture() | ||
def asyncpg_engine_cls() -> t.Type[MyPrettyEngine]: | ||
return MyPrettyEngine | ||
|
||
|
||
async def test_returns_my_pretty_engine(db: MyPrettyEngine) -> None: | ||
assert isinstance(db, MyPrettyEngine) |
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,27 @@ | ||
import pytest | ||
from asyncpg import Connection | ||
|
||
from asyncpg_engine import Engine | ||
|
||
pytestmark = [pytest.mark.asyncio, pytest.mark.asyncpg_engine(transactional=False)] | ||
|
||
|
||
async def test_acquire_returns_new_connection(db: Engine) -> None: | ||
async with db.acquire() as con_0: | ||
async with db.acquire() as con_1: | ||
|
||
assert con_0 != con_1 | ||
|
||
|
||
async def test_con_is_not_the_same_as_acquire_result(db: Engine, con: Connection) -> None: | ||
async with db.acquire() as con_0: | ||
async with db.acquire() as con_1: | ||
|
||
assert con_0 != con_1 | ||
|
||
|
||
@pytest.mark.asyncpg_engine(transactional=False) | ||
async def test_not_transactional(con: Connection) -> None: | ||
sql = "SELECT txid_current()" | ||
|
||
assert await con.fetchval(sql) != await con.fetchval(sql) |
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,32 @@ | ||
import pytest | ||
from asyncpg import Connection | ||
|
||
from asyncpg_engine import Engine | ||
|
||
pytestmark = [pytest.mark.asyncio] | ||
|
||
|
||
async def test_acquire_returns_the_same_connection(db: Engine) -> None: | ||
async with db.acquire() as con_0: | ||
async with db.acquire() as con_1: | ||
|
||
assert con_0 == con_1 | ||
|
||
|
||
async def test_con_is_the_same_as_acquire_result(db: Engine, con: Connection) -> None: | ||
async with db.acquire() as con_0: | ||
|
||
assert con_0 == con | ||
|
||
|
||
async def test_transactional(con: Connection) -> None: | ||
sql = "SELECT txid_current()" | ||
|
||
assert await con.fetchval(sql) == await con.fetchval(sql) | ||
|
||
|
||
@pytest.mark.asyncpg_engine(transactional=True) | ||
async def test_transactional_if_specified(con: Connection) -> None: | ||
sql = "SELECT txid_current()" | ||
|
||
assert await con.fetchval(sql) == await con.fetchval(sql) |
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 was deleted.
Oops, something went wrong.