diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e9deeae5..a0e77796a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,7 @@ repos: - id: mixed-line-ending args: [--fix=lf] - id: trailing-whitespace + exclude: \.ambr$ - id: name-tests-test # TODO: Remove once the django api uses pytest diff --git a/playout/setup.py b/playout/setup.py index 24f8c2289..a416a8b57 100644 --- a/playout/setup.py +++ b/playout/setup.py @@ -37,6 +37,7 @@ setup( "dev": [ "distro", "requests-mock", + "syrupy", "types-python-dateutil", "types-requests", ], diff --git a/playout/tests/fixtures/__init__.py b/playout/tests/fixtures/__init__.py index d0f5ebe60..53d0a76d2 100644 --- a/playout/tests/fixtures/__init__.py +++ b/playout/tests/fixtures/__init__.py @@ -4,8 +4,3 @@ fixtures_path = Path(__file__).parent icecast_stats = fixtures_path / "icecast_stats.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") diff --git a/playout/tests/fixtures/entrypoint-1.1.liq b/playout/tests/fixtures/entrypoint-1.1.liq deleted file mode 100644 index 5a794672b..000000000 --- a/playout/tests/fixtures/entrypoint-1.1.liq +++ /dev/null @@ -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" diff --git a/playout/tests/fixtures/entrypoint-1.4.liq b/playout/tests/fixtures/entrypoint-1.4.liq deleted file mode 100644 index c3029db0f..000000000 --- a/playout/tests/fixtures/entrypoint-1.4.liq +++ /dev/null @@ -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" diff --git a/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr b/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr new file mode 100644 index 000000000..fb0ffce35 --- /dev/null +++ b/playout/tests/liquidsoap/__snapshots__/entrypoint_test.ambr @@ -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" + + ''' +# --- diff --git a/playout/tests/liquidsoap/entrypoint_test.py b/playout/tests/liquidsoap/entrypoint_test.py index 1c2ab9d10..1d79f1437 100644 --- a/playout/tests/liquidsoap/entrypoint_test.py +++ b/playout/tests/liquidsoap/entrypoint_test.py @@ -7,17 +7,15 @@ from libretime_playout.config import Config from libretime_playout.liquidsoap.entrypoint import generate_entrypoint from libretime_playout.liquidsoap.models import Info, StreamPreferences -from ..fixtures import entrypoint_1_1_snapshot, entrypoint_1_4_snapshot - @pytest.mark.parametrize( - "version, expected", + "version", [ - pytest.param((1, 1, 1), entrypoint_1_1_snapshot, id="snapshot_1.1"), - pytest.param((1, 4, 4), entrypoint_1_4_snapshot, id="snapshot_1.4"), + pytest.param((1, 1, 1), id="1.1"), + 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" 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") - assert found == expected + assert found == snapshot