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
|
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from streamlink.utils.path import resolve_executable
if TYPE_CHECKING:
from pathlib import Path
RESOLVE_EXECUTABLE_LOOKUPS = {
"foo": "/usr/bin/foo",
"/usr/bin/foo": "/usr/bin/foo",
"/other/bar": "/other/bar",
}
@pytest.mark.parametrize(
("custom", "names", "fallbacks", "expected"),
[
pytest.param(
None,
[],
[],
None,
id="Empty",
),
pytest.param(
"foo",
[],
[],
"/usr/bin/foo",
id="Custom executable success",
),
pytest.param(
"bar",
[],
[],
None,
id="Custom executable failure",
),
pytest.param(
"bar",
["foo"],
["/usr/bin/foo"],
None,
id="Custom executable overrides names+fallbacks",
),
pytest.param(
None,
["bar", "foo"],
[],
"/usr/bin/foo",
id="Default names success",
),
pytest.param(
None,
["bar", "baz"],
[],
None,
id="Default names failure",
),
pytest.param(
None,
[],
["/usr/bin/unknown", "/other/bar"],
"/other/bar",
id="Fallbacks success",
),
pytest.param(
None,
[],
["/usr/bin/unknown", "/other/baz"],
None,
id="Fallbacks failure",
),
pytest.param(
None,
["bar", "foo"],
["/usr/bin/bar", "/other/baz"],
"/usr/bin/foo",
id="Successful name lookup with fallbacks",
),
pytest.param(
None,
["bar", "baz"],
["/usr/bin/bar", "/other/bar"],
"/other/bar",
id="Unsuccessful name lookup with successful fallbacks",
),
pytest.param(
None,
["bar", "baz"],
["/usr/bin/unknown", "/other/baz"],
None,
id="Failure",
),
],
)
def test_resolve_executable(
monkeypatch: pytest.MonkeyPatch,
custom: str | None,
names: list[str] | None,
fallbacks: list[str | Path] | None,
expected: str,
):
monkeypatch.setattr("streamlink.utils.path.which", RESOLVE_EXECUTABLE_LOOKUPS.get)
assert resolve_executable(custom, names, fallbacks) == expected
|