Exemple #1
0
    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
Exemple #2
0
    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()
Exemple #3
0
    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
Exemple #5
0
 def _preferences_default(self):
     return ScopedPreferences()
Exemple #6
0
    def _preferences_default(self):
        """ Trait initializer. """

        return ScopedPreferences()