2022-08-10 17:33:22 +02:00
|
|
|
from pathlib import Path
|
2023-05-29 10:46:31 +02:00
|
|
|
from subprocess import CalledProcessError, check_call, check_output
|
2022-08-10 17:33:22 +02:00
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from libretime_playout.config import Config
|
|
|
|
from libretime_playout.liquidsoap.entrypoint import generate_entrypoint
|
|
|
|
from libretime_playout.liquidsoap.models import Info, StreamPreferences
|
2023-02-26 23:34:28 +01:00
|
|
|
from libretime_playout.liquidsoap.version import get_liquidsoap_version
|
2022-08-10 17:33:22 +02:00
|
|
|
|
2023-02-26 23:34:28 +01:00
|
|
|
from .conftest import LIQ_VERSION
|
2023-05-29 10:46:31 +02:00
|
|
|
from .fixtures import TEST_STREAM_CONFIGS, make_config_with_stream
|
2023-02-25 18:52:22 +01:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2022-09-09 16:57:22 +02:00
|
|
|
"version",
|
2022-09-09 20:59:37 +02:00
|
|
|
[pytest.param((1, 4, 4), id="1.4")],
|
2022-08-10 17:33:22 +02:00
|
|
|
)
|
2023-02-25 18:52:22 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"stream_config",
|
|
|
|
TEST_STREAM_CONFIGS,
|
|
|
|
)
|
2024-02-08 20:29:10 +01:00
|
|
|
def test_generate_entrypoint(
|
|
|
|
stream_config: Config,
|
|
|
|
stream_preferences: StreamPreferences,
|
|
|
|
version,
|
|
|
|
snapshot,
|
|
|
|
):
|
2022-08-10 17:33:22 +02:00
|
|
|
with mock.patch(
|
|
|
|
"libretime_playout.liquidsoap.entrypoint.here",
|
|
|
|
Path("/fake"),
|
|
|
|
):
|
2023-03-01 17:59:27 +01:00
|
|
|
found = generate_entrypoint(
|
2022-08-10 17:33:22 +02:00
|
|
|
log_filepath=Path("/var/log/radio.log"),
|
2023-02-25 18:52:22 +01:00
|
|
|
config=stream_config,
|
2024-02-08 20:29:10 +01:00
|
|
|
preferences=stream_preferences,
|
2022-08-10 17:33:22 +02:00
|
|
|
info=Info(
|
|
|
|
station_name="LibreTime",
|
|
|
|
),
|
|
|
|
version=version,
|
|
|
|
)
|
|
|
|
|
2022-09-09 16:57:22 +02:00
|
|
|
assert found == snapshot
|
2023-02-26 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
|
|
LIQ_VERSION >= (2, 0, 0),
|
|
|
|
reason="unsupported liquidsoap >= 2.0.0",
|
|
|
|
)
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"stream_config",
|
|
|
|
TEST_STREAM_CONFIGS,
|
|
|
|
)
|
2024-02-08 20:29:10 +01:00
|
|
|
def test_liquidsoap_syntax(
|
|
|
|
tmp_path: Path,
|
|
|
|
stream_config: Config,
|
|
|
|
stream_preferences: StreamPreferences,
|
|
|
|
):
|
2023-02-26 23:34:28 +01:00
|
|
|
entrypoint_filepath = tmp_path / "radio.liq"
|
|
|
|
log_filepath = tmp_path / "radio.log"
|
|
|
|
|
2023-03-01 17:59:27 +01:00
|
|
|
entrypoint_filepath.write_text(
|
|
|
|
generate_entrypoint(
|
|
|
|
log_filepath=log_filepath,
|
|
|
|
config=stream_config,
|
2024-02-08 20:29:10 +01:00
|
|
|
preferences=stream_preferences,
|
2023-03-01 17:59:27 +01:00
|
|
|
info=Info(
|
|
|
|
station_name="LibreTime",
|
|
|
|
),
|
|
|
|
version=get_liquidsoap_version(),
|
2023-02-26 23:34:28 +01:00
|
|
|
),
|
2023-03-01 17:59:27 +01:00
|
|
|
encoding="utf-8",
|
2023-02-26 23:34:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
check_call(["liquidsoap", "--check", str(entrypoint_filepath)])
|
2023-05-29 10:46:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
|
|
LIQ_VERSION >= (2, 0, 0),
|
|
|
|
reason="unsupported liquidsoap >= 2.0.0",
|
|
|
|
)
|
2024-02-08 20:29:10 +01:00
|
|
|
def test_liquidsoap_unsupported_output_aac(
|
|
|
|
tmp_path: Path,
|
|
|
|
stream_preferences: StreamPreferences,
|
|
|
|
):
|
2023-05-29 10:46:31 +02:00
|
|
|
entrypoint_filepath = tmp_path / "radio.liq"
|
|
|
|
log_filepath = tmp_path / "radio.log"
|
|
|
|
|
|
|
|
entrypoint_filepath.write_text(
|
|
|
|
generate_entrypoint(
|
|
|
|
log_filepath=log_filepath,
|
|
|
|
config=make_config_with_stream(
|
|
|
|
outputs={
|
|
|
|
"icecast": [
|
|
|
|
{
|
|
|
|
"enabled": True,
|
|
|
|
"mount": "main.aac",
|
|
|
|
"source_password": "hackme",
|
|
|
|
"audio": {"format": "aac", "bitrate": 128},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
2024-02-08 20:29:10 +01:00
|
|
|
preferences=stream_preferences,
|
2023-05-29 10:46:31 +02:00
|
|
|
info=Info(
|
|
|
|
station_name="LibreTime",
|
|
|
|
),
|
|
|
|
version=get_liquidsoap_version(),
|
|
|
|
),
|
|
|
|
encoding="utf-8",
|
|
|
|
)
|
|
|
|
|
|
|
|
with pytest.raises(CalledProcessError) as exception:
|
|
|
|
check_output(["liquidsoap", "--check", str(entrypoint_filepath)])
|
|
|
|
assert b"You must be missing an optional dependency." in exception.value.stdout
|