Esempio n. 1
0
    def __new__(mcs, name, bases, dict):
        plugin_path = os.path.dirname(streamlink.plugins.__file__)
        plugins = []
        for loader, pname, ispkg in pkgutil.iter_modules([plugin_path]):
            module = load_module(pname, plugin_path)
            if hasattr(module, "__plugin__"):
                plugins.append((pname))

        session = Streamlink()

        def gentest(pname):
            def load_plugin_test(self):
                # Reset file variable to ensure it is still open when doing
                # load_plugin else python might open the plugin source .py
                # using ascii encoding instead of utf-8.
                # See also open() call here: imp._HackedGetData.get_data
                file, pathname, desc = imp.find_module(pname, [plugin_path])
                session.load_plugin(pname, file, pathname, desc)
                # validate that can_handle_url does not fail
                session.plugins[pname].can_handle_url("http://test.com")

            return load_plugin_test

        for pname in plugins:
            dict['test_{0}_load'.format(pname)] = gentest(pname)

        return type.__new__(mcs, name, bases, dict)
Esempio n. 2
0
    def __new__(mcs, name, bases, dict):
        plugin_path = os.path.dirname(streamlink.plugins.__file__)
        plugins = []
        for loader, pname, ispkg in pkgutil.iter_modules([plugin_path]):
            file, pathname, desc = imp.find_module(pname, [plugin_path])
            module = imp.load_module(pname, file, pathname, desc)
            if hasattr(module, "__plugin__"):
                plugins.append((pname))

        session = Streamlink()

        def gentest(pname):
            def load_plugin_test(self):
                # Reset file variable to ensure it is still open when doing
                # load_plugin else python might open the plugin source .py
                # using ascii encoding instead of utf-8.
                # See also open() call here: imp._HackedGetData.get_data
                file, pathname, desc = imp.find_module(pname, [plugin_path])
                session.load_plugin(pname, file, pathname, desc)

            return load_plugin_test

        for pname in plugins:
            dict['test_{0}_load'.format(pname)] = gentest(pname)

        return type.__new__(mcs, name, bases, dict)
Esempio n. 3
0
    def __new__(mcs, name, bases, dict):
        plugin_path = os.path.dirname(streamlink.plugins.__file__)
        plugins = []
        for loader, pname, ispkg in pkgutil.iter_modules([plugin_path]):
            module = load_module(f"streamlink.plugins.{pname}", plugin_path)
            if hasattr(module, "__plugin__"):
                plugins.append((loader, pname))

        def gentest(loader, pname):
            def load_plugin_test(self):
                plugin = loader.find_module(pname).load_module(pname)
                assert hasattr(plugin, "__plugin__"), "It exports __plugin__"
                assert issubclass(
                    plugin.__plugin__,
                    Plugin), "__plugin__ is an instance of the Plugin class"

                assert callable(plugin.__plugin__._get_streams
                                ), "The plugin implements _get_streams"
                assert callable(plugin.__plugin__.can_handle_url
                                ), "The plugin implements can_handle_url"
                sig = inspect.signature(plugin.__plugin__.can_handle_url)
                assert str(
                    sig) == "(url)", "can_handle_url only accepts the url arg"

            return load_plugin_test

        for loader, pname in plugins:
            dict[f"test_{pname}_load"] = gentest(loader, pname)

        return type.__new__(mcs, name, bases, dict)
