-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ec68a4
commit 0d8436e
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# (C) Copyright 2007-2023 Enthought, Inc., Austin, TX | ||
# All rights reserved. | ||
# | ||
# This software is provided without warranty under the terms of the BSD | ||
# license included in LICENSE.txt and may be redistributed only under | ||
# the conditions described in the aforementioned license. The license | ||
# is also available online at http://www.enthought.com/licenses/BSD.txt | ||
# | ||
# Thanks for using Enthought open source! | ||
|
||
"""Tests for the PreferencesPane.""" | ||
|
||
|
||
import unittest | ||
|
||
|
||
from apptools.preferences.api import ( | ||
Preferences, | ||
PreferencesHelper, | ||
ScopedPreferences, | ||
) | ||
from traits.api import Str | ||
from traitsui.api import Item, View | ||
|
||
from envisage.ui.tasks.api import PreferencesPane | ||
|
||
|
||
class MyPreferences(PreferencesHelper): | ||
#: The node that contains the preferences. | ||
preferences_path = "app" | ||
|
||
#: The user's favourite colour | ||
color = Str() | ||
|
||
|
||
class MyPreferencesPane(PreferencesPane): | ||
|
||
model_factory = MyPreferences | ||
|
||
view = View( | ||
Item("color"), | ||
) | ||
|
||
|
||
class TestPreferencesPane(unittest.TestCase): | ||
def test_no_preference_changes_without_apply(self): | ||
# Regression test for https://github.com/enthought/envisage/issues/582 | ||
default_preferences = Preferences(name="default") | ||
default_preferences.set("app.color", "red") | ||
|
||
application_preferences = Preferences(name="application") | ||
preferences = ScopedPreferences( | ||
scopes=[application_preferences, default_preferences] | ||
) | ||
|
||
helper = MyPreferences(preferences=preferences) | ||
self.assertIsNone(application_preferences.get("app.color")) | ||
pane = MyPreferencesPane(model=helper) | ||
|
||
object_context = pane.trait_context()["object"] | ||
|
||
# At this point, the application preferences should still not | ||
# have an app.color setting | ||
self.assertIsNone(object_context.color) |