adding tests
This commit is contained in:
parent
4acd16bdde
commit
a0de0eef48
|
@ -23,4 +23,4 @@ class help(BasePrompt):
|
|||
table.add_row(getattr(obj, 'usage', name), obj.__doc__)
|
||||
print(table)
|
||||
else:
|
||||
print(f"Help for {parts}:")
|
||||
print(f"Help for {' '.join(parts)}:")
|
||||
|
|
|
@ -7,14 +7,18 @@ from sqlalchemy.orm import sessionmaker
|
|||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def in_memory_db():
|
||||
def in_memory_engine():
|
||||
return create_engine('sqlite:///:memory:', future=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def in_memory_db(in_memory_engine):
|
||||
"""
|
||||
An (empty) in-memory SQLite3 database
|
||||
"""
|
||||
engine = create_engine('sqlite:///:memory:', future=True)
|
||||
Session = sessionmaker(bind=engine, future=True)
|
||||
Session = sessionmaker(bind=in_memory_engine, future=True)
|
||||
session = Session()
|
||||
groove.db.metadata.create_all(bind=engine)
|
||||
groove.db.metadata.create_all(bind=in_memory_engine)
|
||||
yield session
|
||||
session.close()
|
||||
|
||||
|
|
60
test/test_shell.py
Normal file
60
test/test_shell.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import pytest
|
||||
|
||||
from groove.db.manager import database_manager
|
||||
from groove.shell import interactive_shell
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cmd_prompt(in_memory_engine, db):
|
||||
with database_manager() as manager:
|
||||
manager._session = db
|
||||
yield interactive_shell.CommandPrompt(manager)
|
||||
|
||||
|
||||
def response_factory(responses):
|
||||
return MagicMock(side_effect=responses + [''])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('inputs, expected', [
|
||||
(['stats'], 'Database contains 4 playlists'), # match the db fixture
|
||||
])
|
||||
def test_stats(monkeypatch, capsys, cmd_prompt, inputs, expected):
|
||||
monkeypatch.setattr('groove.shell.base.prompt', response_factory(inputs))
|
||||
cmd_prompt.start()
|
||||
output = capsys.readouterr()
|
||||
assert expected in output.out
|
||||
|
||||
|
||||
@pytest.mark.parametrize('inputs, expected', [
|
||||
(['quit'], SystemExit),
|
||||
])
|
||||
def test_quit(monkeypatch, capsys, cmd_prompt, inputs, expected):
|
||||
monkeypatch.setattr('groove.shell.base.prompt', response_factory(inputs))
|
||||
with pytest.raises(expected):
|
||||
cmd_prompt.start()
|
||||
|
||||
|
||||
def test_browse(monkeypatch, capsys, cmd_prompt):
|
||||
monkeypatch.setattr('groove.shell.base.prompt', response_factory(['browse']))
|
||||
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.shell.base.prompt', response_factory([inputs]))
|
||||
cmd_prompt.start()
|
||||
output = capsys.readouterr()
|
||||
for txt in expected:
|
||||
assert txt in output.out
|
Loading…
Reference in New Issue
Block a user