def test_ability_to_specify_primary_scope(self): preferences = ScopedPreferences( scopes=[Preferences(name="a"), Preferences(name="b"), Preferences(name="c")], primary_scope_name="b" ) # This should set the prefrrence in the primary scope. preferences.set("acme.foo", "bar") # Look it up specifically in the primary scope. self.assertEqual("bar", preferences.get("b/acme.foo")) return
def test_scoped_preferences(self): """ scoped preferences """ p = set_default_preferences(ScopedPreferences()) # Set a preference value in the default scope. p.set('default/acme.ui.bgcolor', 'blue') class AcmeUIPreferencesHelper(PreferencesHelper): """ A helper! """ # The path to the preferences node that contains our preferences. preferences_path = 'acme.ui' # The traits that we want to initialize from preferences. bgcolor = Str # A trait for a preference that does not exist yet. name = Str helper = AcmeUIPreferencesHelper() # Make sure the trait is set! self.assertEqual('blue', helper.bgcolor) # And that the non-existent trait gets the default value. self.assertEqual('', helper.name) return
def test_ability_to_specify_primary_scope(self): preferences = ScopedPreferences( scopes=[ Preferences(name="a"), Preferences(name="b"), Preferences(name="c"), ], primary_scope_name="b", ) # This should set the prefrrence in the primary scope. preferences.set("acme.foo", "bar") # Look it up specifically in the primary scope. self.assertEqual("bar", preferences.get("b/acme.foo"))
def test_ability_to_specify_primary_scope(self): preferences = ScopedPreferences(scopes=[ Preferences(name='a'), Preferences(name='b'), Preferences(name='c') ], primary_scope_name='b') # This should set the prefrrence in the primary scope. preferences.set('acme.foo', 'bar') # Look it up specifically in the primary scope. self.assertEqual('bar', preferences.get('b/acme.foo')) return
def setUp(self): """ Prepares the test fixture before each test method is called. """ self.preferences = ScopedPreferences() # The filename of the example preferences file. self.example = os.fspath(files(PKG) / "example.ini") # A temporary directory that can safely be written to. self.tmpdir = tempfile.mkdtemp()
def test_ability_to_specify_primary_scope(self): preferences = ScopedPreferences( scopes = [ Preferences(name='a'), Preferences(name='b'), Preferences(name='c') ], primary_scope_name = 'b' ) # This should set the prefrrence in the primary scope. preferences.set('acme.foo', 'bar') # Look it up specifically in the primary scope. self.assertEqual('bar', preferences.get('b/acme.foo')) return
def _preferences_default(self): return ScopedPreferences()
def _preferences_default(self): """ Trait initializer. """ return ScopedPreferences()
from traits.etsconfig.api import ETSConfig from apptools.preferences.api import ScopedPreferences, set_default_preferences, get_default_preferences import os import sys ETSConfig.company = 'Infobiotics' preferences = ScopedPreferences(filename=os.path.join(ETSConfig.get_application_data(create=True), 'preferences.ini')) set_default_preferences(preferences) # allows use of Preferences, PreferencesHelper and bind_preference without explicitly passing preferences assert preferences == get_default_preferences() from infobiotics.mcss.mcss_preferences import PREFERENCES_PATH as MCSS_PREFERENCES_PATH from infobiotics.mcsscmaes.mcsscmaes_preferences import PREFERENCES_PATH as MCSSCMAES_PREFERENCES_PATH from infobiotics.pmodelchecker.pmodelchecker_preferences import PREFERENCES_PATH as PMODELCHECKER_PREFERENCES_PATH from infobiotics.pmodelchecker.prism.prism_preferences import PREFERENCES_PATH as PRISM_PREFERENCES_PATH from infobiotics.pmodelchecker.mc2.mc2_preferences import PREFERENCES_PATH as MC2_PREFERENCES_PATH from infobiotics.pmodelchecker.mc2.mc2_preferences import MC2_MCSS_PREFERENCES_PATH from infobiotics.poptimizer.poptimizer_preferences import PREFERENCES_PATH as POPTIMIZER_PREFERENCES_PATH DEFAULT_MCSS_EXECUTABLE = 'default/'+MCSS_PREFERENCES_PATH+'.executable' DEFAULT_MCSSCMAES_EXECUTABLE = 'default/'+MCSSCMAES_PREFERENCES_PATH+'.executable' DEFAULT_PMODELCHECKER_EXECUTABLE = 'default/'+PMODELCHECKER_PREFERENCES_PATH+'.executable' DEFAULT_PRISM_EXECUTABLE = 'default/'+PRISM_PREFERENCES_PATH+'.executable' DEFAULT_MC2_EXECUTABLE = 'default/'+MC2_PREFERENCES_PATH+'.executable' DEFAULT_MC2_MCSS_EXECUTABLE = 'default/'+MC2_MCSS_PREFERENCES_PATH+'.executable' DEFAULT_POPTIMIZER_EXECUTABLE = 'default/'+POPTIMIZER_PREFERENCES_PATH+'.executable' if sys.platform.startswith('win'): preferences.set(DEFAULT_MCSS_EXECUTABLE, 'mcss.exe'), preferences.set(DEFAULT_MCSSCMAES_EXECUTABLE, 'mcss-cmaes.exe'), preferences.set(DEFAULT_PMODELCHECKER_EXECUTABLE, 'pmodelchecker.exe'),