Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract tests to package with conditional extra tests import for Pyth…
…on 3.5+
- Loading branch information
Showing
7 changed files
with
89 additions
and
201 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ sdist/ | |
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.egg* | ||
*.ini | ||
|
||
# PyInstaller | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,5 @@ | |
'Programming Language :: Python :: 3', | ||
], | ||
test_suite='tests', | ||
test_loader='unittest:TestLoader', | ||
) |
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,70 @@ | ||
""" | ||
peewee-async tests for Python 3.5+ | ||
================================== | ||
These tests should be run only for Python 3.5+, older versions | ||
will just fail with `SyntaxError` while importing this module. | ||
""" | ||
import peewee_async | ||
from . import database,\ | ||
BaseAsyncPostgresTestCase,\ | ||
TestModel,\ | ||
UUIDTestModel | ||
|
||
# Shortcuts | ||
execute = peewee_async.execute | ||
count = peewee_async.count | ||
scalar = peewee_async.scalar | ||
get_object = peewee_async.get_object | ||
create_object = peewee_async.create_object | ||
delete_object = peewee_async.delete_object | ||
update_object = peewee_async.update_object | ||
sync_unwanted = peewee_async.sync_unwanted | ||
|
||
|
||
class FakeUpdateError(Exception): | ||
"""Fake error while updating database. | ||
""" | ||
pass | ||
|
||
|
||
class AsyncPostgresTransactionsTestCase(BaseAsyncPostgresTestCase): | ||
def test_atomic_success(self): | ||
"""Successful update in transaction. | ||
""" | ||
async def test(): | ||
with sync_unwanted(database): | ||
obj = await create_object(TestModel, text='FOO') | ||
obj_id = obj.id | ||
|
||
async with database.async_atomic(): | ||
obj.text = 'BAR' | ||
await update_object(obj) | ||
|
||
res = await get_object(TestModel, TestModel.id == obj_id) | ||
self.assertEqual(res.text, 'BAR') | ||
|
||
self.run_until_complete(test()) | ||
|
||
def test_atomic_failed(self): | ||
"""Failed update in transaction. | ||
""" | ||
async def test(): | ||
with sync_unwanted(database): | ||
obj = await create_object(TestModel, text='FOO') | ||
obj_id = obj.id | ||
|
||
try: | ||
async with database.async_atomic(): | ||
obj.text = 'BAR' | ||
await update_object(obj) | ||
raise FakeUpdateError() | ||
except FakeUpdateError as e: | ||
update_error = True | ||
res = await get_object(TestModel, TestModel.id == obj_id) | ||
|
||
self.assertTrue(update_error) | ||
self.assertEqual(res.text, 'FOO') | ||
|
||
self.run_until_complete(test()) |
This file was deleted.
Oops, something went wrong.