File: test_player.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 (190 lines) | stat: -rw-r--r-- 6,076 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING
from unittest.mock import call, patch

import pytest

from streamlink_cli.utils.player import find_default_player


if TYPE_CHECKING:
    from unittest.mock import Mock


# noinspection PyTestParametrized
class TestFindDefaultPlayer:
    @pytest.fixture(autouse=True)
    def _fakehome(self, request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch):
        home = getattr(request, "param", "")
        monkeypatch.setattr("streamlink_cli.utils.player.Path.home", lambda: home)

    @pytest.fixture(autouse=True)
    def _environ(self, request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch):
        for key, value in getattr(request, "param", {}).items():
            monkeypatch.setenv(key, value)

    @pytest.fixture(autouse=True)
    def which(self, request: pytest.FixtureRequest):
        return_values = getattr(request, "param", {})
        with patch("streamlink_cli.utils.player.which", side_effect=lambda path: return_values.get(path, None)) as mock_which:
            yield mock_which

    @pytest.fixture(autouse=True)
    def _assert_find_default_player(
        self,
        request: pytest.FixtureRequest,
        monkeypatch: pytest.MonkeyPatch,
        which: Mock,
        lookups: list[str],
        expected: str | None,
    ):
        monkeypatch.setattr("streamlink_cli.utils.player.is_win32", "win32" in request.function.__name__)
        monkeypatch.setattr("streamlink_cli.utils.player.is_darwin", "darwin" in request.function.__name__)
        yield
        assert find_default_player() == expected
        assert which.call_args_list == [call(path) for path in lookups]

    @pytest.mark.windows_only()
    @pytest.mark.parametrize(
        "_environ",
        [
            {
                "PROGRAMFILES": "C:\\Program Files",
                "PROGRAMFILES(X86)": "C:\\Program Files (x86)",
                "PROGRAMW6432": "C:\\Program Files",
            },
        ],
        indirect=True,
    )
    @pytest.mark.parametrize(
        ("which", "lookups", "expected"),
        [
            pytest.param(
                {"vlc.exe": "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"},
                ["vlc.exe"],
                Path("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"),
                id="PATH lookup success",
            ),
            pytest.param(
                {"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe": "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe"},
                [
                    "vlc.exe",
                    "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe",
                    "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe",
                ],
                Path("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe"),
                id="fallback paths lookup success",
            ),
            pytest.param(
                {},
                [
                    "vlc.exe",
                    "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe",
                    "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe",
                ],
                None,
                id="lookup failure",
            ),
        ],
        indirect=["which"],
    )
    def test_win32(self):
        pass

    @pytest.mark.windows_only()
    @pytest.mark.parametrize(
        "_environ",
        [
            {
                "PROGRAMFILES": "",
                "PROGRAMFILES(X86)": "",
                "PROGRAMW6432": "",
            },
        ],
        indirect=True,
    )
    @pytest.mark.parametrize(
        ("which", "lookups", "expected"),
        [
            pytest.param(
                {"vlc.exe": "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"},
                ["vlc.exe"],
                Path("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"),
                id="PATH lookup success",
            ),
            pytest.param(
                {},
                ["vlc.exe"],
                None,
                id="no fallback paths",
            ),
        ],
        indirect=["which"],
    )
    def test_win32_no_env_vars(self):
        pass

    @pytest.mark.posix_only()
    @pytest.mark.usefixtures("_fakehome")
    @pytest.mark.parametrize("_fakehome", ["/Users/fake"], indirect=True)
    @pytest.mark.parametrize(
        ("which", "lookups", "expected"),
        [
            pytest.param(
                {"vlc": "/usr/bin/vlc"},
                ["VLC", "vlc"],
                Path("/usr/bin/vlc"),
                id="PATH lookup success",
            ),
            pytest.param(
                {"/Applications/VLC.app/Contents/MacOS/VLC": "/Applications/VLC.app/Contents/MacOS/VLC"},
                [
                    "VLC",
                    "vlc",
                    "/Applications/VLC.app/Contents/MacOS/VLC",
                ],
                Path("/Applications/VLC.app/Contents/MacOS/VLC"),
                id="fallback paths lookup success",
            ),
            pytest.param(
                {},
                [
                    "VLC",
                    "vlc",
                    "/Applications/VLC.app/Contents/MacOS/VLC",
                    "/Applications/VLC.app/Contents/MacOS/vlc",
                    "/Users/fake/Applications/VLC.app/Contents/MacOS/VLC",
                    "/Users/fake/Applications/VLC.app/Contents/MacOS/vlc",
                ],
                None,
                id="lookup failure",
            ),
        ],
        indirect=["which"],
    )
    def test_darwin(self):
        pass

    @pytest.mark.posix_only()
    @pytest.mark.parametrize(
        ("which", "lookups", "expected"),
        [
            pytest.param(
                {"vlc": "/usr/bin/vlc"},
                ["vlc"],
                Path("/usr/bin/vlc"),
                id="lookup success",
            ),
            pytest.param(
                {},
                ["vlc"],
                None,
                id="lookup failure",
            ),
        ],
        indirect=["which"],
    )
    def test_other(self):
        pass