Esempio n. 4
0
    def __new__(mcs, name, bases, dict):
        plugin_path = os.path.dirname(streamlink.plugins.__file__)
        plugins = []
        for loader, pname, ispkg in pkgutil.iter_modules([plugin_path]):
            module = load_module(pname, plugin_path)
            if hasattr(module, "__plugin__"):
                plugins.append((loader, pname))

        def gentest(loader, pname):
            def load_plugin_test(self):
                plugin = loader.find_module(pname).load_module(pname)
                assert hasattr(plugin, "__plugin__"), "It exports __plugin__"
                assert issubclass(
                    plugin.__plugin__,
                    Plugin), "__plugin__ is an instance of the Plugin class"

                classname = plugin.__plugin__.__name__
                assert classname == classname[0].upper() + classname[
                    1:], "__plugin__ class name starts with uppercase letter"
                assert "_" not in classname, "__plugin__ class name does not contain underscores"

                assert callable(plugin.__plugin__._get_streams
                                ), "The plugin implements _get_streams"
                assert callable(plugin.__plugin__.can_handle_url
                                ), "The plugin implements can_handle_url"
                if hasattr(inspect, 'signature'):
                    sig = inspect.signature(plugin.__plugin__.can_handle_url)
                else:
                    argspec = inspect.getargspec(
                        plugin.__plugin__.can_handle_url)
                    # Generate the argument list that is separated by colons.
                    args = argspec.args[:]
                    if argspec.defaults:
                        offset = len(args) - len(argspec.defaults)
                        for i, default in enumerate(argspec.defaults):
                            args[i + offset] = '{}={!r}'.format(
                                args[i + offset], argspec.defaults[i])
                    if argspec.varargs:
                        args.append('*' + argspec.varargs)
                    if argspec.keywords:
                        args.append('**' + argspec.keywords)
                    sig = '(' + ', '.join(args[1:]) + ')'

                assert str(
                    sig) == "(url)", "can_handle_url only accepts the url arg"

            return load_plugin_test

        for loader, pname in plugins:
            dict["test_{0}_load".format(pname)] = gentest(loader, pname)

        return type.__new__(mcs, name, bases, dict)
Esempio n. 5
0
    def __new__(mcs, name, bases, dict):
        plugin_path = os.path.dirname(streamlink.plugins.__file__)
        plugins = []
        for loader, pname, ispkg in pkgutil.iter_modules([plugin_path]):
            module = load_module(f"streamlink.plugins.{pname}", plugin_path)
            if hasattr(module, "__plugin__"):
                plugins.append((loader, pname))

        def gentest(loader, pname):
            def load_plugin_test(self):
                plugin = loader.find_module(pname).load_module(pname)
                assert hasattr(plugin, "__plugin__"), "It exports __plugin__"

                pluginclass = plugin.__plugin__
                assert issubclass(
                    plugin.__plugin__,
                    Plugin), "__plugin__ is an instance of the Plugin class"

                classname = pluginclass.__name__
                assert classname == classname[0].upper() + classname[
                    1:], "__plugin__ class name starts with uppercase letter"
                assert "_" not in classname, "__plugin__ class name does not contain underscores"

                assert isinstance(pluginclass.matchers, list) and len(
                    pluginclass.matchers) > 0, "Has at least one matcher"
                assert all(
                    isinstance(matcher, Matcher) for matcher in
                    pluginclass.matchers), "Only has valid matchers"

                assert not hasattr(
                    pluginclass, "can_handle_url"
                ), "Does not implement deprecated can_handle_url(url)"
                assert not hasattr(
                    pluginclass,
                    "priority"), "Does not implement deprecated priority(url)"
                assert callable(
                    pluginclass._get_streams), "Implements _get_streams()"

            return load_plugin_test

        for loader, pname in plugins:
            dict[f"test_{pname}_load"] = gentest(loader, pname)

        return type.__new__(mcs, name, bases, dict)
Esempio n. 6
0
    def __new__(mcs, name, bases, dict):
        plugin_path = os.path.dirname(streamlink.plugins.__file__)
        plugins = []
        for loader, pname, ispkg in pkgutil.iter_modules([plugin_path]):
            file, pathname, desc = imp.find_module(pname, [plugin_path])
            module = imp.load_module(pname, file, pathname, desc)
            if hasattr(module, "__plugin__"):
                plugins.append((pname, file, pathname, desc))

        session = Streamlink()

        def gentest(pname, file, pathname, desc):
            def load_plugin_test(self):
                session.load_plugin(pname, file, pathname, desc)

            return load_plugin_test

        for pname, file, pathname, desc in plugins:
            dict['test_{0}_load'.format(pname)] = gentest(
                pname, file, pathname, desc)

        return type.__new__(mcs, name, bases, dict)