Esempio n. 1
0
def test_create_from_yml_raises_if_conda_not_installed(mocker: MockerFixture):
    conda = Conda(root=Path("somewhere"), environment_name="test")

    # Ensure shutil.which returns None
    mocker.patch(
        "pytoil.environments.conda.shutil.which",
        autospec=True,
        return_value=None,
    )

    with pytest.raises(CondaNotInstalledError):
        conda.create_from_yml(Path("somewhere"), conda="notconda")
Esempio n. 2
0
def test_create_from_yml_raises_on_bad_yml_file(
        mocker: MockerFixture, bad_temp_environment_yml: Path):

    # Ensure shutil.which doesn't fail
    mocker.patch(
        "pytoil.environments.conda.shutil.which",
        autospec=True,
        return_value="notconda",
    )

    conda = Conda(root=Path("somewhere"),
                  environment_name="test",
                  conda="notconda")

    with pytest.raises(BadEnvironmentFileError):
        conda.create_from_yml(bad_temp_environment_yml.parent,
                              conda="notconda")
Esempio n. 3
0
def test_create_from_yml_raises_if_environment_already_exists(
        mocker: MockerFixture, temp_environment_yml: Path):
    # Ensure shutil.which doesn't fail
    mocker.patch(
        "pytoil.environments.conda.shutil.which",
        autospec=True,
        return_value="notconda",
    )

    # Make it think the environment already exists
    mocker.patch("pytoil.environments.conda.Conda.exists",
                 autospec=True,
                 return_value=True)

    conda = Conda(root=Path("somewhere"),
                  environment_name="test",
                  conda="notconda")

    with pytest.raises(EnvironmentAlreadyExistsError):
        conda.create_from_yml(project_path=temp_environment_yml.parent,
                              conda="notconda")
Esempio n. 4
0
def test_create_from_yml_correctly_calls_subprocess(mocker: MockerFixture,
                                                    temp_environment_yml: Path,
                                                    silent: bool, stdout,
                                                    stderr):

    # Mock out the actual call to conda
    mock_subprocess = mocker.patch("pytoil.environments.conda.subprocess.run",
                                   autospec=True)

    # Give it a fake envs dir
    mocker.patch(
        "pytoil.environments.conda.Conda.get_envs_dir",
        autospec=True,
        return_value=Path("/Users/testyconda3/envs"),
    )

    # Ensure shutil.which doesn't fail
    mocker.patch(
        "pytoil.environments.conda.shutil.which",
        autospec=True,
        return_value="conda",
    )

    conda = Conda(root=Path("somewhere"),
                  environment_name="test",
                  conda="notconda")

    conda.create_from_yml(project_path=temp_environment_yml.parent,
                          conda="notconda",
                          silent=silent)

    mock_subprocess.assert_called_once_with(
        [
            "notconda", "env", "create", "--file",
            f"{temp_environment_yml.resolve()}"
        ],
        cwd=temp_environment_yml.resolve().parent,
        stdout=stdout,
        stderr=stderr,
    )