| 
 | 1 | +from conan.tools.system import PipEnv  | 
 | 2 | +from unittest.mock import patch  | 
 | 3 | +import pytest  | 
 | 4 | +from conan.errors import ConanException  | 
 | 5 | +from conan.internal.model.settings import Settings  | 
 | 6 | +from conan.test.utils.mocks import ConanFileMock  | 
 | 7 | + | 
 | 8 | + | 
 | 9 | +@patch('shutil.which')  | 
 | 10 | +def test_pipenv_conf(mock_shutil_which):  | 
 | 11 | +    conanfile = ConanFileMock()  | 
 | 12 | +    conanfile.settings = Settings()  | 
 | 13 | +    conanfile.conf.define("tools.system.pipenv:python_interpreter", "/python/interpreter/from/config")  | 
 | 14 | +    result = "/python/interpreter/from/config -m venv"  | 
 | 15 | +    pipenv = PipEnv(conanfile, "testenv")  | 
 | 16 | + | 
 | 17 | +    def fake_run(command, win_bash=False, subsystem=None, env=None, ignore_errors=False, quiet=False):  | 
 | 18 | +        assert result in command  | 
 | 19 | +        return 100  | 
 | 20 | +    conanfile.run = fake_run  | 
 | 21 | +    pipenv._create_venv()  | 
 | 22 | +    mock_shutil_which.assert_not_called()  | 
 | 23 | + | 
 | 24 | + | 
 | 25 | +@patch('shutil.which')  | 
 | 26 | +def test_pipenv_error_message(mock_shutil_which):  | 
 | 27 | +    conanfile = ConanFileMock()  | 
 | 28 | +    conanfile.settings = Settings()  | 
 | 29 | +    mock_shutil_which.return_value = None  | 
 | 30 | +    with pytest.raises(ConanException) as exc_info:  | 
 | 31 | +        pipenv = PipEnv(conanfile, "testenv")  | 
 | 32 | +        pipenv._create_venv()  | 
 | 33 | +    assert "install Python system-wide or set the 'tools.system.pipenv:python_interpreter' conf" in exc_info.value.args[0]  | 
 | 34 | + | 
 | 35 | + | 
 | 36 | +def test_pipenv_creation_error_message():  | 
 | 37 | +    conanfile = ConanFileMock()  | 
 | 38 | +    conanfile.settings = Settings()  | 
 | 39 | +    conanfile.conf.define("tools.system.pipenv:python_interpreter", "/python/interpreter/from/config")  | 
 | 40 | +    pipenv = PipEnv(conanfile, "testenv")  | 
 | 41 | + | 
 | 42 | +    def fake_run(command, win_bash=False, subsystem=None, env=None, ignore_errors=False, quiet=False):  | 
 | 43 | +        raise ConanException("fake error message")  | 
 | 44 | +    conanfile.run = fake_run  | 
 | 45 | +    with pytest.raises(ConanException) as exc_info:  | 
 | 46 | +        pipenv._create_venv()  | 
 | 47 | +    assert "using '/python/interpreter/from/config': fake error message" in exc_info.value.args[0]  | 
0 commit comments