Ejemplo n.º 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']),
    ])
Ejemplo n.º 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))
Ejemplo n.º 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']),
    ])
Ejemplo n.º 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
Ejemplo n.º 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)
    )
Ejemplo n.º 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}'
Ejemplo n.º 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']),
    ])
Ejemplo n.º 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']),
    ])
Ejemplo n.º 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'
    )
Ejemplo n.º 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'
    )
Ejemplo n.º 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']),
    ])
Ejemplo n.º 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']),
    ])
Ejemplo n.º 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
Ejemplo n.º 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']),
    ])
Ejemplo n.º 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']),
    ])
Ejemplo n.º 16
0
from __future__ import absolute_import

from pre_commit.main import main

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

from pre_commit.main import main


if __name__ == '__main__':
    exit(main())
Ejemplo n.º 20
0
def test_overall_help(mock_commands, argparse_exit_mock):
    with pytest.raises(CalledExit):
        main.main(['--help'])
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 28
0
from pre_commit.main import main

if __name__ == '__main__':
    raise SystemExit(main())
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 31
0
def test_overall_help(mock_commands, argparse_exit_mock):
    with pytest.raises(CalledExit):
        main.main(['--help'])
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 34
0
def test_overall_help(mock_commands):
    with pytest.raises(SystemExit):
        main.main(['--help'])
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)