dnd-music-console/test/test_playlist.py

45 lines
1.4 KiB
Python
Raw Permalink Normal View History

2024-03-08 13:18:25 -08:00
from unittest.mock import MagicMock
import pytest
import croaker.path
2024-03-26 00:51:16 -07:00
import croaker.playlist
2024-03-08 13:18:25 -08:00
def test_playlist_loading():
2024-03-26 00:51:16 -07:00
pl = croaker.playlist.Playlist(name="test_playlist")
2024-03-08 13:18:25 -08:00
path = str(pl.path)
tracks = [str(t) for t in pl.tracks]
assert path == str(croaker.path.playlist_root() / pl.name)
2024-03-26 00:51:16 -07:00
assert pl.name == "test_playlist"
2024-03-08 13:18:25 -08:00
assert tracks[0] == f"{path}/_theme.mp3"
assert f"{path}/one.mp3" in tracks
assert f"{path}/two.mp3" in tracks
assert f"{path}/one.foo" in tracks
assert f"{path}/one.baz" not in tracks
2024-03-26 00:51:16 -07:00
@pytest.mark.parametrize(
"paths, make_theme, expected_count",
[
(["test_playlist"], True, 4),
(["test_playlist"], False, 4),
(["test_playlist", "sources/one.mp3"], True, 5),
(["test_playlist", "sources/one.mp3"], False, 5),
],
)
2024-03-08 13:18:25 -08:00
def test_playlist_creation(monkeypatch, paths, make_theme, expected_count):
new_symlinks = []
def symlink(target):
new_symlinks.append(target)
2024-03-26 00:51:16 -07:00
pl = croaker.playlist.Playlist(name="foo")
monkeypatch.setattr(croaker.playlist.Path, "unlink", MagicMock())
monkeypatch.setattr(croaker.playlist.Path, "symlink_to", MagicMock(side_effect=symlink))
monkeypatch.setattr(croaker.playlist.Path, "mkdir", MagicMock())
2024-03-08 13:18:25 -08:00
pl.add([croaker.path.playlist_root() / p for p in paths], make_theme)
assert len(new_symlinks) == expected_count