-
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.
* fix: apply_semaphore breaks with our cython semaphore * feat(test): test_apply_semaphore * feat(test): test for failure cases too * chore: `black .` --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
792fd99
commit 1db391b
Showing
2 changed files
with
44 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
import pytest | ||
|
||
from a_sync import Semaphore, apply_semaphore | ||
from a_sync.exceptions import FunctionNotAsync | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
async def test_apply_semaphore_int(): | ||
apply_semaphore(asyncio.sleep, 1) | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
async def test_apply_semaphore_asyncio_semaphore(): | ||
apply_semaphore(asyncio.sleep, asyncio.Semaphore(1)) | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
async def test_apply_semaphore_a_sync_semaphore(): | ||
apply_semaphore(asyncio.sleep, Semaphore(1)) | ||
|
||
|
||
def fail(): | ||
pass | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
async def test_apply_semaphore_failure_int(): | ||
with pytest.raises(FunctionNotAsync): | ||
apply_semaphore(fail, 1) | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
async def test_apply_semaphore_failure_asyncio_semaphore(): | ||
with pytest.raises(FunctionNotAsync): | ||
apply_semaphore(fail, asyncio.Semaphore(1)) | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
async def test_apply_semaphore_failure_a_sync_semaphore(): | ||
with pytest.raises(FunctionNotAsync): | ||
apply_semaphore(fail, Semaphore(1)) |