forked from quodlibet/quodlibet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_qltk_lyrics.py
72 lines (58 loc) · 2.1 KB
/
test_qltk_lyrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import os
from senf import fsnative
import quodlibet.config
from quodlibet.formats import AudioFile
from quodlibet.formats.mp3 import MP3File
from quodlibet.library import SongLibrary
from quodlibet.qltk.lyrics import LyricsPane
from tests import TestCase, init_fake_app, destroy_fake_app, get_data_path
from tests.helper import get_temp_copy
LYRICS = "foobär...\nMore cowbell!©"
def AF(*args, **kwargs):
a = AudioFile(*args, **kwargs)
a.sanitize()
return a
class TLyricsPane(TestCase):
def setUp(self):
quodlibet.config.init()
init_fake_app()
self.pane = None
self.library = SongLibrary()
def tearDown(self):
destroy_fake_app()
self.library.destroy()
quodlibet.config.quit()
if self.pane:
self.pane.destroy()
def test_construction(self):
af = AF({"~filename": fsnative("/dev/null")})
self.pane = LyricsPane(af)
def test_save_lyrics(self):
af = self.temp_mp3()
self.pane = LyricsPane(af)
self.pane._save_lyrics(af, LYRICS)
self.assertEqual(af("~lyrics"), LYRICS)
def test_save_encoded_lyrics(self):
af = self.temp_mp3()
self.pane = LyricsPane(af)
self.pane._save_lyrics(af, LYRICS)
self.assertEqual(af("~lyrics"), LYRICS)
def test_save_lyrics_deletes_lyric_file(self):
af = self.temp_mp3()
lf_name = af.lyric_filename
os.makedirs(os.path.dirname(lf_name))
with open(lf_name, "wb") as f:
f.write(LYRICS.encode("utf-8"))
self.assertTrue(os.path.exists(lf_name))
self.pane = LyricsPane(af)
self.pane._save_lyrics(af, LYRICS)
self.assertFalse(os.path.exists(lf_name))
def temp_mp3(self):
name = get_temp_copy(get_data_path("silence-44-s.mp3"))
af = MP3File(name)
af.sanitize()
return af