@@ -102,11 +102,13 @@ def test_get_version_from_dependency_success():
102102 """Test get_version_from_dependency with valid pyproject.toml."""
103103 mock_toml_content = {
104104 "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+ }
110112 }
111113 }
112114
@@ -132,7 +134,9 @@ def test_get_version_from_dependency_missing_file():
132134@pytest .mark .benchmark
133135def test_get_version_from_dependency_missing_dependency ():
134136 """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+ }
136140
137141 with (
138142 patch ("pathlib.Path.exists" , return_value = True ),
@@ -423,3 +427,22 @@ def test_version_lists_not_empty():
423427 assert len (CLANG_TIDY_VERSIONS ) > 0
424428 assert all (isinstance (v , str ) for v in CLANG_FORMAT_VERSIONS )
425429 assert all (isinstance (v , str ) for v in CLANG_TIDY_VERSIONS )
430+
431+
432+ @pytest .mark .benchmark
433+ def test_resolve_install_with_none_default_version ():
434+ """Test _resolve_install when DEFAULT versions are None."""
435+ with (
436+ patch ("shutil.which" , return_value = None ),
437+ patch ("cpp_linter_hooks.util.DEFAULT_CLANG_FORMAT_VERSION" , None ),
438+ patch ("cpp_linter_hooks.util.DEFAULT_CLANG_TIDY_VERSION" , None ),
439+ patch (
440+ "cpp_linter_hooks.util._install_tool" ,
441+ return_value = Path ("/usr/bin/clang-format" ),
442+ ) as mock_install ,
443+ ):
444+ result = _resolve_install ("clang-format" , None )
445+ assert result == Path ("/usr/bin/clang-format" )
446+
447+ # Should fallback to hardcoded version when DEFAULT is None
448+ mock_install .assert_called_once_with ("clang-format" , None )
0 commit comments