Skip to content

Commit

Permalink
Fixed value check in property assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Nov 13, 2024
1 parent ccd7063 commit dd2659d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/travertino/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __set__(self, obj, value):

value = self.validate(value)

if value != getattr(obj, f"_{self.name}", None):
if value != getattr(obj, f"_{self.name}", self.initial):
setattr(obj, f"_{self.name}", value)
obj.apply(self.name, value)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ def test_property_with_implicit_default(StyleClass):
style.apply.assert_called_once_with("implicit", None)


@pytest.mark.parametrize("StyleClass", [Style, DeprecatedStyle])
def test_set_initial_no_apply(StyleClass):
"""If a property hasn't been set, assigning it its initial value shouldn't apply."""
style = StyleClass()

# 0 is the initial value
style.explicit_value = 0

style.apply.assert_not_called()


@pytest.mark.parametrize("StyleClass", [Style, DeprecatedStyle])
def test_directional_property(StyleClass):
style = StyleClass()
Expand Down

0 comments on commit dd2659d

Please sign in to comment.