コード例 #1
0
ファイル: test_main.py プロジェクト: x1g1/python-githooks
def test_main_entry_point_exit(mocker, workspace_without_git):
    """main function should exit if ran in not valid git project"""
    python_githooks.__main__.__BASE_DIR__ = workspace_without_git
    python_githooks.__main__.__GITHOOKS_BASE_DIR__ = os.path.join(
        workspace_without_git, '.git/hooks')
    mocked_sys_exit = mocker.patch('sys.exit')
    main()
    mocked_sys_exit.assert_called_once_with(1)
コード例 #2
0
def test_main_entry_point_deactivation(mocker, no_sys_args,
                                       workspace_with_config):
    """main function should execute first argument as githook"""
    with mock_githooks_main(workspace_with_config) as mocked_githooks_main:
        mocked_delete_git_hook = mocker.spy(mocked_githooks_main,
                                            "delete_git_hooks")
        sys.argv.extend(["--activate", "--deactivate"])
        main()
        mocked_delete_git_hook.assert_called_once_with(
            configfile_path=workspace_with_config.config,
            githooks_dir=workspace_with_config.hooks,
        )
コード例 #3
0
def test_main_entry_point_config_file_creation(mocker, no_sys_args,
                                               workspace_with_git):
    """main function should create config file if it doesn't exists"""
    with mock_githooks_main(workspace_with_git) as mocked_githooks_main:
        mocked_create_config = mocker.spy(mocked_githooks_main,
                                          "create_config_file")
        mocked_create_githooks = mocker.spy(mocked_githooks_main,
                                            "create_git_hooks")
        sys.argv = sys.argv[:1]
        main()
        assert mocked_create_config.call_count == 1
        assert mocked_create_githooks.call_count == 1
コード例 #4
0
ファイル: test_main.py プロジェクト: x1g1/python-githooks
def test_main_entry_point_config_file_creation(mocker, workspace_with_git):
    """main function should create config file if it doesn't exists"""
    python_githooks.__main__.__BASE_DIR__ = workspace_with_git
    python_githooks.__main__.__GITHOOKS_BASE_DIR__ = os.path.join(
        workspace_with_git, '.git/hooks')
    python_githooks.__main__.__GITHOOKS_CONFIGFILE_PATH__ = os.path.join(
        workspace_with_git, '.githooks.ini')
    mocker.spy(python_githooks.__main__, 'create_config_file')
    mocker.spy(python_githooks.__main__, 'create_git_hooks')
    main()
    assert python_githooks.__main__.create_config_file.call_count == 1
    assert python_githooks.__main__.create_git_hooks.call_count == 1
コード例 #5
0
def test_main_entry_point_githook_execution(mocker, no_sys_args,
                                            workspace_with_config):
    """main function should execute first argument as githook"""
    with mock_githooks_main(workspace_with_config) as mocked_githooks_main:
        mocked_sys_exit = mocker.patch("sys.exit")
        mocked_execute_git_hook = mocker.spy(mocked_githooks_main,
                                             "execute_git_hook")
        sys.argv.extend(["--activate", "pre-commit"])
        main()
        assert mocked_execute_git_hook.call_count == 1
        assert mocked_execute_git_hook.call_args[1][
            "hook_name"] == "pre-commit"
        mocked_sys_exit.assert_called_once_with(0)
コード例 #6
0
def test_main_entry_point_exit(mocker, no_sys_args, workspace_without_git):
    """main function should exit if ran in not valid git project"""
    with mock_githooks_main(workspace_without_git):
        mocked_sys_exit = mocker.patch("sys.exit")
        main()
        mocked_sys_exit.assert_called_once_with(1)
コード例 #7
0
def _post_install():
    from python_githooks import __main__
    __main__.main()