@@ -102,11 +102,13 @@ def test_get_version_from_dependency_success():
102
102
"""Test get_version_from_dependency with valid pyproject.toml."""
103
103
mock_toml_content = {
104
104
"project" : {
105
- "dependencies" : [
106
- "clang-format==20.1.7" ,
107
- "clang-tidy==20.1.0" ,
108
- "other-package==1.0.0" ,
109
- ]
105
+ "optional-dependencies" : {
106
+ "tools" : [
107
+ "clang-format==20.1.7" ,
108
+ "clang-tidy==20.1.0" ,
109
+ "other-package==1.0.0" ,
110
+ ]
111
+ }
110
112
}
111
113
}
112
114
@@ -132,7 +134,9 @@ def test_get_version_from_dependency_missing_file():
132
134
@pytest .mark .benchmark
133
135
def test_get_version_from_dependency_missing_dependency ():
134
136
"""Test get_version_from_dependency with missing dependency."""
135
- mock_toml_content = {"project" : {"dependencies" : ["other-package==1.0.0" ]}}
137
+ mock_toml_content = {
138
+ "project" : {"optional-dependencies" : {"tools" : ["other-package==1.0.0" ]}}
139
+ }
136
140
137
141
with (
138
142
patch ("pathlib.Path.exists" , return_value = True ),
@@ -155,6 +159,30 @@ def test_get_version_from_dependency_malformed_toml():
155
159
assert result is None
156
160
157
161
162
+ @pytest .mark .benchmark
163
+ def test_get_version_from_dependency_fallback_to_dependencies ():
164
+ """Test get_version_from_dependency falls back to project.dependencies."""
165
+ mock_toml_content = {
166
+ "project" : {
167
+ "dependencies" : [
168
+ "clang-format==20.1.7" ,
169
+ "clang-tidy==20.1.0" ,
170
+ "other-package==1.0.0" ,
171
+ ]
172
+ }
173
+ }
174
+
175
+ with (
176
+ patch ("pathlib.Path.exists" , return_value = True ),
177
+ patch ("cpp_linter_hooks.util.tomllib.load" , return_value = mock_toml_content ),
178
+ ):
179
+ result = get_version_from_dependency ("clang-format" )
180
+ assert result == "20.1.7"
181
+
182
+ result = get_version_from_dependency ("clang-tidy" )
183
+ assert result == "20.1.0"
184
+
185
+
158
186
# Tests for _resolve_version
159
187
@pytest .mark .benchmark
160
188
@pytest .mark .parametrize (
0 commit comments