Debian Codegraph @

test/util/test_lyrics.py

raw
1 import textwrap
2
3 from beets.library import Item
4 from beets.util.lyrics import Lyrics
5
6
7 class TestLyrics:
8 def test_instrumental_lyrics(self):
9 lyrics = Lyrics(
10 "[Instrumental]", "lrclib", url="https://lrclib.net/api/1"
11 )
12
13 assert lyrics.full_text == ""
14 assert lyrics.instrumental
15 assert lyrics.backend == "lrclib"
16 assert lyrics.url == "https://lrclib.net/api/1"
17 assert lyrics.language is None
18 assert lyrics.translation_language is None
19
20 def test_from_item_without_lyrics(self):
21 item = Item(lyrics=None)
22
23 lyrics = Lyrics.from_item(item)
24
25 assert lyrics.text == ""
26 assert not lyrics.synced
27 assert lyrics.full_text == ""
28 assert lyrics.sylt == []
29 assert lyrics.text_lines == []
30
31 def test_from_legacy_text(self, is_importable):
32 text = textwrap.dedent("""
33 [00:00.00] Some synced lyrics / Quelques paroles synchronisées
34 [00:00.50]
35 [00:01.00] Some more synced lyrics / Quelques paroles plus synchronisées
36
37 Source: https://lrclib.net/api/1/""")
38
39 lyrics = Lyrics.from_legacy_text(text)
40
41 assert lyrics.full_text == textwrap.dedent(
42 """
43 [00:00.00] Some synced lyrics / Quelques paroles synchronisées
44 [00:00.50]
45 [00:01.00] Some more synced lyrics / Quelques paroles plus synchronisées"""
46 )
47 assert lyrics.backend == "lrclib"
48 assert lyrics.url == "https://lrclib.net/api/1/"
49 langdetect_available = is_importable("langdetect")
50 assert lyrics.language == ("EN" if langdetect_available else None)
51 assert lyrics.translation_language == (
52 "FR" if langdetect_available else None
53 )
54 assert not lyrics.instrumental
55
56 def test_timestamp_precision_and_sylt(self):
57 text = textwrap.dedent("""
58 [00:00.05] Centisecond line
59 [00:01.50] Two decimals
60 [00:02.123] Three decimals
61 [01:00.005] Five milliseconds
62 """).strip()
63 lyrics = Lyrics(text)
64
65 assert lyrics.synced
66 assert lyrics.timestamps == [
67 "[00:00.05]",
68 "[00:01.50]",
69 "[00:02.123]",
70 "[01:00.005]",
71 ]
72 assert lyrics.text_lines == [
73 "Centisecond line",
74 "Two decimals",
75 "Three decimals",
76 "Five milliseconds",
77 ]
78 assert lyrics.sylt == [
79 ("Centisecond line", 50),
80 ("Two decimals", 1500),
81 ("Three decimals", 2123),
82 ("Five milliseconds", 60005),
83 ]