refactor subshells, add help system
This commit is contained in:
@@ -6,6 +6,8 @@ from unittest.mock import MagicMock
|
||||
from groove import playlist, editor
|
||||
from groove.exceptions import PlaylistValidationError, TrackNotFoundError
|
||||
|
||||
from yaml.scanner import ScannerError
|
||||
|
||||
|
||||
def test_create(empty_playlist):
|
||||
assert empty_playlist.record.id
|
||||
@@ -174,6 +176,32 @@ def test_edit(monkeypatch, edits, expected, empty_playlist):
|
||||
assert empty_playlist.name == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error', [TypeError, ScannerError, TrackNotFoundError])
|
||||
def test_edit_errors(monkeypatch, error, empty_playlist):
|
||||
monkeypatch.setattr('groove.playlist.Playlist.from_yaml', MagicMock(
|
||||
side_effect=error
|
||||
))
|
||||
with pytest.raises(PlaylistValidationError):
|
||||
empty_playlist.edit()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error', [IOError, OSError, FileNotFoundError])
|
||||
def test_edit_errors_in_editor(monkeypatch, error, empty_playlist):
|
||||
monkeypatch.setattr('groove.editor.subprocess.check_call', MagicMock(
|
||||
side_effect=error
|
||||
))
|
||||
with pytest.raises(RuntimeError):
|
||||
empty_playlist.edit()
|
||||
|
||||
|
||||
def test_edit_yaml_error_in_editor(monkeypatch, empty_playlist):
|
||||
monkeypatch.setattr('groove.editor.PlaylistEditor.read', MagicMock(
|
||||
side_effect=ScannerError
|
||||
))
|
||||
with pytest.raises(PlaylistValidationError):
|
||||
empty_playlist.edit()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('slug', [None, ''])
|
||||
def test_save_no_slug(slug, empty_playlist):
|
||||
empty_playlist._slug = slug
|
||||
|
||||
+54
-22
@@ -9,7 +9,7 @@ from unittest.mock import MagicMock
|
||||
def cmd_prompt(monkeypatch, in_memory_engine, db):
|
||||
with database_manager() as manager:
|
||||
manager._session = db
|
||||
yield interactive_shell.CommandPrompt(manager)
|
||||
yield interactive_shell.InteractiveShell(manager)
|
||||
|
||||
|
||||
def response_factory(responses):
|
||||
@@ -35,30 +35,15 @@ def test_quit(monkeypatch, capsys, cmd_prompt, inputs, expected):
|
||||
cmd_prompt.start()
|
||||
|
||||
|
||||
def test_browse(monkeypatch, capsys, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory(['browse']))
|
||||
def test_list(monkeypatch, capsys, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory(['list']))
|
||||
cmd_prompt.start()
|
||||
output = capsys.readouterr()
|
||||
assert 'Displaying 4 playlists' in output.out
|
||||
assert 'playlist one' in output.out
|
||||
assert 'the first one' in output.out
|
||||
assert 'playlist-one' in output.out
|
||||
assert 'the second one' in output.out
|
||||
assert 'the threerd one' in output.out
|
||||
assert 'empty playlist' in output.out
|
||||
|
||||
|
||||
@pytest.mark.parametrize('inputs, expected', [
|
||||
(['help'], ['Available Commands', ' help ', ' stats ', ' browse ']),
|
||||
(['help browse'], ['Help for browse']),
|
||||
])
|
||||
def test_help(monkeypatch, capsys, cmd_prompt, inputs, expected):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
|
||||
@pytest.mark.parametrize('inputs', ['help', 'help list'])
|
||||
def test_help(monkeypatch, capsys, cmd_prompt, inputs):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory([inputs]))
|
||||
cmd_prompt.start()
|
||||
output = capsys.readouterr()
|
||||
for txt in expected:
|
||||
assert txt in output.out
|
||||
assert cmd_prompt.__doc__ == cmd_prompt.help_text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('inputs, expected', [
|
||||
@@ -74,4 +59,51 @@ def test_load(monkeypatch, caplog, cmd_prompt, inputs, expected):
|
||||
|
||||
def test_values(cmd_prompt):
|
||||
for cmd in [cmd for cmd in cmd_prompt.commands.keys() if not cmd.startswith('_')]:
|
||||
assert cmd in cmd_prompt.values
|
||||
assert cmd in cmd_prompt.autocomplete_values
|
||||
|
||||
|
||||
def test_playlist_usage(monkeypatch, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
|
||||
'load new playlist',
|
||||
'help'
|
||||
]))
|
||||
cmd_prompt.start()
|
||||
|
||||
|
||||
def test_playliest_edit(monkeypatch, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
|
||||
'load new playlist',
|
||||
'edit'
|
||||
]))
|
||||
cmd_prompt.start()
|
||||
|
||||
|
||||
def test_playlist_show(monkeypatch, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
|
||||
'load playlist one',
|
||||
'show'
|
||||
]))
|
||||
cmd_prompt.start()
|
||||
|
||||
|
||||
def test_playlist_add(monkeypatch, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
|
||||
'load playlist one',
|
||||
'add',
|
||||
'',
|
||||
'add',
|
||||
'UNKLE/Psyence Fiction/01 Guns Blazing (Drums of Death, Part 1).flac',
|
||||
'',
|
||||
]))
|
||||
cmd_prompt.start()
|
||||
|
||||
|
||||
def test_playlist_delete(monkeypatch, cmd_prompt):
|
||||
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
|
||||
'load playlist one',
|
||||
'delete',
|
||||
'',
|
||||
'delete',
|
||||
'DELETE',
|
||||
]))
|
||||
cmd_prompt.start()
|
||||
|
||||
Reference in New Issue
Block a user