From f8d4f3f2c736eb80abd45af32529f1ab6119d422 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Sun, 29 Dec 2024 22:03:04 -0500 Subject: [PATCH] Test both forms of layout() --- tests/test_node.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/test_node.py b/tests/test_node.py index 2160156..799f1ae 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -15,6 +15,24 @@ class Style(BaseStyle): int_prop: int = validated_property(Choices(integer=True)) + class IntrinsicSize(BaseIntrinsicSize): + pass + + class Box(BaseBox): + pass + + def layout(self, viewport): + # A simple layout scheme that allocates twice the viewport size. + self._applicator.node.layout.content_width = viewport.width * 2 + self._applicator.node.layout.content_height = viewport.height * 2 + + +@prep_style_class +@mock_attr("reapply") +class OldStyle(BaseStyle): + # Uses two-argument layout(), as in Toga <= 0.4.8 + int_prop: int = validated_property(Choices(integer=True)) + class IntrinsicSize(BaseIntrinsicSize): pass @@ -38,10 +56,10 @@ class IntrinsicSize(BaseIntrinsicSize): class Box(BaseBox): pass - def layout(self, root, viewport): + def layout(self, viewport): # A simple layout scheme that allocates twice the viewport size. - root.layout.content_width = viewport.width * 2 - root.layout.content_height = viewport.height * 2 + self._applicator.node.layout.content_width = viewport.width * 2 + self._applicator.node.layout.content_height = viewport.height * 2 class AttributeTestStyle(BaseStyle): @@ -130,7 +148,8 @@ def test_create_node(): assert child3.root == new_node -def test_refresh(): +@pytest.mark.parametrize("StyleClass", [Style, OldStyle]) +def test_refresh(StyleClass): """The layout can be refreshed, and the applicator invoked""" # Define an applicator that tracks the node being rendered and its size @@ -155,7 +174,7 @@ def __init__(self, style, children=None): ) # Define a simple 2 level tree of nodes. - style = Style() + style = StyleClass() child1 = TestNode(style=style) child2 = TestNode(style=style) child3 = TestNode(style=style)