From dd2659d81e558825cb1579b08dc92bd8c04b2d74 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 13 Nov 2024 00:04:04 -0500 Subject: [PATCH] Fixed value check in property assignment --- src/travertino/declaration.py | 2 +- tests/test_declaration.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/travertino/declaration.py b/src/travertino/declaration.py index 91791af..9599ea6 100644 --- a/src/travertino/declaration.py +++ b/src/travertino/declaration.py @@ -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) diff --git a/tests/test_declaration.py b/tests/test_declaration.py index 753362a..c2f1414 100644 --- a/tests/test_declaration.py +++ b/tests/test_declaration.py @@ -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()