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()