Skip to content

Commit

Permalink
Simplify test style, make shim also work for differnt parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Dec 30, 2024
1 parent f8d4f3f commit 8fcf1bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/travertino/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def refresh(self, viewport):
######################################################################
# 2024-12: Backwards compatibility for Toga <= 0.4.8
######################################################################
if "node" in signature(self.style.layout).parameters:
params = signature(self.style.layout).parameters
if len(params) == 2 and "_deprecated_usage" not in params:
self.style.layout(self, viewport)
else:
self.style.layout(viewport)
Expand Down
23 changes: 9 additions & 14 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@ def layout(self, viewport):
self._applicator.node.layout.content_height = viewport.height * 2


@prep_style_class
@mock_attr("reapply")
class OldStyle(BaseStyle):
class OldStyle(Style):
# Uses two-argument layout(), as in Toga <= 0.4.8
int_prop: int = validated_property(Choices(integer=True))

class IntrinsicSize(BaseIntrinsicSize):
pass
def layout(self, node, viewport):
super().layout(viewport)

class Box(BaseBox):
pass

def layout(self, node, viewport):
# A simple layout scheme that allocates twice the viewport size.
node.layout.content_width = viewport.width * 2
node.layout.content_height = viewport.height * 2
class OldStyleDifferentName(Style):
# Just to be on the paranoid side, also test with a different parameter name, like
# this test used to have.
def layout(self, root, viewport):
super().layout(viewport)


@prep_style_class
Expand Down Expand Up @@ -148,7 +143,7 @@ def test_create_node():
assert child3.root == new_node


@pytest.mark.parametrize("StyleClass", [Style, OldStyle])
@pytest.mark.parametrize("StyleClass", [Style, OldStyle, OldStyleDifferentName])
def test_refresh(StyleClass):
"""The layout can be refreshed, and the applicator invoked"""

Expand Down

0 comments on commit 8fcf1bd

Please sign in to comment.