From f4b80a2c367096ac778216a869f041cc6d7b5f1f Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Sun, 15 Sep 2024 16:25:31 +0200 Subject: [PATCH] Add test for context provider API. --- tests/test_context.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_context.py b/tests/test_context.py index 2144fc4..56c210b 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -2,6 +2,7 @@ import typing as t +import markupsafe import pytest from htpy import Context, Node, div @@ -33,6 +34,19 @@ def test_context_provider(render: RenderFixture) -> None: assert render(result) == ["
", "Hello: c!", "
"] +class Test_provider_outer_api: + """Ensure provider implements __iter__/__str__""" + + def test_iter(self) -> None: + result = letter_ctx.provider("c", lambda: div[display_letter("Hello")]) + assert list(result) == ["
", "Hello: c!", "
"] + + def test_str(self) -> None: + result = str(letter_ctx.provider("c", lambda: div[display_letter("Hello")])) + assert result == "
Hello: c!
" + assert isinstance(result, markupsafe.Markup) + + def test_no_default(render: RenderFixture) -> None: with pytest.raises( LookupError,