@@ -286,21 +286,27 @@ def test_install_short_circuits(
286286
287287
288288@pytest .mark .parametrize ('verbosity' , range (3 ))
289- @pytest .mark .parametrize ('constraints ' , [[], [ 'foo' ] ])
289+ @pytest .mark .parametrize ('constraints_txt ' , ['' , 'foo' ])
290290@pytest .mark .parametrize ('fresh' , [False , True ])
291291@pytest .mark .usefixtures ('local_pip' )
292292def test_default_impl_install_cmd_well_formed (
293+ tmp_path : Path ,
293294 mocker : pytest_mock .MockerFixture ,
294295 verbosity : int ,
295- constraints : list [ str ] ,
296+ constraints_txt : str ,
296297 fresh : bool ,
297298) -> None :
298299 mocker .patch .object (_ctx , 'verbosity' , verbosity )
299300
301+ constraints_txt_path = None
302+ if constraints_txt :
303+ constraints_txt_path = tmp_path .joinpath ('constraints.txt' )
304+ constraints_txt_path .write_text (constraints_txt , encoding = 'utf-8' )
305+
300306 with build .env .DefaultIsolatedEnv () as env :
301307 run_subprocess = mocker .patch ('build.env.run_subprocess' )
302308
303- env .install (['some' , 'requirements' ], constraints , _fresh = fresh )
309+ env .install (['some' , 'requirements' ], constraints_txt_path , _fresh = fresh )
304310
305311 run_subprocess .assert_called_once_with (
306312 [
@@ -316,29 +322,35 @@ def test_default_impl_install_cmd_well_formed(
316322 '--no-input' ,
317323 '-r' ,
318324 mocker .ANY ,
319- * (['-c' , mocker . ANY ] if constraints else []),
325+ * (['-c' , str ( constraints_txt_path ) ] if constraints_txt_path else []),
320326 ],
321327 env = mocker .ANY ,
322328 )
323329
324330
325331@pytest .mark .parametrize ('verbosity' , range (3 ))
326- @pytest .mark .parametrize ('constraints ' , [[], [ 'foo' ] ])
332+ @pytest .mark .parametrize ('constraints_txt ' , ['' , 'foo' ])
327333@pytest .mark .parametrize ('fresh' , [False , True ])
328334@pytest .mark .skipif (IS_PYPY , reason = 'uv cannot find PyPy executable' )
329335@pytest .mark .skipif (MISSING_UV , reason = 'uv executable not found' )
330336def test_uv_impl_install_cmd_well_formed ( # pragma: no cover -- uv tests are skipped on PyPy, covered on CPython
337+ tmp_path : Path ,
331338 mocker : pytest_mock .MockerFixture ,
332339 verbosity : int ,
333- constraints : list [ str ] ,
340+ constraints_txt : str ,
334341 fresh : bool ,
335342) -> None :
336343 mocker .patch .object (_ctx , 'verbosity' , verbosity )
337344
345+ constraints_txt_path = None
346+ if constraints_txt :
347+ constraints_txt_path = tmp_path .joinpath ('constraints.txt' )
348+ constraints_txt_path .write_text (constraints_txt , encoding = 'utf-8' )
349+
338350 with build .env .DefaultIsolatedEnv (installer = 'uv' ) as env :
339351 run_subprocess = mocker .patch ('build.env.run_subprocess' )
340352
341- env .install (['some' , 'requirements' ], constraints , _fresh = fresh )
353+ env .install (['some' , 'requirements' ], constraints_txt_path , _fresh = fresh )
342354
343355 run_subprocess .assert_called_once_with (
344356 [
@@ -350,7 +362,7 @@ def test_uv_impl_install_cmd_well_formed( # pragma: no cover -- uv tests are sk
350362 'requirements' ,
351363 '--python' ,
352364 mocker .ANY ,
353- * (['-c' , mocker . ANY ] if constraints else []),
365+ * (['-c' , str ( constraints_txt_path ) ] if constraints_txt_path else []),
354366 ],
355367 env = mocker .ANY ,
356368 )
@@ -360,7 +372,7 @@ def test_uv_impl_install_cmd_well_formed( # pragma: no cover -- uv tests are sk
360372
361373@pytest .mark .usefixtures ('local_pip' )
362374def test_default_impl_install_files_line_endings_not_doubled (mocker : pytest_mock .MockerFixture ) -> None :
363- # The requirements/constraints files are opened in text mode, which translates every
375+ # The requirements files are opened in text mode, which translates every
364376 # '\n' written to os.linesep -- '\r\n' on disk is correct on Windows. Joining with
365377 # os.linesep first (instead of '\n') would double-translate there, turning '\r\n' into
366378 # '\r\r\n'. Read back as bytes, before the files are deleted by the
@@ -372,38 +384,13 @@ def fake_run_subprocess(cmd: list[str], **_kwargs: object) -> None:
372384 for arg in args :
373385 if arg == '-r' :
374386 written ['requirements' ] = Path (next (args )).read_bytes ()
375- elif arg == '-c' :
376- written ['constraints' ] = Path (next (args )).read_bytes ()
377387
378388 with build .env .DefaultIsolatedEnv () as env :
379389 mocker .patch ('build.env.run_subprocess' , side_effect = fake_run_subprocess )
380- env .install (['some' , 'requirements' ], [ 'a-constraint' , 'b-constraint' ] )
390+ env .install (['some' , 'requirements' ])
381391
382392 assert b'\r \r ' not in written ['requirements' ]
383393 assert written ['requirements' ].splitlines () == [b'some' , b'requirements' ]
384- assert b'\r \r ' not in written ['constraints' ]
385- assert written ['constraints' ].splitlines () == [b'a-constraint' , b'b-constraint' ]
386-
387-
388- @pytest .mark .skipif (IS_PYPY , reason = 'uv cannot find PyPy executable' )
389- @pytest .mark .skipif (MISSING_UV , reason = 'uv executable not found' )
390- def test_uv_impl_install_files_line_endings_not_doubled ( # pragma: no cover -- skipped on PyPy, covered on CPython
391- mocker : pytest_mock .MockerFixture ,
392- ) -> None :
393- written : dict [str , bytes ] = {}
394-
395- def fake_run_subprocess (cmd : list [str ], ** _kwargs : object ) -> None :
396- args = iter (cmd )
397- for arg in args :
398- if arg == '-c' :
399- written ['constraints' ] = Path (next (args )).read_bytes ()
400-
401- with build .env .DefaultIsolatedEnv (installer = 'uv' ) as env :
402- mocker .patch ('build.env.run_subprocess' , side_effect = fake_run_subprocess )
403- env .install (['some' , 'requirements' ], ['a-constraint' , 'b-constraint' ])
404-
405- assert b'\r \r ' not in written ['constraints' ]
406- assert written ['constraints' ].splitlines () == [b'a-constraint' , b'b-constraint' ]
407394
408395
409396@pytest .mark .usefixtures ('local_pip' )
0 commit comments