Ejemplo n.º 1
0
    def test_install_commit_msg_hook_negative(self, git_hooks_dir, isdir,
                                              path_exists, copy):
        lint_config = LintConfig()
        lint_config.target = os.path.join(u"/hür", u"dur")
        git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git",
                                                  "hooks")
        # mock that current dir is not a git repo
        isdir.return_value = False
        expected_msg = u"{0} is not a git repository".format(
            lint_config.target)
        with self.assertRaisesRegex(GitHookInstallerError, expected_msg):
            GitHookInstaller.install_commit_msg_hook(lint_config)
            isdir.assert_called_with(git_hooks_dir.return_value)
            path_exists.assert_not_called()
            copy.assert_not_called()

        # mock that there is already a commit hook present
        isdir.return_value = True
        path_exists.return_value = True
        expected_dst = os.path.join(git_hooks_dir.return_value,
                                    COMMIT_MSG_HOOK_DST_PATH)
        expected_msg = u"There is already a commit-msg hook file present in {0}.\n".format(expected_dst) + \
                       "gitlint currently does not support appending to an existing commit-msg file."
        with self.assertRaisesRegex(GitHookInstallerError, expected_msg):
            GitHookInstaller.install_commit_msg_hook(lint_config)
Ejemplo n.º 2
0
 def test_install_commit_msg_hook(self, isdir, path_exists, copy, stat, chmod):
     GitHookInstaller.install_commit_msg_hook()
     isdir.assert_called_once_with('.git/hooks')
     path_exists.assert_called_once_with(COMMIT_MSG_HOOK_DST_PATH)
     copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH, COMMIT_MSG_HOOK_DST_PATH)
     stat.assert_called_once_with(COMMIT_MSG_HOOK_DST_PATH)
     chmod.assert_called_once_with(COMMIT_MSG_HOOK_DST_PATH, ANY)
Ejemplo n.º 3
0
 def test_install_commit_msg_hook(self, isdir, path_exists, copy, stat,
                                  chmod):
     GitHookInstaller.install_commit_msg_hook()
     isdir.assert_called_once_with('.git/hooks')
     path_exists.assert_called_once_with(COMMIT_MSG_HOOK_DST_PATH)
     copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH,
                                  COMMIT_MSG_HOOK_DST_PATH)
     stat.assert_called_once_with(COMMIT_MSG_HOOK_DST_PATH)
     chmod.assert_called_once_with(COMMIT_MSG_HOOK_DST_PATH, ANY)
Ejemplo n.º 4
0
 def test_install_commit_msg_hook(isdir, path_exists, copy, stat, chmod):
     lint_config = LintConfig(target="/foo/bar")
     expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH)
     GitHookInstaller.install_commit_msg_hook(lint_config)
     isdir.assert_called_once_with('/foo/bar/.git/hooks')
     path_exists.assert_called_once_with(expected_dst)
     copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH, expected_dst)
     stat.assert_called_once_with(expected_dst)
     chmod.assert_called_once_with(expected_dst, ANY)
Ejemplo n.º 5
0
 def test_install_commit_msg_hook(isdir, path_exists, copy, stat, chmod):
     lint_config = LintConfig(target="/foo/bar")
     expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH)
     GitHookInstaller.install_commit_msg_hook(lint_config)
     isdir.assert_called_once_with('/foo/bar/.git/hooks')
     path_exists.assert_called_once_with(expected_dst)
     copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH, expected_dst)
     stat.assert_called_once_with(expected_dst)
     chmod.assert_called_once_with(expected_dst, ANY)
Ejemplo n.º 6
0
 def test_install_commit_msg_hook(self, isdir, path_exists, copy, stat, chmod):
     lint_config = LintConfig()
     lint_config.target = self.SAMPLES_DIR
     expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH)
     GitHookInstaller.install_commit_msg_hook(lint_config)
     isdir.assert_called_with(self.SAMPLES_DIR + '/.git/hooks')
     path_exists.assert_called_once_with(expected_dst)
     copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH, expected_dst)
     stat.assert_called_once_with(expected_dst)
     chmod.assert_called_once_with(expected_dst, ANY)
