-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import asyncio | ||
from typing import Coroutine | ||
|
||
import pytest | ||
import weave | ||
from weave.trace.weave_client import Call | ||
|
||
|
||
def test_non_async_non_coro(client): | ||
@weave.op() | ||
def non_async_non_coro(): | ||
return 1 | ||
|
||
res = non_async_non_coro() | ||
assert res == 1 | ||
res, call = non_async_non_coro.call() | ||
assert isinstance(call, Call) | ||
assert call.ended_at is not None | ||
assert res == 1 | ||
assert call.ended_at is not None | ||
|
||
@pytest.mark.asyncio | ||
async def test_non_async_coro(client): | ||
@weave.op() | ||
def non_async_coro(): | ||
return asyncio.to_thread(lambda: 1) | ||
|
||
res = non_async_coro() | ||
assert isinstance(res, Coroutine) | ||
assert await res == 1 | ||
res, call = non_async_coro.call() | ||
assert isinstance(call, Call) | ||
assert call.ended_at is not None | ||
assert isinstance(res, Coroutine) | ||
assert await res == 1 | ||
assert call.ended_at is not None | ||
|
||
@pytest.mark.asyncio | ||
async def test_async_coro(client): | ||
@weave.op() | ||
async def async_coro(): | ||
return asyncio.to_thread(lambda: 1) | ||
|
||
res = async_coro() | ||
assert isinstance(res, Coroutine) | ||
res2 = await res | ||
assert isinstance(res2, Coroutine) | ||
assert await res2 == 1 | ||
res, call = async_coro.call() | ||
assert isinstance(call, Call) | ||
assert call.ended_at is None # BIG DIFFERENCE! We haven't ended the outer op yet! | ||
assert isinstance(res, Coroutine) | ||
res2 = await res | ||
assert isinstance(res2, Coroutine) # Since we did not await the inner coroutine, we still have a coroutine here. | ||
assert await res2 == 1 | ||
assert call.ended_at is not None | ||
|
||
@pytest.mark.asyncio | ||
async def test_async_awaited_coro(client): | ||
@weave.op() | ||
async def async_awaited_coro(): | ||
return await asyncio.to_thread(lambda: 1) | ||
|
||
res = async_awaited_coro() | ||
assert isinstance(res, Coroutine) | ||
assert await res == 1 | ||
res, call = async_awaited_coro.call() | ||
assert isinstance(call, Call) | ||
assert call.ended_at is None # BIG DIFFERENCE! We haven't ended the outer op yet! | ||
assert isinstance(res, Coroutine) | ||
assert await res == 1 | ||
assert call.ended_at is not None | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_non_coro(client): | ||
@weave.op() | ||
async def async_non_coro(): | ||
return 1 | ||
|
||
res = async_non_coro() | ||
assert isinstance(res, Coroutine) | ||
assert await res == 1 | ||
res, call = async_non_coro.call() | ||
assert isinstance(call, Call) | ||
assert call.ended_at is None # BIG DIFFERENCE! We haven't ended the outer op yet! | ||
assert isinstance(res, Coroutine) | ||
assert await res == 1 | ||
assert call.ended_at is not None |
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