Skip to content

Commit

Permalink
Added test, and layout shouldn't be called if there's no applicator; …
Browse files Browse the repository at this point in the history
…we count on having the style._applicator.node link
  • Loading branch information
HalfWhitt committed Dec 31, 2024
1 parent fdf1fa6 commit 7d29b59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/travertino/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def refresh(self, viewport):
if self._root:
self._root.refresh(viewport)
else:
self.style.layout(*self._layout_args(viewport))
if self.applicator:
self.style.layout(*self._layout_args(viewport))
self.applicator.set_bounds()

######################################################################
Expand Down
37 changes: 37 additions & 0 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,43 @@ def test_create_node():
assert child3.root == new_node


@pytest.mark.parametrize(
"StyleClass, method_name",
[
(Style, "_layout_args_new"),
(OldStyle, "_layout_args_old"),
],
)
def test_layout_signature_check(StyleClass, method_name):
"""Which signauture to use is only checked once."""

class Applicator:
def set_bounds(self):
pass

class TestNode(Node):
# So we don't change the actual Node class
pass

# Before refresh() is called, _layout_args is still the original decision-maker.
assert TestNode._layout_args != getattr(TestNode, method_name)
node_1 = TestNode(style=StyleClass(), applicator=Applicator())
node_2 = TestNode(style=StyleClass(), applicator=Applicator())
assert node_1._layout_args != getattr(node_1, method_name)
assert node_1._layout_args != getattr(node_1, method_name)

# _layout_args should now be replaced with the correct version -- for the node that
# called refresh, as well as a preexisting other instance, and the class itself.
node_1.refresh(Viewport(width=10, height=20))
assert TestNode._layout_args == getattr(TestNode, method_name)
assert node_1._layout_args == getattr(node_1, method_name)
assert node_2._layout_args == getattr(node_2, method_name)

# Should also hold true for subsequently created instances.
node_3 = TestNode(style=StyleClass(), applicator=Applicator())
assert node_3._layout_args == getattr(node_3, method_name)


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

0 comments on commit 7d29b59

Please sign in to comment.