def test_help_other_command(mock_commands, argparse_parse_args_spy): with pytest.raises(SystemExit): main.main(['help', 'run']) argparse_parse_args_spy.assert_has_calls([ mock.call(['help', 'run']), mock.call(['run', '--help']), ])
def test_expected_fatal_error_no_git_repo(in_tmpdir, cap_out, mock_store_dir): with pytest.raises(SystemExit): main.main([]) log_file = os.path.join(mock_store_dir, 'pre-commit.log') assert cap_out.get() == ( 'An error has occurred: FatalError: git failed. ' 'Is it installed, and are you in a Git repository directory?\n' 'Check the log at {}\n'.format(log_file))
def test_init_templatedir(mock_store_dir): with mock.patch.object(main, 'init_templatedir') as patch: main.main(('init-templatedir', 'tdir')) assert patch.call_count == 1 assert 'tdir' in patch.call_args[0] assert patch.call_args[1]['hook_types'] is None assert patch.call_args[1]['skip_on_missing_config'] is True
def test_expected_fatal_error_no_git_repo(in_tmpdir, cap_out, mock_store_dir): with pytest.raises(SystemExit): main.main([]) log_file = os.path.join(mock_store_dir, 'pre-commit.log') assert cap_out.get() == ( 'An error has occurred: FatalError: git failed. ' 'Is it installed, and are you in a Git repository directory?\n' 'Check the log at {}\n'.format(log_file) )
def test_expected_fatal_error_no_git_repo(in_tmpdir, cap_out, mock_store_dir): with pytest.raises(SystemExit): main.main([]) log_file = os.path.join(mock_store_dir, 'pre-commit.log') cap_out_lines = cap_out.get().splitlines() assert ( cap_out_lines[-2] == 'An error has occurred: FatalError: git failed. ' 'Is it installed, and are you in a Git repository directory?') assert cap_out_lines[-1] == f'Check the log at {log_file}'
def test_help_command( mock_commands, argparse_exit_mock, argparse_parse_args_spy, ): with pytest.raises(CalledExit): main.main(['help']) argparse_parse_args_spy.assert_has_calls([ mock.call(['help']), mock.call(['--help']), ])
def test_expected_fatal_error_no_git_repo( tempdir_factory, cap_out, mock_out_store_directory, ): with cwd(tempdir_factory.get()): with pytest.raises(PreCommitSystemExit): main.main([]) assert cap_out.get() == ( 'An error has occurred: FatalError: git failed. ' 'Is it installed, and are you in a Git repository directory?\n' 'Check the log at ~/.pre-commit/pre-commit.log\n' )
def test_help_cmd_in_empty_directory( in_tmpdir, mock_commands, argparse_parse_args_spy, ): with pytest.raises(SystemExit): main.main(['help', 'run']) argparse_parse_args_spy.assert_has_calls([ mock.call(['help', 'run']), mock.call(['run', '--help']), ])
def test_init_templatedir_options(mock_store_dir): args = ( 'init-templatedir', 'tdir', '--hook-type', 'commit-msg', '--no-allow-missing-config', ) with mock.patch.object(main, 'init_templatedir') as patch: main.main(args) assert patch.call_count == 1 assert 'tdir' in patch.call_args[0] assert patch.call_args[1]['hook_types'] == ['commit-msg'] assert patch.call_args[1]['skip_on_missing_config'] is False
def test_help_cmd_in_empty_directory( mock_commands, tempdir_factory, argparse_exit_mock, argparse_parse_args_spy, ): path = tempdir_factory.get() with cwd(path): with pytest.raises(CalledExit): main.main(['help', 'run']) argparse_parse_args_spy.assert_has_calls([ mock.call(['help', 'run']), mock.call(['run', '--help']), ])
from __future__ import absolute_import from pre_commit.main import main if __name__ == '__main__': exit(main())
def test_overall_help(mock_commands): with pytest.raises(SystemExit): main.main(['--help'])
def test_all_cmds(command, mock_commands, mock_store_dir): main.main((command,)) assert getattr(mock_commands, command.replace('-', '_')).call_count == 1 assert_only_one_mock_called(mock_commands)
def test_overall_help(mock_commands, argparse_exit_mock): with pytest.raises(CalledExit): main.main(['--help'])
def test_try_repo(mock_store_dir): with mock.patch.object(main, 'try_repo') as patch: main.main(('try-repo', '.')) assert patch.call_count == 1
def test_install_command(command, mock_commands): main.main((command,)) assert getattr(mock_commands, command.replace('-', '_')).call_count == 1 assert_only_one_mock_called(mock_commands)
def test_autoupdate_command(mock_commands): main.main(['autoupdate']) assert mock_commands.autoupdate_mock.call_count == 1 assert_only_one_mock_called(mock_commands)
def test_no_commands_run_command(mock_commands): main.main([]) assert mock_commands.run_mock.call_count == 1 assert_only_one_mock_called(mock_commands)
def test_warning_on_tags_only(mock_commands, cap_out, mock_store_dir): main.main(('autoupdate', '--tags-only')) assert '--tags-only is the default' in cap_out.get()
from pre_commit.main import main if __name__ == '__main__': raise SystemExit(main())
def test_clean_command(mock_commands): main.main(['clean']) assert mock_commands.clean_mock.call_count == 1 assert_only_one_mock_called(mock_commands)
def test_warning_on_tags_only(mock_commands, cap_out): main.main(('autoupdate', '--tags-only')) assert '--tags-only is the default' in cap_out.get()
def test_uninstall_command(mock_commands): main.main(['uninstall']) assert mock_commands.uninstall_mock.call_count == 1 assert_only_one_mock_called(mock_commands)
def test_all_cmds(command, mock_commands, mock_store_dir): main.main((command, )) assert getattr(mock_commands, command.replace('-', '_')).call_count == 1 assert_only_one_mock_called(mock_commands)
def test_init_templatedir(mock_store_dir): with mock.patch.object(main, 'init_templatedir') as patch: main.main(('init-templatedir', 'tdir')) assert patch.call_count == 1
def test_install_hooks_command(mock_commands): main.main(('install-hooks', )) assert mock_commands.install_hooks_mock.call_count == 1 assert_only_one_mock_called(mock_commands)
def test_install_hooks_command(mock_commands): main.main(('install-hooks',)) assert mock_commands.install_hooks_mock.call_count == 1 assert_only_one_mock_called(mock_commands)