1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
import pytest |
4
|
|
|
from music_album_creation.tracks_parsing import StringParser |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
@pytest.fixture(scope='module') |
8
|
|
|
def track_durations(): |
9
|
|
|
return ["0:12", "0:38", "0:20", "0:25", "0:10", "0:30", "1:00"] |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@pytest.fixture(scope='module') |
13
|
|
|
def track_timestamps(): |
14
|
|
|
return ["0:00", "0:12", "0:50", "1:10", "1:35", "1:45", "2:15"] |
15
|
|
|
|
16
|
|
|
@pytest.fixture(scope='module') |
17
|
|
|
def delimeters1(): |
18
|
|
|
return ['. ', ' - ', '. ', ' - ', '. '] |
19
|
|
|
|
20
|
|
|
@pytest.fixture(scope='module') |
21
|
|
|
def track_names(): |
22
|
|
|
return ["Lopan", "Hesher", "Uber en Colère", "Delta-v" ,"Bowie’s Last Breath", "I’m Not A Real Indian (But I Play One On TV)", '24'] |
23
|
|
|
|
24
|
|
|
@pytest.fixture(scope='module') |
25
|
|
|
def delimeters2(): |
26
|
|
|
return [' ', ' - ', ' - ', ' - ', ' - '] |
27
|
|
|
|
28
|
|
|
def build_string(dels1, names, dels2, hhmmss_list): |
29
|
|
|
return '\n'.join(['{}{}{}{}{}'.format(i+1, dels1[i % len(dels1)], x[0], dels2[i % len(dels2)], x[1]) for i, x in enumerate(zip(names, hhmmss_list))]) |
30
|
|
|
|
31
|
|
|
@pytest.fixture(scope='module') |
32
|
|
|
def timestamps_info_string(delimeters1, track_names, delimeters2, track_timestamps): |
33
|
|
|
return build_string(delimeters1, track_names, delimeters2, track_timestamps) |
34
|
|
|
|
35
|
|
|
@pytest.fixture(scope='module') |
36
|
|
|
def durations_info_string(delimeters1, track_names, delimeters2, track_durations): |
37
|
|
|
return build_string(delimeters1, track_names, delimeters2, track_durations) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
class TestSplitters: |
42
|
|
|
@pytest.mark.parametrize("track_line, name, time", [ |
43
|
|
|
("01. A track - 0:00", "A track", "0:00"), |
44
|
|
|
("1 A track - 0:00", "A track", "0:00"), |
45
|
|
|
("01 A track - 0:00", "A track", "0:00"), |
46
|
|
|
("01. A track - 0:00", "A track", "0:00"), |
47
|
|
|
("3. Uber en Colère - 9:45", "Uber en Colère", '9:45'), |
48
|
|
|
("3. Delta-v - 20:04", 'Delta-v', '20:04'), |
49
|
|
|
("3. Delta-v - 0:00", 'Delta-v', '0:00'), |
50
|
|
|
("3 Delta-v - 20:04", 'Delta-v', '20:04'), |
51
|
|
|
("3 Delta-v - 0:00", 'Delta-v', '0:00'), |
52
|
|
|
]) |
53
|
|
|
def test_tracks_line_parsing(self, track_line, name, time): |
54
|
|
|
assert StringParser._parse_track_line(track_line) == [name, time] |
55
|
|
|
|
56
|
|
|
@pytest.mark.parametrize("video_title, artist, album, year", [ |
57
|
|
|
("Alber Jupiter - We Are Just Floating In Space (2019) (New Full Album)", "Alber Jupiter", "We Are Just Floating In Space", "2019"), |
58
|
|
|
("My Artist - My Album (2001)", "My Artist", "My Album", "2001"), |
59
|
|
|
("Composer A - Metro 2033 (2010)", "Composer A", "Metro 2033", "2010"), |
60
|
|
|
]) |
61
|
|
|
def test_youtube_video_title_parsing(self, video_title, artist, album, year): |
62
|
|
|
assert StringParser.parse_album_info(video_title) == {'artist': artist, 'album': album, 'year': year} |
63
|
|
|
|
64
|
|
|
@pytest.mark.parametrize("tracks_string", [ |
65
|
|
|
('1. Virtual Funeral - 0:00\n2. Macedonian Lines - 6:46\n3. Melancholy Sadie - 11:30\n4. Bowie’s Last Breath - 16:19\n5. I’m Not A Real Indian (But I Play One On TV) - 20:20\n6. I Make Weird Choices - 23:44'), |
66
|
|
|
('1. Virtual Funeral - 0:00\n2. Macedonian Lines - 6:46\n3. Melancholy Sadie - 11:30\n4. Bowie’s Last Breath - 16:19\n5. I’m Not A Real Indian (But I Play One On TV) - 20:20\n6. I Make Weird Choices - 23:44\n'), |
67
|
|
|
('1 Virtual Funeral - 0:00\n2 Macedonian Lines - 6:46\n3 Melancholy Sadie - 11:30\n4 Bowie’s Last Breath - 16:19\n5 I’m Not A Real Indian (But I Play One On TV) - 20:20\n6 I Make Weird Choices - 23:44'), |
68
|
|
|
('1 Virtual Funeral - 0:00\n2 Macedonian Lines - 6:46\n3 Melancholy Sadie - 11:30\n4 Bowie’s Last Breath - 16:19\n5 I’m Not A Real Indian (But I Play One On TV) - 20:20\n6 I Make Weird Choices - 23:44\n'), |
69
|
|
|
]) |
70
|
|
|
def test_tracks_string(self, tracks_string): |
71
|
|
|
assert StringParser.parse_hhmmss_string(tracks_string) == [['Virtual Funeral', '0:00'], |
72
|
|
|
['Macedonian Lines', '6:46'], |
73
|
|
|
['Melancholy Sadie', '11:30'], |
74
|
|
|
['Bowie’s Last Breath', '16:19'], |
75
|
|
|
["I’m Not A Real Indian (But I Play One On TV)", '20:20'], |
76
|
|
|
['I Make Weird Choices', '23:44']] |
77
|
|
|
|
78
|
|
|
@pytest.mark.parametrize("track_file, track_number, track_name", [ |
79
|
|
|
("Thievery Corporation/The Cosmic Game (2005)/14 - The Supreme Illusion (Feat- Gunjan).mp3", '14', 'The Supreme Illusion (Feat- Gunjan)'), |
80
|
|
|
("Monster Magnet/Dopes to Infinity (Single) 1995/02 - Forbidden Planet.mp3", '02', 'Forbidden Planet'), |
81
|
|
|
("Monster Magnet/Greatest Hits 2003/02 - Medicine.mp3", '02', 'Medicine'), |
82
|
|
|
("Porcupine Tree/On The Sunday Of Life/07 - Message Form A Self-Destructing Turnip.mp3", '07', 'Message Form A Self-Destructing Turnip'), |
83
|
|
|
("Rotor/Rotor 2001/06 A Madrugada.mp3", '06', 'A Madrugada'), |
84
|
|
|
("Karma To Burn/Arc Stanton 2014/02 56.mp3", '02', '56'), |
85
|
|
|
("Cesaria Evora/Cesaria Evora - Cabo Verde/06-Mar e Morada De Sodade.mp3", '06', 'Mar e Morada De Sodade'), |
86
|
|
|
("Sungrazer/Sungrazer - Mirador (2011)/06.Mirador.mp3", '06', 'Mirador'), |
87
|
|
|
("SadhuS (The Smoking Community)/Sadhus The smoking community/06 Bampoola.mp3", '06', 'Bampoola'), |
88
|
|
|
("Remember Me - Original Soundtrack (2013)/12. The Ego Room.mp3", '12', 'The Ego Room'), |
89
|
|
|
("Queens of the Stone Age/Like a Clockwork/02 I Sat By the Ocean.mp3", '02', 'I Sat By the Ocean'), |
90
|
|
|
("Ill Nino/[2010] Dead New World/05 - Bleed Like You.mp3", '05', 'Bleed Like You'), |
91
|
|
|
( |
92
|
|
|
"Urban Dance Squad/Urban Dance Squad - Life 'n Perspectives of a Genuine Crossover/03. Life 'n Perspectives I.mp3", '03', "Life 'n Perspectives I"), |
93
|
|
|
("Cesaria Evora/Cesaria Evora - Cafe Atlantico/06-Carnaval De Sao Vicente.mp3", '06', 'Carnaval De Sao Vicente'), |
94
|
|
|
("Dala Sun/Sala Dun (2010)/04 - Fuck It Away.mp3", '04', 'Fuck It Away'), |
95
|
|
|
("In This Moment/Blood (2012)/01- Rise With Me.mp3", '01', 'Rise With Me'), |
96
|
|
|
]) |
97
|
|
|
def test_mp3_files_parsing(self, track_file, track_number, track_name): |
98
|
|
|
assert StringParser.parse_track_number_n_name(track_file) == {'track_number': track_number, 'track_name': track_name} |
99
|
|
|
|
100
|
|
|
def test_parsing_timestamps_tracks_info(self, timestamps_info_string, track_names, track_timestamps): |
101
|
|
|
assert StringParser.parse_hhmmss_string(timestamps_info_string) == [[x, y] for x, y in zip(track_names, track_timestamps)] |
102
|
|
|
|
103
|
|
|
def test_parsing_durations_tracks_info(self, durations_info_string, track_names, track_durations): |
104
|
|
|
assert StringParser.parse_hhmmss_string(durations_info_string) == [[x, y] for x, y in zip(track_names, track_durations)] |
105
|
|
|
|
106
|
|
|
def test_durations_list_converion(self, track_durations, track_timestamps): |
107
|
|
|
assert [_[1] for _ in StringParser.duration_data_to_timestamp_data([['a', x] for x in track_durations])] == track_timestamps |
108
|
|
|
|