diff --git a/groove/path.py b/groove/path.py index f0c6309..c5b4a08 100644 --- a/groove/path.py +++ b/groove/path.py @@ -44,7 +44,7 @@ def static_root(): dirname = os.environ.get('STATIC_PATH', 'static') path = root() / Path(dirname) if not path.exists() or not path.is_dir(): - raise ConfigurationError( + raise ConfigurationError( # pragma: no cover f"The static assets directory {dirname} (STATIC_PATH) " f"doesn't exist, or isn't a directory.\n\n{_reinstall_hint}" ) @@ -56,7 +56,7 @@ def static(relpath, theme=None): if theme: root = theme.path / Path('static') if not root.is_dir(): - raise ThemeConfigurationError( + raise ThemeConfigurationError( # pragma: no cover f"The themes directory {relpath} (THEMES_PATH) " f"doesn't contain a 'static' directory." ) @@ -73,7 +73,7 @@ def themes_root(): dirname = os.environ.get('THEMES_PATH', 'themes') path = root() / Path(dirname) if not path.exists() or not path.is_dir(): - raise ConfigurationError( + raise ConfigurationError( # pragma: no cover f"The themes directory {dirname} (THEMES_PATH) " f"doesn't exist, or isn't a directory.\n\n{_reinstall_hint}" ) @@ -84,7 +84,7 @@ def themes_root(): def theme(name): path = themes_root() / Path(name) if not path.exists() or not path.is_dir(): - available = ','.join(available_themes) + available = ','.join(available_themes()) raise ThemeMissingException( f"A theme directory named {name} does not exist or isn't a directory. " "Perhaps there is a typo in the name?\n" diff --git a/groove/shell/base.py b/groove/shell/base.py index 4590cb0..f6eb614 100644 --- a/groove/shell/base.py +++ b/groove/shell/base.py @@ -7,7 +7,7 @@ class BasePrompt(Completer): def __init__(self, manager=None, parent=None): super(BasePrompt, self).__init__() - if (not manager and not parent): + if (not manager and not parent): # pragma: no cover raise RuntimeError("Must define either a database manager or a parent object.") self._prompt = '' diff --git a/groove/shell/interactive_shell.py b/groove/shell/interactive_shell.py index 4129764..68bfaba 100644 --- a/groove/shell/interactive_shell.py +++ b/groove/shell/interactive_shell.py @@ -33,7 +33,7 @@ class CommandPrompt(BasePrompt): def values(self): return [k for k in self.commands.keys() if not k.startswith('_')] - def default_completer(self, document, complete_event): + def default_completer(self, document, complete_event): # pragma: no cover def _formatter(row): self._playlist = Playlist.from_row(row, self.manager.session) return self.playlist.record.name @@ -47,19 +47,17 @@ class CommandPrompt(BasePrompt): name = cmd + ' ' + ' '.join(parts) if cmd in self.commands: self.commands[cmd].start(name) - else: - self._playlist = Playlist( - slug=slugify(name), - name=name, - session=self.manager.session, - create_ok=True - ) - res = self.commands['_playlist'].start() - if res is False: - return res - return True + return True + self._playlist = Playlist( + slug=slugify(name), + name=name, + session=self.manager.session, + create_ok=True + ) + res = self.commands['_playlist'].start() + return True and res -def start(): +def start(): # pragma: no cover with database_manager() as manager: CommandPrompt(manager).start() diff --git a/test/fixtures/themes/alt_theme/static/test.css b/test/fixtures/themes/alt_theme/static/test.css deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_path.py b/test/test_path.py index 3e67bd8..ff56abf 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -2,12 +2,35 @@ import pytest import os from groove import path -from groove.exceptions import ConfigurationError +from groove.exceptions import ConfigurationError, ThemeMissingException +from groove.webserver import themes -def test_missing_theme_root(monkeypatch): +@pytest.mark.parametrize('root', ['/dev/null/missing', None]) +def test_missing_media_root(monkeypatch, root): broken_env = {k: v for (k, v) in os.environ.items()} - broken_env['GROOVE_ON_DEMAND_ROOT'] = '/dev/null/missing' + broken_env['MEDIA_ROOT'] = root + monkeypatch.setattr(os, 'environ', broken_env) + with pytest.raises(ConfigurationError): + path.media_root() + +def test_static(monkeypatch): + assert path.static('foo') + assert path.static('foo', theme=themes.load_theme('default_theme')) + +@pytest.mark.parametrize('root', ['/dev/null/missing', None]) +def test_missing_theme_root(monkeypatch, root): + broken_env = {k: v for (k, v) in os.environ.items()} + broken_env['GROOVE_ON_DEMAND_ROOT'] = root monkeypatch.setattr(os, 'environ', broken_env) with pytest.raises(ConfigurationError): path.themes_root() + + +def test_theme_no_path(): + with pytest.raises(ThemeMissingException): + path.theme('nope') + + +def test_database(env): + assert env['DATABASE_PATH'] in path.database().name diff --git a/test/test_playlists.py b/test/test_playlists.py index b263653..52805ca 100644 --- a/test/test_playlists.py +++ b/test/test_playlists.py @@ -6,8 +6,6 @@ from unittest.mock import MagicMock from groove import playlist, editor from groove.exceptions import PlaylistValidationError, TrackNotFoundError -# 166-167, 200, 203-204, 227-228, 253->255, 255->exit, 270, 346-347 - def test_create(empty_playlist): assert empty_playlist.record.id diff --git a/test/test_shell.py b/test/test_shell.py index 7987cca..acf65b5 100644 --- a/test/test_shell.py +++ b/test/test_shell.py @@ -58,6 +58,7 @@ def test_help(monkeypatch, capsys, cmd_prompt, inputs, expected): 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', [ @@ -69,3 +70,8 @@ def test_load(monkeypatch, caplog, cmd_prompt, inputs, expected): monkeypatch.setattr('groove.shell.base.prompt', response_factory([inputs])) cmd_prompt.start() assert expected in caplog.text + + +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