Exemple #1
0
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']),
    ])
Exemple #2
0
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))
Exemple #3
0
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']),
    ])
Exemple #4
0
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
Exemple #5
0
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)
    )
Exemple #6
0
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}'
Exemple #7
0
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']),
    ])
Exemple #8
0
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']),
    ])
Exemple #9
0
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'
    )
Exemple #10
0
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'
    )
Exemple #11
0
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']),
    ])
Exemple #12
0
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']),
    ])
Exemple #13
0
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
Exemple #14
0
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']),
    ])
Exemple #15
0
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']),
    ])
Exemple #16
0
from __future__ import absolute_import

from pre_commit.main import main

if __name__ == '__main__':
    exit(main())
Exemple #17
0
def test_overall_help(mock_commands):
    with pytest.raises(SystemExit):
        main.main(['--help'])
Exemple #18
0
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)
Exemple #19
0
from __future__ import absolute_import

from pre_commit.main import main


if __name__ == '__main__':
    exit(main())
Exemple #20
0
def test_overall_help(mock_commands, argparse_exit_mock):
    with pytest.raises(CalledExit):
        main.main(['--help'])
Exemple #21
0
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
Exemple #22
0
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
Exemple #23
0
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)
Exemple #24
0
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)
Exemple #25
0
def test_autoupdate_command(mock_commands):
    main.main(['autoupdate'])
    assert mock_commands.autoupdate_mock.call_count == 1
    assert_only_one_mock_called(mock_commands)
Exemple #26
0
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)
Exemple #27
0
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()
Exemple #28
0
from pre_commit.main import main

if __name__ == '__main__':
    raise SystemExit(main())
Exemple #29
0
def test_clean_command(mock_commands):
    main.main(['clean'])
    assert mock_commands.clean_mock.call_count == 1
    assert_only_one_mock_called(mock_commands)
Exemple #30
0
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()
Exemple #31
0
def test_overall_help(mock_commands, argparse_exit_mock):
    with pytest.raises(CalledExit):
        main.main(['--help'])
Exemple #32
0
def test_uninstall_command(mock_commands):
    main.main(['uninstall'])
    assert mock_commands.uninstall_mock.call_count == 1
    assert_only_one_mock_called(mock_commands)
Exemple #33
0
def test_uninstall_command(mock_commands):
    main.main(['uninstall'])
    assert mock_commands.uninstall_mock.call_count == 1
    assert_only_one_mock_called(mock_commands)
Exemple #34
0
def test_overall_help(mock_commands):
    with pytest.raises(SystemExit):
        main.main(['--help'])
Exemple #35
0
def test_clean_command(mock_commands):
    main.main(['clean'])
    assert mock_commands.clean_mock.call_count == 1
    assert_only_one_mock_called(mock_commands)
Exemple #36
0
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)
Exemple #37
0
def test_autoupdate_command(mock_commands):
    main.main(['autoupdate'])
    assert mock_commands.autoupdate_mock.call_count == 1
    assert_only_one_mock_called(mock_commands)
Exemple #38
0
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
Exemple #39
0
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)
Exemple #40
0
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)
Exemple #41
0
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)