Skip to content

Commit

Permalink
Force trait order by redeclaring traits
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Jul 15, 2024
1 parent 0d8436e commit 679df32
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions envisage/ui/tasks/tests/test_preferences_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@


from apptools.preferences.api import (
IPreferences,
Preferences,
PreferencesHelper,
ScopedPreferences,
)
from traits.api import Str
from traits.api import Instance, Str
from traitsui.api import Item, View

from envisage.ui.tasks.api import PreferencesPane


class MyPreferences(PreferencesHelper):
#: Redeclare preferences to force trait copying order.
preferences = Instance(IPreferences)

#: The node that contains the preferences.
preferences_path = "app"
preferences_path = Str("app")

#: The user's favourite colour
color = Str()
Expand All @@ -37,9 +41,7 @@ class MyPreferencesPane(PreferencesPane):

model_factory = MyPreferences

view = View(
Item("color"),
)
view = View(Item("color"))


class TestPreferencesPane(unittest.TestCase):
Expand All @@ -57,8 +59,10 @@ def test_no_preference_changes_without_apply(self):
self.assertIsNone(application_preferences.get("app.color"))
pane = MyPreferencesPane(model=helper)

object_context = pane.trait_context()["object"]
# The trait_context method triggers the problematic clone_traits
# operation.
pane.trait_context()["object"]

# At this point, the application preferences should still not
# have an app.color setting
self.assertIsNone(object_context.color)
self.assertIsNone(application_preferences.get("app.color"))

0 comments on commit 679df32

Please sign in to comment.