Exemplo n.º 1
0
def test_install_self_creates_venv_if_not_one_already(mocker: MockerFixture,
                                                      silent: bool, stdout,
                                                      stderr):
    mock = mocker.patch(
        "pytoil.environments.virtualenv.subprocess.run",
        autospec=True,
    )

    # Make it think there isn't a venv
    mocker.patch(
        "pytoil.environments.virtualenv.Venv.exists",
        autospec=True,
        return_value=False,
    )

    # Mock out the venv.create method
    mock_create = mocker.patch("pytoil.environments.virtualenv.Venv.create",
                               autospec=True)

    venv = Venv(root=Path("somewhere"))

    venv.install_self(silent=silent)

    mock_create.assert_called_once()

    mock.assert_called_once_with(
        [f"{venv.executable}", "-m", "pip", "install", "-e", ".[dev]"],
        cwd=venv.project_path,
        stdout=stdout,
        stderr=stderr,
    )
Exemplo n.º 2
0
def test_install_self_calls_pip_correctly(mocker: MockerFixture, silent: bool,
                                          stdout, stderr):
    mock = mocker.patch(
        "pytoil.environments.virtualenv.subprocess.run",
        autospec=True,
    )

    # Make it think there's already a venv
    mocker.patch(
        "pytoil.environments.virtualenv.Venv.exists",
        autospec=True,
        return_value=True,
    )

    venv = Venv(root=Path("somewhere"))

    venv.install_self(silent=silent)

    mock.assert_called_once_with(
        [f"{venv.executable}", "-m", "pip", "install", "-e", ".[dev]"],
        cwd=venv.project_path,
        stdout=stdout,
        stderr=stderr,
    )