@@ -24,21 +24,21 @@ def component_manager(components_dir):
24
24
def pre_commit_component (component_manager ):
25
25
"""Get the Pre-commit component."""
26
26
components = component_manager ._discover_components ()
27
- return components .get (' pre_commit' )
27
+ return components .get (" pre_commit" )
28
28
29
29
30
30
def test_pre_commit_component_exists (pre_commit_component ):
31
31
"""Test that Pre-commit component exists and has correct metadata."""
32
32
assert pre_commit_component is not None
33
- assert pre_commit_component .name == ' pre_commit'
34
- assert pre_commit_component .display_name == ' Pre-commit Hooks'
35
- assert ' Pre-commit hooks' in pre_commit_component .description
36
- assert pre_commit_component .category == ' quality'
33
+ assert pre_commit_component .name == " pre_commit"
34
+ assert pre_commit_component .display_name == " Pre-commit Hooks"
35
+ assert " Pre-commit hooks" in pre_commit_component .description
36
+ assert pre_commit_component .category == " quality"
37
37
38
38
39
39
def test_pre_commit_dependencies (pre_commit_component ):
40
40
"""Test that Pre-commit has correct dependencies."""
41
- expected_dependencies = {' task_automation' , ' github_actions' }
41
+ expected_dependencies = {" task_automation" , " github_actions" }
42
42
assert set (pre_commit_component .dependencies ) == expected_dependencies
43
43
44
44
@@ -49,9 +49,7 @@ def test_pre_commit_no_conflicts(pre_commit_component):
49
49
50
50
def test_pre_commit_cookiecutter_vars (pre_commit_component ):
51
51
"""Test that Pre-commit sets correct cookiecutter variables."""
52
- expected_vars = {
53
- 'use_pre_commit' : True
54
- }
52
+ expected_vars = {"use_pre_commit" : True }
55
53
56
54
for key , expected_value in expected_vars .items ():
57
55
assert key in pre_commit_component .cookiecutter_vars
@@ -60,11 +58,9 @@ def test_pre_commit_cookiecutter_vars(pre_commit_component):
60
58
61
59
def test_pre_commit_files (pre_commit_component ):
62
60
"""Test that Pre-commit component has correct files."""
63
- expected_files = {
64
- '.pre-commit-config.yaml'
65
- }
61
+ expected_files = {".pre-commit-config.yaml" }
66
62
67
- actual_files = {file_config [' dest' ] for file_config in pre_commit_component .files }
63
+ actual_files = {file_config [" dest" ] for file_config in pre_commit_component .files }
68
64
assert actual_files == expected_files
69
65
70
66
@@ -73,108 +69,108 @@ def test_pre_commit_config_content(components_dir):
73
69
config_path = components_dir / "pre_commit" / "files" / ".pre-commit-config.yaml.j2"
74
70
assert config_path .exists ()
75
71
76
- content = config_path .read_text (encoding = ' utf-8' )
72
+ content = config_path .read_text (encoding = " utf-8" )
77
73
78
74
# Check for conditional uv usage
79
- assert ' use_uv' in content
80
- assert ' uv-pre-commit' in content
81
- assert ' uv-lock' in content
75
+ assert " use_uv" in content
76
+ assert " uv-pre-commit" in content
77
+ assert " uv-lock" in content
82
78
83
79
# Check for conditional GitHub Actions integration
84
- assert ' use_github_actions' in content
85
- assert ' check-github-workflows' in content
86
- assert ' actionlint' in content
80
+ assert " use_github_actions" in content
81
+ assert " check-github-workflows" in content
82
+ assert " actionlint" in content
87
83
88
84
# Check for YAML formatting
89
- assert ' yamlfmt' in content
85
+ assert " yamlfmt" in content
90
86
91
87
92
88
def test_component_yaml_syntax (components_dir ):
93
89
"""Test that component.yaml has valid syntax."""
94
90
component_yaml = components_dir / "pre_commit" / "component.yaml"
95
91
assert component_yaml .exists ()
96
92
97
- with open (component_yaml , encoding = ' utf-8' ) as f :
93
+ with open (component_yaml , encoding = " utf-8" ) as f :
98
94
config = yaml .safe_load (f )
99
95
100
96
# Validate required fields
101
- required_fields = [' name' , ' display_name' , ' description' , ' category' , ' dependencies' , ' files' ]
97
+ required_fields = [" name" , " display_name" , " description" , " category" , " dependencies" , " files" ]
102
98
for field in required_fields :
103
99
assert field in config
104
100
105
101
# Validate dependencies
106
- assert ' task_automation' in config [' dependencies' ]
107
- assert ' github_actions' in config [' dependencies' ]
102
+ assert " task_automation" in config [" dependencies" ]
103
+ assert " github_actions" in config [" dependencies" ]
108
104
109
105
# Validate files structure
110
- for file_config in config [' files' ]:
111
- assert ' src' in file_config
112
- assert ' dest' in file_config
106
+ for file_config in config [" files" ]:
107
+ assert " src" in file_config
108
+ assert " dest" in file_config
113
109
114
110
115
111
def test_file_templates_exist (components_dir ):
116
112
"""Test that all referenced template files exist."""
117
113
component_yaml = components_dir / "pre_commit" / "component.yaml"
118
114
119
- with open (component_yaml , encoding = ' utf-8' ) as f :
115
+ with open (component_yaml , encoding = " utf-8" ) as f :
120
116
config = yaml .safe_load (f )
121
117
122
118
files_dir = components_dir / "pre_commit" / "files"
123
119
124
- for file_config in config [' files' ]:
125
- src_file = files_dir / file_config [' src' ]
120
+ for file_config in config [" files" ]:
121
+ src_file = files_dir / file_config [" src" ]
126
122
assert src_file .exists (), f"Template file not found: { src_file } "
127
123
128
124
129
125
def test_uv_integration (components_dir ):
130
126
"""Test that pre-commit config integrates with uv."""
131
127
config_path = components_dir / "pre_commit" / "files" / ".pre-commit-config.yaml.j2"
132
- content = config_path .read_text (encoding = ' utf-8' )
128
+ content = config_path .read_text (encoding = " utf-8" )
133
129
134
130
# Should include uv-specific hooks
135
- assert ' uv-pre-commit' in content
136
- assert ' uv-lock' in content
131
+ assert " uv-pre-commit" in content
132
+ assert " uv-lock" in content
137
133
138
134
139
135
def test_conditional_uv_usage (components_dir ):
140
136
"""Test conditional uv usage in pre-commit hooks."""
141
137
config_path = components_dir / "pre_commit" / "files" / ".pre-commit-config.yaml.j2"
142
- content = config_path .read_text (encoding = ' utf-8' )
138
+ content = config_path .read_text (encoding = " utf-8" )
143
139
144
140
# Should have conditional blocks for uv
145
- assert ' if cookiecutter.use_uv' in content
146
- assert ' uv-lock' in content
141
+ assert " if cookiecutter.use_uv" in content
142
+ assert " uv-lock" in content
147
143
148
144
# Should have conditional ending
149
- assert ' endif' in content
145
+ assert " endif" in content
150
146
151
147
152
148
def test_github_actions_integration (components_dir ):
153
149
"""Test GitHub Actions integration in pre-commit config."""
154
150
config_path = components_dir / "pre_commit" / "files" / ".pre-commit-config.yaml.j2"
155
- content = config_path .read_text (encoding = ' utf-8' )
151
+ content = config_path .read_text (encoding = " utf-8" )
156
152
157
153
# Should have conditional GitHub Actions specific hooks
158
- assert ' if cookiecutter.use_github_actions' in content
159
- assert ' check-github-workflows' in content
160
- assert ' actionlint' in content
154
+ assert " if cookiecutter.use_github_actions" in content
155
+ assert " check-github-workflows" in content
156
+ assert " actionlint" in content
161
157
162
158
163
159
def test_yamlfmt_integration (components_dir ):
164
160
"""Test YAML formatting integration."""
165
161
config_path = components_dir / "pre_commit" / "files" / ".pre-commit-config.yaml.j2"
166
- content = config_path .read_text (encoding = ' utf-8' )
162
+ content = config_path .read_text (encoding = " utf-8" )
167
163
168
164
# Should include yamlfmt for YAML formatting
169
- assert ' yamlfmt' in content
170
- assert ' google/yamlfmt' in content
165
+ assert " yamlfmt" in content
166
+ assert " google/yamlfmt" in content
171
167
172
168
173
169
def test_actionlint_integration (components_dir ):
174
170
"""Test GitHub Actions linting integration."""
175
171
config_path = components_dir / "pre_commit" / "files" / ".pre-commit-config.yaml.j2"
176
- content = config_path .read_text (encoding = ' utf-8' )
172
+ content = config_path .read_text (encoding = " utf-8" )
177
173
178
174
# Should include actionlint for GitHub Actions validation
179
- assert ' actionlint' in content
180
- assert ' rhysd/actionlint' in content
175
+ assert " actionlint" in content
176
+ assert " rhysd/actionlint" in content
0 commit comments