From 464b65232ba9b10259f16cbb43aeaf93e924f767 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 2 May 2024 16:00:21 +0400 Subject: [PATCH] Test: post-processors --- backend/test_pp.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 backend/test_pp.py diff --git a/backend/test_pp.py b/backend/test_pp.py new file mode 100644 index 0000000..0c95a13 --- /dev/null +++ b/backend/test_pp.py @@ -0,0 +1,80 @@ +from unittest import TestCase + +import os +import subprocess + +from mutagen import mp3 + +import id3pp +import http_pool + + +TEST_MP3 = 'music/test.mp3' + +INFO_BEFORE = { + "filepath": TEST_MP3, + "title": "A Line in the Sand", + "channel": "Linkin Park - Topic", + "playlist": "Album \u2013 The Hunting Party", + "playlist_index": 12, + "release_year": 2015, + "genre": "numetal", +} + +INFO_AFTER = { + **INFO_BEFORE, + "track": "A Line in the Sand", + "artist": "Linkin Park", + "album": "The Hunting Party", + "track_number": 12, +} + + +class TestPostProcessorsOnFakeData(TestCase): + + def setUp(self) -> None: + + http_pool.get() + + def test_infoytpp(self) -> None: + + _, info = id3pp.InfoYouTubePP().run(INFO_BEFORE) + self.assertEqual(info, INFO_AFTER) + + def test_id3(self) -> None: + + try: + if os.path.exists(TEST_MP3): + os.unlink(TEST_MP3) + ret = subprocess.call( + [ + 'ffmpeg', + '-nostdin', + '-f', 'lavfi', + '-i', 'anullsrc=r=44100:cl=mono', + '-t', '1', + '-b:a', '32k', + '-acodec', 'libmp3lame', + TEST_MP3, + ], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + if ret != 0: + raise RuntimeError(f'FFmpeg returned {ret} exit code') + except Exception as err: + self.skipTest(f'Error while writing empty MP3: {err:r}') + + id3pp.ID3TagsPP().run(INFO_AFTER) + + file = mp3.MP3(TEST_MP3) + self.assertEqual(file['TIT2'].text[0], 'A Line in the Sand') + self.assertEqual(file['TPE1'].text[0], 'Linkin Park') + self.assertEqual(file['TALB'].text[0], 'The Hunting Party') + self.assertEqual(file['TDRC'].text[0].get_text(), '2015') + self.assertEqual(file['TRCK'].text[0], '12') + self.assertEqual(file['TCON'].text[0], 'numetal') + + def tearDown(self) -> None: + + http_pool.get().clear()