test(playout): use snapshot testing tool (#2115)

This commit is contained in:
Jonas L 2022-09-09 16:57:22 +02:00 committed by GitHub
parent 11c55d26dc
commit 36264ed4a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 229 additions and 224 deletions

View File

@ -22,6 +22,7 @@ repos:
- id: mixed-line-ending - id: mixed-line-ending
args: [--fix=lf] args: [--fix=lf]
- id: trailing-whitespace - id: trailing-whitespace
exclude: \.ambr$
- id: name-tests-test - id: name-tests-test
# TODO: Remove once the django api uses pytest # TODO: Remove once the django api uses pytest

View File

@ -37,6 +37,7 @@ setup(
"dev": [ "dev": [
"distro", "distro",
"requests-mock", "requests-mock",
"syrupy",
"types-python-dateutil", "types-python-dateutil",
"types-requests", "types-requests",
], ],

View File

@ -4,8 +4,3 @@ fixtures_path = Path(__file__).parent
icecast_stats = fixtures_path / "icecast_stats.xml" icecast_stats = fixtures_path / "icecast_stats.xml"
shoutcast_admin = fixtures_path / "shoutcast_admin.xml" shoutcast_admin = fixtures_path / "shoutcast_admin.xml"
entrypoint_1_1 = fixtures_path / "entrypoint-1.1.liq"
entrypoint_1_1_snapshot = entrypoint_1_1.read_text(encoding="utf-8")
entrypoint_1_4 = fixtures_path / "entrypoint-1.4.liq"
entrypoint_1_4_snapshot = entrypoint_1_4.read_text(encoding="utf-8")

View File

@ -1,106 +0,0 @@
# THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT!
###########################################################
# The ignore() lines are to squash unused variable warnings
# Inputs
master_live_stream_mp = "main"
master_live_stream_port = 8001
dj_live_stream_mp = "show"
dj_live_stream_port = 8002
# Output s1
s1_enable = true
s1_output = "icecast"
s1_host = "localhost"
s1_port = 8000
s1_mount = "main"
s1_user = "source"
s1_pass = "hackme"
s1_channels = "stereo"
s1_type = "ogg"
s1_bitrate = 256
s1_name = "LibreTime!"
s1_description = "LibreTime Radio! Stream #1"
s1_genre = "various"
s1_url = "https://libretime.org"
# Output s2
s2_enable = true
s2_output = "icecast"
s2_host = "localhost"
s2_port = 8000
s2_mount = "second"
s2_user = "source"
s2_pass = "hackme"
s2_channels = "stereo"
s2_type = "mp3"
s2_bitrate = 256
s2_name = ""
s2_description = ""
s2_genre = ""
s2_url = ""
# Output s3
s3_enable = false
s3_output = "icecast"
s3_host = "localhost"
s3_port = 8000
s3_mount = ""
s3_user = "source"
s3_pass = ""
s3_channels = "stereo"
s3_type = "ogg"
s3_bitrate = 256
s3_name = ""
s3_description = ""
s3_genre = ""
s3_url = ""
# Output s4
s4_enable = false
s4_output = "icecast"
s4_host = "localhost"
s4_port = 8000
s4_mount = ""
s4_user = "source"
s4_pass = ""
s4_channels = "stereo"
s4_type = "ogg"
s4_bitrate = 256
s4_name = ""
s4_description = ""
s4_genre = ""
s4_url = ""
icecast_vorbis_metadata = false
# System output
output_sound_device = false
output_sound_device_type = "alsa"
# Settings
auth_path = "/fake/liquidsoap_auth.py"
set("log.file.path", "/var/log/radio.log")
set("server.telnet", true)
set("server.telnet.bind_addr", "127.0.0.1")
set("server.telnet.port", 1234)
set("harbor.bind_addr", "0.0.0.0")
station_name = ref "LibreTime"
off_air_meta = ref "LibreTime - offline"
stream_metadata_type = ref 0
default_dj_fade = ref 0.0
%include "/fake/1.1/ls_script.liq"

View File

@ -1,106 +0,0 @@
# THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT!
###########################################################
# The ignore() lines are to squash unused variable warnings
# Inputs
master_live_stream_mp = "main"
master_live_stream_port = 8001
dj_live_stream_mp = "show"
dj_live_stream_port = 8002
# Output s1
s1_enable = true
s1_output = "icecast"
s1_host = "localhost"
s1_port = 8000
s1_mount = "main"
s1_user = "source"
s1_pass = "hackme"
s1_channels = "stereo"
s1_type = "ogg"
s1_bitrate = 256
s1_name = "LibreTime!"
s1_description = "LibreTime Radio! Stream #1"
s1_genre = "various"
s1_url = "https://libretime.org"
# Output s2
s2_enable = true
s2_output = "icecast"
s2_host = "localhost"
s2_port = 8000
s2_mount = "second"
s2_user = "source"
s2_pass = "hackme"
s2_channels = "stereo"
s2_type = "mp3"
s2_bitrate = 256
s2_name = ""
s2_description = ""
s2_genre = ""
s2_url = ""
# Output s3
s3_enable = false
s3_output = "icecast"
s3_host = "localhost"
s3_port = 8000
s3_mount = ""
s3_user = "source"
s3_pass = ""
s3_channels = "stereo"
s3_type = "ogg"
s3_bitrate = 256
s3_name = ""
s3_description = ""
s3_genre = ""
s3_url = ""
# Output s4
s4_enable = false
s4_output = "icecast"
s4_host = "localhost"
s4_port = 8000
s4_mount = ""
s4_user = "source"
s4_pass = ""
s4_channels = "stereo"
s4_type = "ogg"
s4_bitrate = 256
s4_name = ""
s4_description = ""
s4_genre = ""
s4_url = ""
icecast_vorbis_metadata = false
# System output
output_sound_device = false
output_sound_device_type = "alsa"
# Settings
auth_path = "/fake/liquidsoap_auth.py"
set("log.file.path", "/var/log/radio.log")
set("server.telnet", true)
set("server.telnet.bind_addr", "127.0.0.1")
set("server.telnet.port", 1234)
set("harbor.bind_addrs", ["0.0.0.0"])
station_name = ref "LibreTime"
off_air_meta = ref "LibreTime - offline"
stream_metadata_type = ref 0
default_dj_fade = ref 0.0
%include "/fake/1.4/ls_script.liq"

View File

@ -0,0 +1,222 @@
# name: test_generate_entrypoint[1.1]
'''
# THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT!
###########################################################
# The ignore() lines are to squash unused variable warnings
# Inputs
master_live_stream_mp = "main"
master_live_stream_port = 8001
dj_live_stream_mp = "show"
dj_live_stream_port = 8002
# Output s1
s1_enable = true
s1_output = "icecast"
s1_host = "localhost"
s1_port = 8000
s1_mount = "main"
s1_user = "source"
s1_pass = "hackme"
s1_channels = "stereo"
s1_type = "ogg"
s1_bitrate = 256
s1_name = "LibreTime!"
s1_description = "LibreTime Radio! Stream #1"
s1_genre = "various"
s1_url = "https://libretime.org"
# Output s2
s2_enable = true
s2_output = "icecast"
s2_host = "localhost"
s2_port = 8000
s2_mount = "second"
s2_user = "source"
s2_pass = "hackme"
s2_channels = "stereo"
s2_type = "mp3"
s2_bitrate = 256
s2_name = ""
s2_description = ""
s2_genre = ""
s2_url = ""
# Output s3
s3_enable = false
s3_output = "icecast"
s3_host = "localhost"
s3_port = 8000
s3_mount = ""
s3_user = "source"
s3_pass = ""
s3_channels = "stereo"
s3_type = "ogg"
s3_bitrate = 256
s3_name = ""
s3_description = ""
s3_genre = ""
s3_url = ""
# Output s4
s4_enable = false
s4_output = "icecast"
s4_host = "localhost"
s4_port = 8000
s4_mount = ""
s4_user = "source"
s4_pass = ""
s4_channels = "stereo"
s4_type = "ogg"
s4_bitrate = 256
s4_name = ""
s4_description = ""
s4_genre = ""
s4_url = ""
icecast_vorbis_metadata = false
# System output
output_sound_device = false
output_sound_device_type = "alsa"
# Settings
auth_path = "/fake/liquidsoap_auth.py"
set("log.file.path", "/var/log/radio.log")
set("server.telnet", true)
set("server.telnet.bind_addr", "127.0.0.1")
set("server.telnet.port", 1234)
set("harbor.bind_addr", "0.0.0.0")
station_name = ref "LibreTime"
off_air_meta = ref "LibreTime - offline"
stream_metadata_type = ref 0
default_dj_fade = ref 0.0
%include "/fake/1.1/ls_script.liq"
'''
# ---
# name: test_generate_entrypoint[1.4]
'''
# THIS FILE IS AUTO GENERATED. PLEASE DO NOT EDIT!
###########################################################
# The ignore() lines are to squash unused variable warnings
# Inputs
master_live_stream_mp = "main"
master_live_stream_port = 8001
dj_live_stream_mp = "show"
dj_live_stream_port = 8002
# Output s1
s1_enable = true
s1_output = "icecast"
s1_host = "localhost"
s1_port = 8000
s1_mount = "main"
s1_user = "source"
s1_pass = "hackme"
s1_channels = "stereo"
s1_type = "ogg"
s1_bitrate = 256
s1_name = "LibreTime!"
s1_description = "LibreTime Radio! Stream #1"
s1_genre = "various"
s1_url = "https://libretime.org"
# Output s2
s2_enable = true
s2_output = "icecast"
s2_host = "localhost"
s2_port = 8000
s2_mount = "second"
s2_user = "source"
s2_pass = "hackme"
s2_channels = "stereo"
s2_type = "mp3"
s2_bitrate = 256
s2_name = ""
s2_description = ""
s2_genre = ""
s2_url = ""
# Output s3
s3_enable = false
s3_output = "icecast"
s3_host = "localhost"
s3_port = 8000
s3_mount = ""
s3_user = "source"
s3_pass = ""
s3_channels = "stereo"
s3_type = "ogg"
s3_bitrate = 256
s3_name = ""
s3_description = ""
s3_genre = ""
s3_url = ""
# Output s4
s4_enable = false
s4_output = "icecast"
s4_host = "localhost"
s4_port = 8000
s4_mount = ""
s4_user = "source"
s4_pass = ""
s4_channels = "stereo"
s4_type = "ogg"
s4_bitrate = 256
s4_name = ""
s4_description = ""
s4_genre = ""
s4_url = ""
icecast_vorbis_metadata = false
# System output
output_sound_device = false
output_sound_device_type = "alsa"
# Settings
auth_path = "/fake/liquidsoap_auth.py"
set("log.file.path", "/var/log/radio.log")
set("server.telnet", true)
set("server.telnet.bind_addr", "127.0.0.1")
set("server.telnet.port", 1234)
set("harbor.bind_addrs", ["0.0.0.0"])
station_name = ref "LibreTime"
off_air_meta = ref "LibreTime - offline"
stream_metadata_type = ref 0
default_dj_fade = ref 0.0
%include "/fake/1.4/ls_script.liq"
'''
# ---

View File

@ -7,17 +7,15 @@ from libretime_playout.config import Config
from libretime_playout.liquidsoap.entrypoint import generate_entrypoint from libretime_playout.liquidsoap.entrypoint import generate_entrypoint
from libretime_playout.liquidsoap.models import Info, StreamPreferences from libretime_playout.liquidsoap.models import Info, StreamPreferences
from ..fixtures import entrypoint_1_1_snapshot, entrypoint_1_4_snapshot
@pytest.mark.parametrize( @pytest.mark.parametrize(
"version, expected", "version",
[ [
pytest.param((1, 1, 1), entrypoint_1_1_snapshot, id="snapshot_1.1"), pytest.param((1, 1, 1), id="1.1"),
pytest.param((1, 4, 4), entrypoint_1_4_snapshot, id="snapshot_1.4"), pytest.param((1, 4, 4), id="1.4"),
], ],
) )
def test_generate_entrypoint(tmp_path: Path, config: Config, version, expected): def test_generate_entrypoint(tmp_path: Path, config: Config, version, snapshot):
entrypoint_filepath = tmp_path / "radio.liq" entrypoint_filepath = tmp_path / "radio.liq"
with mock.patch( with mock.patch(
@ -40,4 +38,4 @@ def test_generate_entrypoint(tmp_path: Path, config: Config, version, expected):
) )
found = entrypoint_filepath.read_text(encoding="utf-8") found = entrypoint_filepath.read_text(encoding="utf-8")
assert found == expected assert found == snapshot