Skip to content
This repository has been archived by the owner on Jan 25, 2025. It is now read-only.

Commit

Permalink
Test both forms of layout()
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Dec 30, 2024
1 parent ef049e3 commit f8d4f3f
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f8d4f3f

Please sign in to comment.