Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Mar 6, 2024
1 parent 2e65e58 commit 959f116
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def tmp_dir():
shutil.rmtree(path)


@pytest.fixture(autouse=True)
def force_venv(mocker):
mocker.patch.object(build.env, '_has_virtualenv', lambda: False)
@pytest.fixture(autouse=True, params=[False])
def has_virtualenv(request, mocker):
mocker.patch.object(build.env, '_has_virtualenv', lambda: request.param)


def pytest_report_header() -> str:
Expand Down
36 changes: 11 additions & 25 deletions tests/test_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations

import logging
import platform
import subprocess
Expand Down Expand Up @@ -97,7 +99,7 @@ def test_isolated_env_log(
env.install(['something'])

assert [(record.levelname, record.message) for record in caplog.records] == [
('INFO', 'Creating isolated environment: venv...'),
('INFO', 'Creating isolated environment: venv+pip...'),
('INFO', 'Installing packages in isolated environment:\n- something'),
]

Expand Down Expand Up @@ -197,27 +199,10 @@ def test_venv_or_virtualenv_impl_install_cmd_well_formed(
]


@pytest.mark.parametrize('verbosity', [0, 1, 9000])
def test_uv_impl_create_cmd_well_formed(
mocker: pytest_mock.MockerFixture,
verbosity: int,
):
run_subprocess = mocker.patch('build.env.run_subprocess')

with pytest.raises(RuntimeError, match='Virtual environment creation failed'), \
build.env.DefaultIsolatedEnv('uv') as env: # fmt: skip
(create_call,) = run_subprocess.call_args_list
cmd_tail = ['venv', env.path]
if verbosity:
cmd_tail += ['-v']
assert create_call.args[0][1:] == cmd_tail
assert not create_call.kwargs


def test_uv_impl_install_cmd_well_formed(
mocker: pytest_mock.MockerFixture,
):
with build.env.DefaultIsolatedEnv('uv') as env:
with build.env.DefaultIsolatedEnv('venv+uv') as env:
run_subprocess = mocker.patch('build.env.run_subprocess')

env.install(['foo'])
Expand All @@ -230,15 +215,16 @@ def test_uv_impl_install_cmd_well_formed(


@pytest.mark.parametrize(
('env_impl', 'backend_cls'),
('env_impl', 'backend_cls', 'has_virtualenv'),
[
('venv', build.env._VenvImplBackend),
('virtualenv', build.env._VirtualenvImplBackend),
('uv', build.env._UvImplBackend),
(None, build.env._VenvImplBackend, False),
(None, build.env._VirtualenvImplBackend, True),
('venv+uv', build.env._UvImplBackend, None),
],
indirect=('has_virtualenv',),
)
def test_venv_creation(
env_impl: build.env.EnvImpl,
def test_uv_venv_creation(
env_impl: build.env.EnvImpl | None,
backend_cls: build.env._EnvImplBackend,
):
with build.env.DefaultIsolatedEnv(env_impl) as env:
Expand Down
16 changes: 8 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
'build_package_via_sdist',
),
(
['--env-impl', 'venv'],
[cwd, out, ['wheel'], {}, True, False, 'venv'],
['--env-impl', 'venv+uv'],
[cwd, out, ['wheel'], {}, True, False, 'venv+uv'],
'build_package_via_sdist',
),
(
Expand Down Expand Up @@ -236,13 +236,13 @@ def test_build_package_via_sdist_invalid_distribution(tmp_dir, package_test_setu
pytest.param(
[],
[
'* Creating isolated environment: venv...',
'* Creating isolated environment: venv+pip...',
'* Installing packages in isolated environment:',
' - setuptools >= 42.0.0',
'* Getting build dependencies for sdist...',
'* Building sdist...',
'* Building wheel from sdist',
'* Creating isolated environment: venv...',
'* Creating isolated environment: venv+pip...',
'* Installing packages in isolated environment:',
' - setuptools >= 42.0.0',
'* Getting build dependencies for wheel...',
Expand All @@ -269,7 +269,7 @@ def test_build_package_via_sdist_invalid_distribution(tmp_dir, package_test_setu
pytest.param(
['--wheel'],
[
'* Creating isolated environment: venv...',
'* Creating isolated environment: venv+pip...',
'* Installing packages in isolated environment:',
' - setuptools >= 42.0.0',
'* Getting build dependencies for wheel...',
Expand Down Expand Up @@ -327,7 +327,7 @@ def test_output(package_test_setuptools, tmp_dir, capsys, args, output):
False,
'ERROR ',
[
'* Creating isolated environment: venv...',
'* Creating isolated environment: venv+pip...',
'* Installing packages in isolated environment:',
' - setuptools >= 42.0.0',
' - this is invalid',
Expand All @@ -337,7 +337,7 @@ def test_output(package_test_setuptools, tmp_dir, capsys, args, output):
True,
'\33[91mERROR\33[0m ',
[
'\33[1m* Creating isolated environment: venv...\33[0m',
'\33[1m* Creating isolated environment: venv+pip...\33[0m',
'\33[1m* Installing packages in isolated environment:\33[0m',
' - setuptools >= 42.0.0',
' - this is invalid',
Expand Down Expand Up @@ -429,7 +429,7 @@ def raise_called_process_err(*args, **kwargs):
assert (
stdout
== """\
* Creating isolated environment: venv...
* Creating isolated environment: venv+pip...
> test args
< stdoutput
ERROR Failed to create venv. Maybe try installing virtualenv.
Expand Down

0 comments on commit 959f116

Please sign in to comment.