Test: post-processors

This commit is contained in:
DarkCat09 2024-05-02 16:00:21 +04:00
parent 38abaa9bba
commit 464b65232b
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

80
backend/test_pp.py Normal file
View file

@ -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()