Skip to content

Commit e33d5dc

Browse files
committed
✅ Cover the CLI with tests
1 parent a04cb1c commit e33d5dc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_cli.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import runpy
2+
import sys
3+
from unittest.mock import call, patch
4+
5+
import pytest
6+
from click.testing import CliRunner
7+
8+
import gcm
9+
from gcm.cli import cli
10+
11+
12+
@patch.dict(sys.modules)
13+
@patch('sys.argv', ['gcm', 'enable', 'foo'])
14+
@patch('click.echo')
15+
@patch('gcm.commands.enable.Enable.callback')
16+
def test_main(callback, echo):
17+
del sys.modules['gcm.cli']
18+
19+
with pytest.raises(SystemExit):
20+
runpy.run_module('gcm.cli', run_name='__main__')
21+
22+
callback.assert_called_once_with(package='app-misc/foo')
23+
assert echo.call_args_list == [
24+
call('Enabling ccache for \x1b[32m\x1b[1mapp-misc/foo\x1b[0m'),
25+
call('\x1b[32mDone :-)\x1b[0m'),
26+
]
27+
28+
29+
def test_cli_version():
30+
runner = CliRunner()
31+
result = runner.invoke(cli, ['--version'])
32+
assert result.exit_code == 0
33+
assert result.output == f'{gcm.__name__}, version {gcm.__version__}\n'

0 commit comments

Comments
 (0)