|
@@ -3424,6 +3424,18 @@ class ChildUsesMixinState(UsesMixinState):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
+class ChildMixinState(ChildUsesMixinState, mixin=True):
|
|
|
|
+ """A mixin state that inherits from a concrete state that uses mixins."""
|
|
|
|
+
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class GrandchildUsesMixinState(ChildMixinState):
|
|
|
|
+ """A grandchild state that uses the mixin state."""
|
|
|
|
+
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
def test_mixin_state() -> None:
|
|
def test_mixin_state() -> None:
|
|
"""Test that a mixin state works correctly."""
|
|
"""Test that a mixin state works correctly."""
|
|
assert "num" in UsesMixinState.base_vars
|
|
assert "num" in UsesMixinState.base_vars
|
|
@@ -3438,6 +3450,9 @@ def test_mixin_state() -> None:
|
|
is not UsesMixinState.backend_vars["_backend_no_default"]
|
|
is not UsesMixinState.backend_vars["_backend_no_default"]
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ assert UsesMixinState.get_parent_state() == State
|
|
|
|
+ assert UsesMixinState.get_root_state() == State
|
|
|
|
+
|
|
|
|
|
|
def test_child_mixin_state() -> None:
|
|
def test_child_mixin_state() -> None:
|
|
"""Test that mixin vars are only applied to the highest state in the hierarchy."""
|
|
"""Test that mixin vars are only applied to the highest state in the hierarchy."""
|
|
@@ -3447,6 +3462,24 @@ def test_child_mixin_state() -> None:
|
|
assert "computed" in ChildUsesMixinState.inherited_vars
|
|
assert "computed" in ChildUsesMixinState.inherited_vars
|
|
assert "computed" not in ChildUsesMixinState.computed_vars
|
|
assert "computed" not in ChildUsesMixinState.computed_vars
|
|
|
|
|
|
|
|
+ assert ChildUsesMixinState.get_parent_state() == UsesMixinState
|
|
|
|
+ assert ChildUsesMixinState.get_root_state() == State
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_grandchild_mixin_state() -> None:
|
|
|
|
+ """Test that a mixin can inherit from a concrete state class."""
|
|
|
|
+ assert "num" in GrandchildUsesMixinState.inherited_vars
|
|
|
|
+ assert "num" not in GrandchildUsesMixinState.base_vars
|
|
|
|
+
|
|
|
|
+ assert "computed" in GrandchildUsesMixinState.inherited_vars
|
|
|
|
+ assert "computed" not in GrandchildUsesMixinState.computed_vars
|
|
|
|
+
|
|
|
|
+ assert ChildMixinState.get_parent_state() == ChildUsesMixinState
|
|
|
|
+ assert ChildMixinState.get_root_state() == State
|
|
|
|
+
|
|
|
|
+ assert GrandchildUsesMixinState.get_parent_state() == ChildUsesMixinState
|
|
|
|
+ assert GrandchildUsesMixinState.get_root_state() == State
|
|
|
|
+
|
|
|
|
|
|
def test_assignment_to_undeclared_vars():
|
|
def test_assignment_to_undeclared_vars():
|
|
"""Test that an attribute error is thrown when undeclared vars are set."""
|
|
"""Test that an attribute error is thrown when undeclared vars are set."""
|