-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_spotify_import.py
56 lines (47 loc) · 2.13 KB
/
test_spotify_import.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
from spotify_import import replace_bad_words, dict_get, scoped, divide_tracks_into_chunks
def test_replace_bad_words():
pairs = (
('Rodeo - feat. Nas', 'Rodeo - Nas'),
('INDUSTRY BABY (feat. Jack Harlow)', 'INDUSTRY BABY (Jack Harlow)'),
('Wild Thoughts (feat. Rihanna & Bryson Tiller)', 'Wild Thoughts (Rihanna Bryson Tiller)'),
('Ray Ban Vision ft. Cyhi Da Prynce', 'Ray Ban Vision Cyhi Da Prynce'),
('Delta - Original Mix', 'Delta'),
('This Nation (Original Mix)', 'This Nation'),
)
for (bad, good) in pairs:
assert replace_bad_words(bad) == good
def test_scoped():
assert scoped(['first', 'second']) == 'first second'
assert scoped(['third']) == 'third'
assert scoped(['foo bar baz', 'another', 'foo', 'bar']) == 'foo bar baz another foo bar'
def test_dict_get():
dict_1 = {'first': {'second': {'third': 'value'}}}
assert dict_get(dict_1, 'first', 'second', 'third') == 'value'
dict_2 = {'first': 'thing'}
assert dict_get(dict_2, 'first') == 'thing'
dict_3 = {
'other': 'stuff',
'maybe': ['a', 'list!'],
'first': {
'could be': 'more stuff',
'second': {
'irrelevant': 'value',
'third': 'value',
}
}
}
assert dict_get(dict_3, 'first', 'second', 'third') == 'value'
assert dict_get(dict_3, 'first', 'second', 'wrong') is None
assert dict_get(dict_3, 'first', 'second', 'wrong', 'house') is None
assert dict_get(dict_3, 'first', 'second', 'third', 'fourth') is None
assert dict_get({}, 'first') is None
assert dict_get({}) is None
def test_divide_tracks_into_chunks():
tracks = list(range(200))
assert divide_tracks_into_chunks(tracks) == [list(range(100)), list(range(100, 200))]
tracks = list(range(199))
assert divide_tracks_into_chunks(tracks) == [list(range(100)), list(range(100, 199))]
tracks = list(range(99))
assert divide_tracks_into_chunks(tracks) == [list(range(99))]
tracks = list(range(299))
assert divide_tracks_into_chunks(tracks) == [list(range(100)), list(range(100, 200)), list(range(200, 299))]