-
Notifications
You must be signed in to change notification settings - Fork 12
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
99 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from collections.abc import AsyncIterator | ||
|
||
import pytest | ||
|
||
from htpy import Element, li, ul | ||
|
||
|
||
async def async_lis() -> AsyncIterator[Element]: | ||
yield li["a"] | ||
yield li["b"] | ||
|
||
|
||
async def hi() -> Element: | ||
return li["hi"] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_iterator() -> None: | ||
result = [chunk async for chunk in ul[async_lis()]] | ||
assert result == ["<ul>", "<li>", "a", "</li>", "<li>", "b", "</li>", "</ul>"] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_cororoutinefunction_children() -> None: | ||
result = [chunk async for chunk in ul[hi]] | ||
assert result == ["<ul>", "<li>", "hi", "</li>", "</ul>"] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_cororoutine_children() -> None: | ||
result = [chunk async for chunk in ul[hi()]] | ||
assert result == ["<ul>", "<li>", "hi", "</li>", "</ul>"] | ||
|
||
|
||
def test_sync_iteration_with_async_children() -> None: | ||
with pytest.raises( | ||
ValueError, | ||
match=( | ||
r"<async_generator object async_lis at .+> is not a valid child element\. " | ||
r"Use async iteration to retrieve element content: https://htpy.dev/async/" | ||
), | ||
): | ||
str(ul[async_lis()]) |