adding tests
This commit is contained in:
parent
f3fd8215f0
commit
d2f4a85cd5
26
.coveragerc
Normal file
26
.coveragerc
Normal file
|
@ -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
|
3
pytest.ini
Normal file
3
pytest.ini
Normal file
|
@ -0,0 +1,3 @@
|
|||
[pytest]
|
||||
log_cli_level = DEBUG
|
||||
addopts = --cov=croaker/ --cov-report=term-missing
|
0
test/fixtures/playlists/test_playlist/_theme.mp3
vendored
Normal file
0
test/fixtures/playlists/test_playlist/_theme.mp3
vendored
Normal file
0
test/fixtures/playlists/test_playlist/one.baz
vendored
Normal file
0
test/fixtures/playlists/test_playlist/one.baz
vendored
Normal file
0
test/fixtures/playlists/test_playlist/one.foo
vendored
Normal file
0
test/fixtures/playlists/test_playlist/one.foo
vendored
Normal file
0
test/fixtures/playlists/test_playlist/one.mp3
vendored
Normal file
0
test/fixtures/playlists/test_playlist/one.mp3
vendored
Normal file
0
test/fixtures/playlists/test_playlist/two.mp3
vendored
Normal file
0
test/fixtures/playlists/test_playlist/two.mp3
vendored
Normal file
0
test/fixtures/sources/album/"one" - two'.mp3
vendored
Normal file
0
test/fixtures/sources/album/"one" - two'.mp3
vendored
Normal file
0
test/fixtures/sources/one.mp3
vendored
Normal file
0
test/fixtures/sources/one.mp3
vendored
Normal file
0
test/fixtures/sources/two.mp3
vendored
Normal file
0
test/fixtures/sources/two.mp3
vendored
Normal file
48
test/test_playlist.py
Normal file
48
test/test_playlist.py
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user