Пример #1
0
 def test_install_version_undefined(
     self, mocker: MockerFixture, tmp_path: Path
 ) -> None:
     """Test install."""
     mocker.patch.object(TFEnvManager, "version", None)
     tfenv = TFEnvManager(tmp_path)
     with pytest.raises(
         ValueError, match=r"^version not provided and unable to find .*"
     ):
         tfenv.install()
Пример #2
0
    def test_install_already_installed(self, mock_download,
                                       mock_available_versions, monkeypatch,
                                       tmp_path):
        """Test install with version already installed."""
        mock_available_versions.return_value = ["0.12.0"]
        monkeypatch.setattr(TFEnvManager, "versions_dir", tmp_path)
        tfenv = TFEnvManager(tmp_path)
        (tfenv.versions_dir / "0.12.0").mkdir()

        assert tfenv.install("0.12.0")
        mock_available_versions.assert_not_called()
        mock_download.assert_not_called()
        assert tfenv.current_version == "0.12.0"

        assert tfenv.install(r"0\.12\..*")  # regex does not match dir
Пример #3
0
    def test_install_already_installed(self, mocker: MockerFixture,
                                       tmp_path: Path) -> None:
        """Test install with version already installed."""
        mock_available_versions = mocker.patch(
            f"{MODULE}.get_available_tf_versions", return_value=["0.12.0"])
        mock_download = mocker.patch(f"{MODULE}.download_tf_release")
        mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
        tfenv = TFEnvManager(tmp_path)
        (tfenv.versions_dir / "0.12.0").mkdir()

        assert tfenv.install("0.12.0")
        mock_available_versions.assert_not_called()
        mock_download.assert_not_called()
        assert tfenv.current_version == "0.12.0"

        assert tfenv.install(r"0\.12\..*")  # regex does not match dir
Пример #4
0
    def test_install_no_version(self, tmp_path):
        """Test install with no version available."""
        tfenv = TFEnvManager(tmp_path)

        with pytest.raises(ValueError) as excinfo:
            assert tfenv.install()
        assert str(excinfo.value) == (
            "version not provided and unable to find a .terraform-version file"
        )
Пример #5
0
    def test_install_latest(self, mock_download, mock_available_versions,
                            monkeypatch, tmp_path):
        """Test install latest."""
        mock_available_versions.return_value = ["0.12.0", "0.11.5"]
        monkeypatch.setattr(TFEnvManager, "versions_dir", tmp_path)
        tfenv = TFEnvManager(tmp_path)

        assert tfenv.install("latest")
        mock_available_versions.assert_called_once_with(False)
        mock_download.assert_called_once_with("0.12.0", tfenv.versions_dir,
                                              tfenv.command_suffix)
        assert tfenv.current_version == "0.12.0"

        assert tfenv.install("latest:0.11.5")
        mock_available_versions.assert_called_with(False)
        mock_download.assert_called_with("0.11.5", tfenv.versions_dir,
                                         tfenv.command_suffix)
        assert tfenv.current_version == "0.11.5"
Пример #6
0
    def test_install(self, mock_download, mock_available_versions, monkeypatch,
                     tmp_path):
        """Test install."""
        mock_available_versions.return_value = ["0.12.0", "0.11.5"]
        monkeypatch.setattr(TFEnvManager, "versions_dir", tmp_path)
        monkeypatch.setattr(TFEnvManager, "get_version_from_file",
                            MagicMock(return_value="0.11.5"))
        tfenv = TFEnvManager(tmp_path)

        assert tfenv.install("0.12.0")
        mock_available_versions.assert_called_once_with(True)
        mock_download.assert_called_once_with("0.12.0", tfenv.versions_dir,
                                              tfenv.command_suffix)
        assert tfenv.current_version == "0.12.0"

        assert tfenv.install()
        mock_download.assert_called_with("0.11.5", tfenv.versions_dir,
                                         tfenv.command_suffix)
        assert tfenv.current_version == "0.11.5"
Пример #7
0
    def test_install_latest(self, mocker: MockerFixture,
                            tmp_path: Path) -> None:
        """Test install latest."""
        mock_available_versions = mocker.patch(
            f"{MODULE}.get_available_tf_versions",
            return_value=["0.12.0", "0.11.5"])
        mock_download = mocker.patch(f"{MODULE}.download_tf_release")
        mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
        tfenv = TFEnvManager(tmp_path)

        assert tfenv.install("latest")
        mock_available_versions.assert_called_once_with(False)
        mock_download.assert_called_once_with("0.12.0", tfenv.versions_dir,
                                              tfenv.command_suffix)
        assert tfenv.current_version == "0.12.0"

        assert tfenv.install("latest:0.11.5")
        mock_available_versions.assert_called_with(False)
        mock_download.assert_called_with("0.11.5", tfenv.versions_dir,
                                         tfenv.command_suffix)
        assert tfenv.current_version == "0.11.5"
