Skip to content

Commit

Permalink
Add test for context provider API.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelme committed Sep 15, 2024
1 parent 08f0b45 commit f4b80a2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import typing as t

import markupsafe
import pytest

from htpy import Context, Node, div
Expand Down Expand Up @@ -33,6 +34,19 @@ def test_context_provider(render: RenderFixture) -> None:
assert render(result) == ["<div>", "Hello: c!", "</div>"]


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) == ["<div>", "Hello: c!", "</div>"]

def test_str(self) -> None:
result = str(letter_ctx.provider("c", lambda: div[display_letter("Hello")]))
assert result == "<div>Hello: c!</div>"
assert isinstance(result, markupsafe.Markup)


def test_no_default(render: RenderFixture) -> None:
with pytest.raises(
LookupError,
Expand Down

0 comments on commit f4b80a2

Please sign in to comment.