Ejemplo n.º 7
0
    def test_install_commit_msg_hook_negative(self, isdir, path_exists, copy):
        # mock that current dir is not a git repo
        isdir.return_value = False
        with self.assertRaises(GitHookInstallerError):
            GitHookInstaller.install_commit_msg_hook()
            isdir.assert_called_once_with('.git/hooks')
            path_exists.assert_not_called()
            copy.assert_not_called()

        # mock that there is already a commit hook present
        isdir.return_value = True
        path_exists.return_value = True
        with self.assertRaises(GitHookInstallerError):
            GitHookInstaller.install_commit_msg_hook()
Ejemplo n.º 8
0
    def test_install_commit_msg_hook_negative(self, isdir, path_exists, copy):
        # mock that current dir is not a git repo
        isdir.return_value = False
        with self.assertRaises(GitHookInstallerError):
            GitHookInstaller.install_commit_msg_hook()
            isdir.assert_called_once_with('.git/hooks')
            path_exists.assert_not_called()
            copy.assert_not_called()

        # mock that there is already a commit hook present
        isdir.return_value = True
        path_exists.return_value = True
        with self.assertRaises(GitHookInstallerError):
            GitHookInstaller.install_commit_msg_hook()
Ejemplo n.º 9
0
 def test_install_commit_msg_hook(git_hooks_dir, isdir, path_exists, copy,
                                  stat, chmod):
     lint_config = LintConfig()
     lint_config.target = os.path.join(u"/hür", u"dur")
     git_hooks_dir.return_value = os.path.join(u"/föo", u"bar", ".git",
                                               "hooks")
     expected_dst = os.path.join(git_hooks_dir.return_value,
                                 COMMIT_MSG_HOOK_DST_PATH)
     GitHookInstaller.install_commit_msg_hook(lint_config)
     isdir.assert_called_with(git_hooks_dir.return_value)
     path_exists.assert_called_once_with(expected_dst)
     copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH, expected_dst)
     stat.assert_called_once_with(expected_dst)
     chmod.assert_called_once_with(expected_dst, ANY)
     git_hooks_dir.assert_called_with(lint_config.target)
Ejemplo n.º 10
0
    def test_install_commit_msg_hook_negative(self, isdir, path_exists, copy):
        lint_config = LintConfig(target="/foo/bar")
        # mock that current dir is not a git repo
        isdir.return_value = False
        expected_msg = "/foo/bar is not a git repository"
        with self.assertRaisesRegexp(GitHookInstallerError, expected_msg):
            GitHookInstaller.install_commit_msg_hook(lint_config)
            isdir.assert_called_once_with('/foo/bar/.git/hooks')
            path_exists.assert_not_called()
            copy.assert_not_called()

        # mock that there is already a commit hook present
        isdir.return_value = True
        path_exists.return_value = True
        expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH)
        expected_msg = "There is already a commit-msg hook file present in {0}.\n".format(expected_dst) + \
                       "gitlint currently does not support appending to an existing commit-msg file."
        with self.assertRaisesRegexp(GitHookInstallerError, expected_msg):
            GitHookInstaller.install_commit_msg_hook(lint_config)
Ejemplo n.º 11
0
    def test_install_commit_msg_hook_negative(self, isdir, path_exists, copy):
        lint_config = LintConfig(target="/foo/bar")
        # mock that current dir is not a git repo
        isdir.return_value = False
        expected_msg = "/foo/bar is not a git repository"
        with self.assertRaisesRegexp(GitHookInstallerError, expected_msg):
            GitHookInstaller.install_commit_msg_hook(lint_config)
            isdir.assert_called_once_with('/foo/bar/.git/hooks')
            path_exists.assert_not_called()
            copy.assert_not_called()

        # mock that there is already a commit hook present
        isdir.return_value = True
        path_exists.return_value = True
        expected_dst = os.path.join("/foo/bar", COMMIT_MSG_HOOK_DST_PATH)
        expected_msg = "There is already a commit-msg hook file present in {0}.\n".format(expected_dst) + \
                       "gitlint currently does not support appending to an existing commit-msg file."
        with self.assertRaisesRegexp(GitHookInstallerError, expected_msg):
            GitHookInstaller.install_commit_msg_hook(lint_config)