diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..b676257 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,26 @@ +# .coveragerc to control coverage.py +[run] +branch = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + + # Don't complain about abstract methods, they aren't run: + @(abc\.)?abstractmethod + +ignore_errors = True diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..1dbd516 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +log_cli_level = DEBUG +addopts = --cov=croaker/ --cov-report=term-missing diff --git a/test/fixtures/playlists/test_playlist/_theme.mp3 b/test/fixtures/playlists/test_playlist/_theme.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/playlists/test_playlist/one.baz b/test/fixtures/playlists/test_playlist/one.baz new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/playlists/test_playlist/one.foo b/test/fixtures/playlists/test_playlist/one.foo new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/playlists/test_playlist/one.mp3 b/test/fixtures/playlists/test_playlist/one.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/playlists/test_playlist/two.mp3 b/test/fixtures/playlists/test_playlist/two.mp3 new file mode 100644 index 0000000..e69de29 diff --git "a/test/fixtures/sources/album/\"one\" - two'.mp3" "b/test/fixtures/sources/album/\"one\" - two'.mp3" new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/sources/one.mp3 b/test/fixtures/sources/one.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/sources/two.mp3 b/test/fixtures/sources/two.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/test/test_playlist.py b/test/test_playlist.py new file mode 100644 index 0000000..7277530 --- /dev/null +++ b/test/test_playlist.py @@ -0,0 +1,48 @@ +from pathlib import Path +from unittest.mock import MagicMock + +import pytest + +import croaker.playlist +import croaker.path + +@pytest.fixture(autouse=True) +def mock_env(monkeypatch): + fixtures = Path(__file__).parent / 'fixtures' + monkeypatch.setenv('CROAKER_ROOT', str(fixtures)) + monkeypatch.setenv('MEDIA_GLOB', '*.mp3,*.foo,*.bar') + + +def test_playlist_loading(): + pl = croaker.playlist.Playlist(name='test_playlist') + path = str(pl.path) + tracks = [str(t) for t in pl.tracks] + + assert path == str(croaker.path.playlist_root() / pl.name) + assert pl.name == 'test_playlist' + 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 + + +@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), +]) +def test_playlist_creation(monkeypatch, paths, make_theme, expected_count): + new_symlinks = [] + + def symlink(target): + new_symlinks.append(target) + + 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()) + + pl.add([croaker.path.playlist_root() / p for p in paths], make_theme) + assert len(new_symlinks) == expected_count