-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_pre_commit.py
More file actions
150 lines (126 loc) · 5.08 KB
/
test_pre_commit.py
File metadata and controls
150 lines (126 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from pathlib import Path
from usethis._config import usethis_config
from usethis._config_file import files_manager
from usethis._integrations.pre_commit import schema
from usethis._test import change_cwd
from usethis._tool.pre_commit import PreCommitConfig
from usethis._types.backend import BackendEnum
class TestFromSystemHook:
def test_uv_backend_entry_prefix(self, tmp_path: Path):
# Act
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="my-hook",
entry="my-cmd",
)
# Assert
assert len(config.repo_configs) == 1
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert len(repo.hooks) == 1
assert repo.hooks[0].entry == "uv run --frozen --offline my-cmd"
def test_none_backend_entry_no_prefix(self, tmp_path: Path):
# Act
with (
change_cwd(tmp_path),
files_manager(),
usethis_config.set(backend=BackendEnum.none),
):
config = PreCommitConfig.from_system_hook(
hook_id="my-hook",
entry="my-cmd",
)
# Assert
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert repo.hooks[0].entry == "my-cmd"
def test_hook_id(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert repo.hooks[0].id == "test-hook"
def test_name_equals_hook_id(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert repo.hooks[0].name == "test-hook"
def test_requires_venv_is_true(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
assert config.repo_configs[0].requires_venv is True
def test_inform_how_to_use_on_migrate_is_false(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
assert config.inform_how_to_use_on_migrate is False
def test_pass_filenames_is_false(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert repo.hooks[0].pass_filenames is False
def test_always_run_is_true(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert repo.hooks[0].always_run is True
def test_system_language_set(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert repo.hooks[0].language == schema.Language("system")
def test_local_repo(self, tmp_path: Path):
with change_cwd(tmp_path), files_manager():
config = PreCommitConfig.from_system_hook(
hook_id="test-hook",
entry="test-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.repo == "local"
def test_poetry_backend_entry_prefix(self, tmp_path: Path):
with (
change_cwd(tmp_path),
files_manager(),
usethis_config.set(backend=BackendEnum.poetry),
):
config = PreCommitConfig.from_system_hook(
hook_id="my-hook",
entry="my-cmd",
)
repo = config.repo_configs[0].repo
assert isinstance(repo, schema.LocalRepo)
assert repo.hooks is not None
assert len(repo.hooks) == 1
assert repo.hooks[0].entry == "poetry run my-cmd"