File: conftest.py

package info (click to toggle)
streamlink 8.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,564 kB
  • sloc: python: 51,188; sh: 184; makefile: 152
file content (92 lines) | stat: -rw-r--r-- 2,821 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from __future__ import annotations

from typing import TYPE_CHECKING

from tests.plugins import PluginCanHandleUrl


if TYPE_CHECKING:
    from collections.abc import Callable

    import pytest

    from streamlink.plugin.plugin import Matcher


def pytest_collection_modifyitems(items: list[pytest.Item]):  # pragma: no cover
    # remove empty parametrized tests
    items[:] = [
        item
        for item in items
        if not any(
            marker.name == "skip" and str(marker.kwargs.get("reason", "")).startswith("got empty parameter set")
            for marker in item.own_markers
        )
    ]


def pytest_generate_tests(metafunc: pytest.Metafunc):
    if metafunc.cls is not None and issubclass(metafunc.cls, PluginCanHandleUrl):
        name: str = f"_parametrize_plugincanhandleurl_{metafunc.function.__name__}"
        parametrizer: Callable[[pytest.Metafunc], None] | None = globals().get(name)
        if parametrizer:
            parametrizer(metafunc)


def _parametrize_plugincanhandleurl_test_all_matchers_match(metafunc: pytest.Metafunc):
    matchers: list[tuple[int, Matcher]] = list(enumerate(metafunc.cls.matchers()))
    metafunc.parametrize(
        "matcher",
        [m for i, m in matchers],
        ids=[m.name or f"#{i}" for i, m in matchers],
    )


def _parametrize_plugincanhandleurl_test_all_named_matchers_have_tests(metafunc: pytest.Metafunc):
    matchers: list[Matcher] = [m for m in metafunc.cls.matchers() if m.name is not None]
    metafunc.parametrize(
        "matcher",
        matchers,
        ids=[m.name for m in matchers],
    )


def _parametrize_plugincanhandleurl_test_url_matches_positive_unnamed(metafunc: pytest.Metafunc):
    metafunc.parametrize(
        "url",
        metafunc.cls.urls_unnamed(),
    )


def _parametrize_plugincanhandleurl_test_url_matches_positive_named(metafunc: pytest.Metafunc):
    urls = metafunc.cls.urls_named()
    metafunc.parametrize(
        "name,url",
        urls,
        ids=[f"NAME={name} URL={url}" for name, url in urls],
    )


def _parametrize_plugincanhandleurl_test_url_matches_groups_unnamed(metafunc: pytest.Metafunc):
    urlgroups = metafunc.cls.urlgroups_unnamed()
    metafunc.parametrize(
        "url,groups",
        urlgroups,
        ids=[f"URL={url} GROUPS={groups}" for url, groups in urlgroups],
    )


def _parametrize_plugincanhandleurl_test_url_matches_groups_named(metafunc: pytest.Metafunc):
    urlgroups = metafunc.cls.urlgroups_named()
    metafunc.parametrize(
        "name,url,groups",
        urlgroups,
        ids=[f"NAME={name} URL={url} GROUPS={groups}" for name, url, groups in urlgroups],
    )


def _parametrize_plugincanhandleurl_test_url_matches_negative(metafunc: pytest.Metafunc):
    metafunc.parametrize(
        "url",
        metafunc.cls.urls_negative(),
    )