Пример #8
0
 def test_install_already_installed(
     self, mocker: MockerFixture, tmp_path: Path
 ) -> None:
     """Test install."""
     version = VersionTuple(0, 15, 5)
     mocker.patch.object(TFEnvManager, "version", version)
     mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
     mock_download = mocker.patch(f"{MODULE}.download_tf_release")
     tfenv = TFEnvManager(tmp_path)
     (tfenv.versions_dir / str(version)).mkdir()
     assert tfenv.install() == str(tfenv.bin)
     mock_download.assert_not_called()
Пример #9
0
 def test_install(self, mocker: MockerFixture, tmp_path: Path) -> None:
     """Test install."""
     version = VersionTuple(0, 15, 5)
     mocker.patch.object(TFEnvManager, "version", version)
     mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
     mock_download = mocker.patch(f"{MODULE}.download_tf_release")
     tfenv = TFEnvManager(tmp_path)
     (tfenv.versions_dir / "0.15.2").mkdir()
     assert tfenv.install() == str(tfenv.bin)
     mock_download.assert_called_once_with(
         str(version), tfenv.versions_dir, tfenv.command_suffix
     )
Пример #10
0
    def test_install_unavailable(self, mock_download, mock_available_versions,
                                 monkeypatch, tmp_path):
        """Test install."""
        mock_available_versions.return_value = []
        monkeypatch.setattr(TFEnvManager, "versions_dir", tmp_path)
        tfenv = TFEnvManager(tmp_path)

        with pytest.raises(SystemExit) as excinfo:
            assert tfenv.install("0.12.0")
        assert excinfo.value.code == 1
        mock_available_versions.assert_called_once_with(True)
        mock_download.assert_not_called()
        assert not tfenv.current_version
Пример #11
0
    def test_install_min_required(self, mock_download, mock_available_versions,
                                  monkeypatch, tmp_path):
        """Test install min_required."""
        mock_available_versions.return_value = ["0.12.0"]
        monkeypatch.setattr(TFEnvManager, "versions_dir", tmp_path)
        monkeypatch.setattr(TFEnvManager, "get_min_required",
                            MagicMock(return_value="0.12.0"))
        tfenv = TFEnvManager(tmp_path)

        assert tfenv.install("min-required")
        mock_available_versions.assert_called_once_with(True)
        mock_download.assert_called_once_with("0.12.0", tfenv.versions_dir,
                                              tfenv.command_suffix)
        assert tfenv.current_version == "0.12.0"
        tfenv.get_min_required.assert_called_once_with()  # pylint: disable=no-member
Пример #12
0
    def test_install_unavailable(self, mocker: MockerFixture,
                                 tmp_path: Path) -> None:
        """Test install."""
        mock_available_versions = mocker.patch(
            f"{MODULE}.get_available_tf_versions", return_value=[])
        mock_download = mocker.patch(f"{MODULE}.download_tf_release")
        mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
        tfenv = TFEnvManager(tmp_path)

        with pytest.raises(SystemExit) as excinfo:
            assert tfenv.install("0.12.0")
        assert excinfo.value.code == 1
        mock_available_versions.assert_called_once_with(True)
        mock_download.assert_not_called()
        assert not tfenv.current_version
Пример #13
0
 def test_install_set_version(self, mocker: MockerFixture, tmp_path: Path) -> None:
     """Test install set version."""
     version = VersionTuple(0, 15, 5)
     mocker.patch.object(TFEnvManager, "version", version)
     mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
     mock_download = mocker.patch(f"{MODULE}.download_tf_release")
     mock_set_version = mocker.patch.object(
         TFEnvManager, "set_version", return_value=None
     )
     tfenv = TFEnvManager(tmp_path)
     assert tfenv.install(str(version))
     mock_download.assert_called_once_with(
         str(version), tfenv.versions_dir, tfenv.command_suffix
     )
     mock_set_version.assert_called_once_with(str(version))
Пример #14
0
    def test_install_min_required(self, mocker: MockerFixture,
                                  tmp_path: Path) -> None:
        """Test install min_required."""
        mock_available_versions = mocker.patch(
            f"{MODULE}.get_available_tf_versions", return_value=["0.12.0"])
        mock_download = mocker.patch(f"{MODULE}.download_tf_release")
        mocker.patch.object(TFEnvManager, "versions_dir", tmp_path)
        mocker.patch.object(TFEnvManager, "get_min_required",
                            MagicMock(return_value="0.12.0"))
        tfenv = TFEnvManager(tmp_path)

        assert tfenv.install("min-required")
        mock_available_versions.assert_called_once_with(True)
        mock_download.assert_called_once_with("0.12.0", tfenv.versions_dir,
                                              tfenv.command_suffix)
        assert tfenv.current_version == "0.12.0"
        tfenv.get_min_required.assert_called_once_with()  # pylint: disable=no-member