示例#1
0
    def test_unknown_parent(self):
        """Raise an exception if parent is an unknown type"""
        @parent.Parent('test_parent')
        class Parent(object):
            """Parent"""

        # Clear registry
        parent.get_plugins().clear()

        with self.assertRaisesRegex(ValueError, "Unknown parent type"):

            class Child1(Parent):  # pylint: disable=unused-variable
                """Child"""
                _alias_ = 'child'
示例#2
0
    def get_plugin(self, plugin_type, name, version=None):
        """
        Args:
            plugin_type(str): Parent type
            name(str): Plugin name
            version(str): Plugin version

        Returns:
            :py:class:`Plugin`: Plugin, or :py:data:`None` if plugin can't be found

        Retrieve a specific plugin. ``blacklist`` and ``type_filter`` still apply.

        If ``version`` is not specified, the newest available version is returned.
        """

        if not self.loaded:
            self.load_modules()

        # pylint: disable=protected-access
        return get_plugins()[self.group]._filter(blacklist=self.blacklist,
                                                 newest_only=True,
                                                 type_filter=self.type_filter,
                                                 type=plugin_type,
                                                 name=name,
                                                 version=version)
示例#3
0
    def test_parent_bare(self):
        """Parent type defaults to parent class name"""
        @parent.Parent
        class Basic(object):
            """Basic document string"""

        self.assertEqual(Basic._type_, 'Basic')
        self.assertTrue('Basic' in parent.get_plugins()['_default'])
示例#4
0
    def test_parent_basic(self):
        """Basic use of Parent decorator"""
        @parent.Parent('basic')
        class Basic(object):
            """Basic document string"""

        self.assertTrue(issubclass(Basic, parent.Plugin))
        self.assertTrue(isinstance(Basic, parent.PluginType))
        self.assertTrue(Basic._parent_)
        self.assertTrue(Basic._skipload_)
        self.assertEqual(Basic.__doc__, 'Basic document string')
        self.assertEqual(Basic._type_, 'basic')
        self.assertTrue('basic' in parent.get_plugins()['_default'])
示例#5
0
    def plugins_all(self):
        """
        All resulting versions of all plugins in the group filtered by ``blacklist``

        Returns:
            dict: Nested dictionary of plugins accessible through dot-notation.

        Similar to :py:attr:`plugins`, but lowest level is a regular dictionary of
        all unfiltered plugin versions for the given plugin type and name.

        Parent types are always included.
        Child plugins will only be included if at least one valid, non-blacklisted plugin
        is available.
        """

        if not self.loaded:
            self.load_modules()

        # pylint: disable=protected-access
        return get_plugins()[self.group]._filter(blacklist=self.blacklist,
                                                 type_filter=self.type_filter)
示例#6
0
    def plugins(self):
        """
        Newest version of all plugins in the group filtered by ``blacklist``

        Returns:
            dict: Nested dictionary of plugins accessible through dot-notation.

        Plugins are returned in a nested dictionary, but can also be accessed through dot-notion.
        Just as when accessing an undefined dictionary key with index-notation,
        a :py:exc:`KeyError` will be raised if the plugin type or plugin does not exist.

        Parent types are always included.
        Child plugins will only be included if a valid, non-blacklisted plugin is available.
        """

        if not self.loaded:
            self.load_modules()

        # pylint: disable=protected-access
        return get_plugins()[self.group]._filter(blacklist=self.blacklist, newest_only=True,
                                                 type_filter=self.type_filter)
示例#7
0
    def tearDown(self):

        # Clear plugins from module
        parent.get_plugins().clear()