-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fix_spotify_favorites.py
76 lines (64 loc) · 1.93 KB
/
test_fix_spotify_favorites.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
73
74
75
76
from pathlib import Path
from typing import Optional
from typing import Set
import pytest
import fix_spotify_favorites as fix
_fake_track = {
"id": "foo",
"duration_ms": 5,
"explicit": True,
"uri": "bar",
"name": "Track Name",
"href": "https://foo",
"track_number": 4,
}
def test_Track_from_result():
got = fix.Track.from_result(_fake_track)
assert isinstance(got, fix.Track)
assert got._data == _fake_track
assert got.uri == "bar"
def test_Album_from_result():
data = {
"id": "foo",
"uri": "bar",
"name": "An Album Cover",
"album_type": "album",
"href": "https://foo",
"release_date": "2022-04-01",
"release_date_precision": "day",
"artists": [{"name": "Weird Al"}, {"name": "Tenacious D"}],
"tracks": {"items": [_fake_track, _fake_track]},
}
got = fix.Album.from_result(data)
assert isinstance(got, fix.Album)
assert got._data == data
assert len(got.tracks) == 2
assert got.artist_name == "Weird Al,Tenacious D"
@pytest.mark.parametrize(
"path, want",
[
(None, set()),
(Path("foo.csv"), set()),
(Path(__file__), {"foo", "bar"}),
],
)
def test_read_skiplist_file(path: Optional[Path], want: Set[str], monkeypatch):
monkeypatch.setattr(fix, "parse_skiplist_file", lambda _: want)
got = fix.read_skiplist_file(path)
assert got == want
@pytest.mark.parametrize(
"fake_data, want",
[
("spotify_id,album\nfoo,bar" "", {"foo"}),
("name,spotify_id,album\napple,foo,bar" "", {"foo"}),
("spotify_id\nfoo\nbar", {"foo", "bar"}),
# Different line ending
("spotify_id\r\nfoo", {"foo"}),
],
)
def test_parse_skiplist_file(fake_data: str, want: str, tmp_path: Path):
# Create the fake skiplist file.
path = tmp_path / "skiplist.csv"
path.write_text(fake_data)
got = fix.parse_skiplist_file(path)
assert got == want