summaryrefslogtreecommitdiffstats
path: root/tests/commands
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-04 18:42:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-04 18:42:11 +0000
commit361ff4da262b4891323287049e9e6c5fbe1d01dc (patch)
tree969b376a2c170841758d39ef9516dac65c8b94cd /tests/commands
parentAdding upstream version 2.17.0. (diff)
downloadpre-commit-361ff4da262b4891323287049e9e6c5fbe1d01dc.tar.xz
pre-commit-361ff4da262b4891323287049e9e6c5fbe1d01dc.zip
Adding upstream version 2.18.1.upstream/2.18.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/commands')
-rw-r--r--tests/commands/autoupdate_test.py20
-rw-r--r--tests/commands/clean_test.py2
-rw-r--r--tests/commands/gc_test.py2
-rw-r--r--tests/commands/hook_impl_test.py2
-rw-r--r--tests/commands/init_templatedir_test.py2
-rw-r--r--tests/commands/install_uninstall_test.py56
-rw-r--r--tests/commands/migrate_config_test.py2
-rw-r--r--tests/commands/run_test.py2
-rw-r--r--tests/commands/sample_config_test.py2
-rw-r--r--tests/commands/try_repo_test.py2
10 files changed, 87 insertions, 5 deletions
diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py
index 7316eb9..3806b0e 100644
--- a/tests/commands/autoupdate_test.py
+++ b/tests/commands/autoupdate_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import shlex
from unittest import mock
@@ -101,6 +103,24 @@ def test_rev_info_update_tags_only_does_not_pick_tip(tagged):
assert new_info.rev == 'v1.2.3'
+def test_rev_info_update_tags_prefers_version_tag(tagged, out_of_date):
+ cmd_output('git', 'tag', 'latest', cwd=out_of_date.path)
+ config = make_config_from_repo(tagged.path, rev=tagged.original_rev)
+ info = RevInfo.from_config(config)
+ new_info = info.update(tags_only=True, freeze=False)
+ assert new_info.rev == 'v1.2.3'
+
+
+def test_rev_info_update_tags_non_version_tag(out_of_date):
+ cmd_output('git', 'tag', 'latest', cwd=out_of_date.path)
+ config = make_config_from_repo(
+ out_of_date.path, rev=out_of_date.original_rev,
+ )
+ info = RevInfo.from_config(config)
+ new_info = info.update(tags_only=True, freeze=False)
+ assert new_info.rev == 'latest'
+
+
def test_rev_info_update_freeze_tag(tagged):
git_commit(cwd=tagged.path)
config = make_config_from_repo(tagged.path, rev=tagged.original_rev)
diff --git a/tests/commands/clean_test.py b/tests/commands/clean_test.py
index 955a6bc..dd8e4a5 100644
--- a/tests/commands/clean_test.py
+++ b/tests/commands/clean_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
from unittest import mock
diff --git a/tests/commands/gc_test.py b/tests/commands/gc_test.py
index 02b3694..c128e93 100644
--- a/tests/commands/gc_test.py
+++ b/tests/commands/gc_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os
import pre_commit.constants as C
diff --git a/tests/commands/hook_impl_test.py b/tests/commands/hook_impl_test.py
index 37b78bc..b0159f8 100644
--- a/tests/commands/hook_impl_test.py
+++ b/tests/commands/hook_impl_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import subprocess
import sys
from unittest import mock
diff --git a/tests/commands/init_templatedir_test.py b/tests/commands/init_templatedir_test.py
index 4e131df..64bfc8b 100644
--- a/tests/commands/init_templatedir_test.py
+++ b/tests/commands/init_templatedir_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
from unittest import mock
diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py
index 0b2e248..ae668ac 100644
--- a/tests/commands/install_uninstall_test.py
+++ b/tests/commands/install_uninstall_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
import re
@@ -5,6 +7,7 @@ import re_assert
import pre_commit.constants as C
from pre_commit import git
+from pre_commit.commands.install_uninstall import _hook_types
from pre_commit.commands.install_uninstall import CURRENT_HASH
from pre_commit.commands.install_uninstall import install
from pre_commit.commands.install_uninstall import install_hooks
@@ -25,6 +28,36 @@ from testing.util import cwd
from testing.util import git_commit
+def test_hook_types_explicitly_listed():
+ assert _hook_types(os.devnull, ['pre-push']) == ['pre-push']
+
+
+def test_hook_types_default_value_when_not_specified():
+ assert _hook_types(os.devnull, None) == ['pre-commit']
+
+
+def test_hook_types_configured(tmpdir):
+ cfg = tmpdir.join('t.cfg')
+ cfg.write('default_install_hook_types: [pre-push]\nrepos: []\n')
+
+ assert _hook_types(str(cfg), None) == ['pre-push']
+
+
+def test_hook_types_configured_nonsense(tmpdir):
+ cfg = tmpdir.join('t.cfg')
+ cfg.write('default_install_hook_types: []\nrepos: []\n')
+
+ # hopefully the user doesn't do this, but the code allows it!
+ assert _hook_types(str(cfg), None) == []
+
+
+def test_hook_types_configuration_has_error(tmpdir):
+ cfg = tmpdir.join('t.cfg')
+ cfg.write('[')
+
+ assert _hook_types(str(cfg), None) == ['pre-commit']
+
+
def test_is_not_script():
assert is_our_script('setup.py') is False
@@ -59,7 +92,7 @@ def test_install_multiple_hooks_at_once(in_git_dir, store):
install(C.CONFIG_FILE, store, hook_types=['pre-commit', 'pre-push'])
assert in_git_dir.join('.git/hooks/pre-commit').exists()
assert in_git_dir.join('.git/hooks/pre-push').exists()
- uninstall(hook_types=['pre-commit', 'pre-push'])
+ uninstall(C.CONFIG_FILE, hook_types=['pre-commit', 'pre-push'])
assert not in_git_dir.join('.git/hooks/pre-commit').exists()
assert not in_git_dir.join('.git/hooks/pre-push').exists()
@@ -77,14 +110,14 @@ def test_install_hooks_dead_symlink(in_git_dir, store):
def test_uninstall_does_not_blow_up_when_not_there(in_git_dir):
- assert uninstall(hook_types=['pre-commit']) == 0
+ assert uninstall(C.CONFIG_FILE, hook_types=['pre-commit']) == 0
def test_uninstall(in_git_dir, store):
assert not in_git_dir.join('.git/hooks/pre-commit').exists()
install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
assert in_git_dir.join('.git/hooks/pre-commit').exists()
- uninstall(hook_types=['pre-commit'])
+ uninstall(C.CONFIG_FILE, hook_types=['pre-commit'])
assert not in_git_dir.join('.git/hooks/pre-commit').exists()
@@ -414,7 +447,7 @@ def test_uninstall_restores_legacy_hooks(tempdir_factory, store):
# Now install and uninstall pre-commit
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) == 0
- assert uninstall(hook_types=['pre-commit']) == 0
+ assert uninstall(C.CONFIG_FILE, hook_types=['pre-commit']) == 0
# Make sure we installed the "old" hook correctly
ret, output = _get_commit_output(tempdir_factory, touch_file='baz')
@@ -449,7 +482,7 @@ def test_uninstall_doesnt_remove_not_our_hooks(in_git_dir):
pre_commit.write('#!/usr/bin/env bash\necho 1\n')
make_executable(pre_commit.strpath)
- assert uninstall(hook_types=['pre-commit']) == 0
+ assert uninstall(C.CONFIG_FILE, hook_types=['pre-commit']) == 0
assert pre_commit.exists()
@@ -1005,3 +1038,16 @@ def test_install_temporarily_allow_mising_config(tempdir_factory, store):
'Skipping `pre-commit`.'
)
assert expected in output
+
+
+def test_install_uninstall_default_hook_types(in_git_dir, store):
+ cfg_src = 'default_install_hook_types: [pre-commit, pre-push]\nrepos: []\n'
+ in_git_dir.join(C.CONFIG_FILE).write(cfg_src)
+
+ assert not install(C.CONFIG_FILE, store, hook_types=None)
+ assert os.access(in_git_dir.join('.git/hooks/pre-commit').strpath, os.X_OK)
+ assert os.access(in_git_dir.join('.git/hooks/pre-push').strpath, os.X_OK)
+
+ assert not uninstall(C.CONFIG_FILE, hook_types=None)
+ assert not in_git_dir.join('.git/hooks/pre-commit').exists()
+ assert not in_git_dir.join('.git/hooks/pre-push').exists()
diff --git a/tests/commands/migrate_config_test.py b/tests/commands/migrate_config_test.py
index f5eddd3..b80244e 100644
--- a/tests/commands/migrate_config_test.py
+++ b/tests/commands/migrate_config_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import pre_commit.constants as C
from pre_commit.commands.migrate_config import migrate_config
diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py
index 3a6fa2a..085b063 100644
--- a/tests/commands/run_test.py
+++ b/tests/commands/run_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
import shlex
import sys
diff --git a/tests/commands/sample_config_test.py b/tests/commands/sample_config_test.py
index 8e3a904..cf56e98 100644
--- a/tests/commands/sample_config_test.py
+++ b/tests/commands/sample_config_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
from pre_commit.commands.sample_config import sample_config
diff --git a/tests/commands/try_repo_test.py b/tests/commands/try_repo_test.py
index a157d16..0b2db7e 100644
--- a/tests/commands/try_repo_test.py
+++ b/tests/commands/try_repo_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
import re
import time