Add initial test suite
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, PropertyMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def subcommand(temp_directory):
|
||||
tmp = temp_directory.as_posix()
|
||||
with patch.dict('os.environ', {'ORIG_CWD': tmp, 'QMK_HOME': tmp}, clear=True):
|
||||
import qmk_cli.subcommands.clone as clone
|
||||
|
||||
yield clone
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_clone(subcommand):
|
||||
with patch.object(subcommand, 'git_clone') as git_clone:
|
||||
yield git_clone
|
||||
|
||||
|
||||
def test_clone(subcommand, mock_cli, git_clone):
|
||||
type(mock_cli.args).baseurl = PropertyMock(return_value='asdf')
|
||||
type(mock_cli.args).fork = PropertyMock(return_value='fork')
|
||||
git_clone.return_value = True
|
||||
|
||||
ret = subcommand.clone(mock_cli)
|
||||
|
||||
git_clone.assert_called_once()
|
||||
assert ret is True
|
||||
|
||||
|
||||
def test_clone_not_empty(subcommand, mock_cli, temp_directory, git_clone):
|
||||
type(mock_cli.args).baseurl = PropertyMock(return_value='asdf')
|
||||
type(mock_cli.args).fork = PropertyMock(return_value='fork')
|
||||
type(mock_cli.args).destination = PropertyMock(return_value=temp_directory)
|
||||
(temp_directory / 'asdf').touch()
|
||||
|
||||
ret = subcommand.clone(mock_cli)
|
||||
|
||||
git_clone.assert_not_called()
|
||||
assert ret is False
|
||||
@@ -0,0 +1,51 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, PropertyMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def subcommand(temp_directory):
|
||||
tmp = temp_directory.as_posix()
|
||||
with patch.dict('os.environ', {'ORIG_CWD': tmp, 'QMK_HOME': tmp}, clear=True):
|
||||
import qmk_cli.subcommands.env as env
|
||||
|
||||
yield env
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def is_qmk_firmware(subcommand):
|
||||
with patch.object(subcommand, 'is_qmk_firmware') as is_qmk_firmware:
|
||||
is_qmk_firmware.return_value = True
|
||||
|
||||
yield is_qmk_firmware
|
||||
|
||||
|
||||
def test_request_qmk_firmware_exists(subcommand, mock_cli, capsys, temp_directory, is_qmk_firmware):
|
||||
subcommand.env(mock_cli)
|
||||
captured = capsys.readouterr().out
|
||||
assert f'QMK_HOME="{temp_directory}"' in captured
|
||||
assert f'QMK_FIRMWARE="{temp_directory}"' in captured
|
||||
|
||||
|
||||
def test_request_all_variables(subcommand, mock_cli, capsys, temp_directory):
|
||||
subcommand.env(mock_cli)
|
||||
captured = capsys.readouterr().out
|
||||
assert f'QMK_HOME="{temp_directory}"' in captured
|
||||
assert 'QMK_FIRMWARE=""' in captured
|
||||
assert 'QMK_UNICODE="True"' in captured
|
||||
|
||||
|
||||
def test_request_single_variable(subcommand, mock_cli, capsys, temp_directory):
|
||||
type(mock_cli.args).var = PropertyMock(return_value='QMK_HOME')
|
||||
|
||||
subcommand.env(mock_cli)
|
||||
captured = capsys.readouterr().out
|
||||
assert captured == f'{temp_directory}\n'
|
||||
|
||||
|
||||
def test_request_single_variable_no_exits(subcommand, mock_cli, capsys):
|
||||
type(mock_cli.args).var = PropertyMock(return_value='ASDF')
|
||||
|
||||
ret = subcommand.env(mock_cli)
|
||||
captured = capsys.readouterr().err
|
||||
assert captured == 'Variable "ASDF" does not exist!\n'
|
||||
assert ret is False
|
||||
@@ -0,0 +1,176 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, PropertyMock, ANY
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def subcommand(temp_directory):
|
||||
tmp = temp_directory.as_posix()
|
||||
with patch.dict('os.environ', {'ORIG_CWD': tmp, 'QMK_HOME': tmp}, clear=True):
|
||||
import qmk_cli.subcommands.setup as setup
|
||||
|
||||
yield setup
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def is_qmk_firmware(subcommand):
|
||||
with patch.object(subcommand, 'is_qmk_firmware') as is_qmk_firmware:
|
||||
is_qmk_firmware.return_value = True
|
||||
|
||||
yield is_qmk_firmware
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def yesno(subcommand):
|
||||
with patch.object(subcommand, 'yesno') as yesno:
|
||||
yesno.return_value = True
|
||||
|
||||
yield yesno
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def choice(subcommand):
|
||||
with patch.object(subcommand, 'choice') as choice:
|
||||
yield choice
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def question(subcommand):
|
||||
with patch.object(subcommand, 'question') as question:
|
||||
yield question
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_clone_fork(subcommand):
|
||||
with patch.object(subcommand, 'git_clone_fork') as git_clone_fork:
|
||||
yield git_clone_fork
|
||||
|
||||
|
||||
def test_setup_both_yes_no_invalid(subcommand, mock_cli):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=True)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=True)
|
||||
|
||||
with pytest.raises(SystemExit) as e:
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
assert e.value.code == 1
|
||||
|
||||
|
||||
def test_setup_reclone(subcommand, mock_cli, is_qmk_firmware, temp_directory, yesno, choice, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
type(mock_cli.args).fork = 'asdf'
|
||||
choice.return_value = 'Delete and reclone asdf'
|
||||
yesno.return_value = True
|
||||
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
yesno.assert_called_once()
|
||||
assert 'This will delete your current qmk_firmware directory.' in yesno.call_args.args[0]
|
||||
git_clone_fork.assert_called_once()
|
||||
|
||||
|
||||
def test_setup_reclone_no(subcommand, mock_cli, is_qmk_firmware, temp_directory, yesno, choice, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
type(mock_cli.args).fork = 'asdf'
|
||||
choice.return_value = 'Delete and reclone asdf'
|
||||
yesno.return_value = False
|
||||
|
||||
with pytest.raises(SystemExit) as e:
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
assert e.value.code == 1
|
||||
git_clone_fork.assert_not_called()
|
||||
|
||||
|
||||
def test_setup_clone_diff_fork(subcommand, mock_cli, is_qmk_firmware, temp_directory, yesno, choice, question, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
choice.return_value = 'Delete and clone a different fork'
|
||||
yesno.return_value = True
|
||||
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
yesno.assert_called_once()
|
||||
assert 'This will delete your current qmk_firmware directory.' in yesno.call_args.args[0]
|
||||
git_clone_fork.assert_called_once()
|
||||
|
||||
|
||||
def test_setup_clone_diff_fork_no(subcommand, mock_cli, is_qmk_firmware, temp_directory, yesno, choice, question, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
choice.return_value = 'Delete and clone a different fork'
|
||||
yesno.return_value = False
|
||||
|
||||
with pytest.raises(SystemExit) as e:
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
assert e.value.code == 1
|
||||
git_clone_fork.assert_not_called()
|
||||
|
||||
|
||||
def test_setup_home_exists_not_empty(subcommand, mock_cli, is_qmk_firmware, temp_directory):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
is_qmk_firmware.return_value = False
|
||||
(temp_directory / 'asdf').touch()
|
||||
|
||||
with pytest.raises(SystemExit) as e:
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
assert e.value.code == 1
|
||||
|
||||
|
||||
def test_setup_missing(subcommand, mock_cli, is_qmk_firmware, temp_directory, yesno, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
is_qmk_firmware.return_value = False
|
||||
yesno.return_value = True
|
||||
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
yesno.assert_called_once()
|
||||
assert 'Would you like to clone' in yesno.call_args.args[0]
|
||||
git_clone_fork.assert_called_once()
|
||||
|
||||
|
||||
def test_setup_missing_no(subcommand, mock_cli, is_qmk_firmware, temp_directory, yesno, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).home = PropertyMock(return_value=temp_directory)
|
||||
is_qmk_firmware.return_value = False
|
||||
yesno.return_value = False
|
||||
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
yesno.assert_called_once()
|
||||
assert 'Would you like to clone' in yesno.call_args.args[0]
|
||||
git_clone_fork.assert_not_called()
|
||||
|
||||
|
||||
def test_setup_chains_args_to_doctor(subcommand, mock_cli, is_qmk_firmware, yesno, choice, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=True)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=False)
|
||||
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
mock_cli.run.assert_called_once()
|
||||
assert mock_cli.run.call_args.args[0] == [ANY, '--color', '--unicode', 'doctor', '-y']
|
||||
|
||||
|
||||
def test_setup_chains_args_to_doctor_no(subcommand, mock_cli, is_qmk_firmware, yesno, choice, git_clone_fork):
|
||||
type(mock_cli.args).yes = PropertyMock(return_value=False)
|
||||
type(mock_cli.args).no = PropertyMock(return_value=True)
|
||||
mock_cli.config.general.color = False
|
||||
mock_cli.config.general.unicode = False
|
||||
|
||||
subcommand.setup(mock_cli)
|
||||
|
||||
mock_cli.run.assert_called_once()
|
||||
assert mock_cli.run.call_args.args[0] == [ANY, '--no-color', '--no-unicode', 'doctor', '-n']
|
||||
Reference in New Issue
Block a user