@@ -66,3 +66,97 @@ def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch:
6666 "This may take a few minutes..." ,
6767 f"Using pre-commit with uv { uv } via pre-commit-uv { self } " ,
6868 ]
69+
70+
71+ test_install_with_uv_config_cases : list [tuple [str , str ]] = [
72+ (
73+ "pyproject.toml" ,
74+ """
75+ [[tool.uv.index]]
76+ name = "internal"
77+ url = "https://pypi.org/simple/"
78+ default = true
79+ """ ,
80+ ),
81+ (
82+ "uv.toml" ,
83+ """
84+ [[index]]
85+ name = "internal"
86+ url = "https://pypi.org/simple/"
87+ default = true
88+ """ ,
89+ ),
90+ ]
91+
92+
93+ @pytest .mark .parametrize (
94+ ("file_name" , "content" ),
95+ test_install_with_uv_config_cases ,
96+ )
97+ def test_install_with_uv_config (
98+ git_repo : Path ,
99+ caplog : pytest .LogCaptureFixture ,
100+ monkeypatch : pytest .MonkeyPatch ,
101+ file_name : str ,
102+ content : str ,
103+ ) -> None :
104+ (git_repo / file_name ).write_text (dedent (content ))
105+
106+ monkeypatch .setenv ("FORCE_PRE_COMMIT_UV_PATCH" , "1" )
107+
108+ import pre_commit_uv # noqa: PLC0415
109+
110+ pre_commit_uv ._patch () # noqa: SLF001
111+ main .main (["install-hooks" , "-c" , str (git_repo / precommit_file )])
112+
113+ assert caplog .messages == [
114+ "Initializing environment for https://github.com/tox-dev/pyproject-fmt." ,
115+ "Installing environment for https://github.com/tox-dev/pyproject-fmt." ,
116+ "Once installed this environment will be reused." ,
117+ "This may take a few minutes..." ,
118+ f"Using pre-commit with uv { uv } via pre-commit-uv { self } " ,
119+ ]
120+
121+
122+ test_install_with_uv_config_raises_error_cases : list [tuple [str , str ]] = [
123+ (
124+ "pyproject.toml" ,
125+ """
126+ [[tool.uv.index]]
127+ name = "internal"
128+ url = "https://pypi.example/simple/"
129+ default = true
130+ """ ,
131+ ),
132+ (
133+ "uv.toml" ,
134+ """
135+ [[index]]
136+ name = "internal"
137+ url = "https://pypi.example/simple/"
138+ default = true
139+ """ ,
140+ ),
141+ ]
142+
143+
144+ @pytest .mark .parametrize (("file_name" , "content" ), test_install_with_uv_config_raises_error_cases )
145+ def test_install_with_uv_config_raises_error (
146+ git_repo : Path ,
147+ monkeypatch : pytest .MonkeyPatch ,
148+ file_name : str ,
149+ content : str ,
150+ ) -> None :
151+ """Test to make sure that uv config is used for non default pypi repos."""
152+ (git_repo / file_name ).write_text (dedent (content ))
153+
154+ monkeypatch .setenv ("FORCE_PRE_COMMIT_UV_PATCH" , "1" )
155+
156+ import pre_commit_uv # noqa: PLC0415
157+
158+ pre_commit_uv ._patch () # noqa: SLF001
159+
160+ # would raise SystemExit due to bad config
161+ with pytest .raises (SystemExit ):
162+ main .main (["install-hooks" , "-c" , str (git_repo / precommit_file )])
0 commit comments