Skip to content

Commit

Permalink
Assign node to applicator before reapply can happen
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Nov 5, 2024
1 parent 99a1189 commit 17c6213
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/travertino/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def applicator(self):

@applicator.setter
def applicator(self, applicator):
self._applicator = applicator
self.style._applicator = applicator

if applicator:
applicator.node = self

self._applicator = applicator
self.style._applicator = applicator

@property
def root(self):
"""The root of the tree containing this node.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import Mock
from warnings import catch_warnings

import pytest

Expand Down Expand Up @@ -43,6 +44,17 @@ def layout(self, root, viewport):
root.layout.content_height = viewport.height * 2


class AttributeTestStyle(BaseStyle):
class IntrinsicSize(BaseIntrinsicSize):
pass

class Box(BaseBox):
pass

def reapply(self):
assert self._applicator.node.style is self


def test_create_leaf():
"""A leaf can be created"""
style = Style()
Expand Down Expand Up @@ -371,3 +383,11 @@ def test_apply_before_node_is_ready():

with pytest.warns(RuntimeWarning):
Node(style=style, applicator=applicator)


def test_applicator_has_node_reference():
# At the point that the style tries to apply itself, the applicator should already
# have a reference to its node.

with catch_warnings(action="error", category=RuntimeWarning):
Node(style=AttributeTestStyle(), applicator=Mock())

0 comments on commit 17c6213

Please sign in to comment.