Raise exception for unsupported R versions

pull/772/head
Tim Head 2019-09-08 16:02:53 +02:00
rodzic c50983532e
commit d8c8259343
2 zmienionych plików z 21 dodań i 3 usunięć

Wyświetl plik

@ -65,6 +65,7 @@ class RBuildPack(PythonBuildPack):
version.
"""
version_map = {
"3.4": "3.4",
"3.5": "3.5.3-1bionic",
"3.5.0": "3.5.0-1bionic",
"3.5.1": "3.5.1-2bionic",
@ -81,10 +82,13 @@ class RBuildPack(PythonBuildPack):
parts = self.runtime.split("-")
if len(parts) == 5:
r_version = parts[1]
if r_version not in version_map:
raise ValueError(
"Version '{}' of R is not supported.".format(r_version)
)
# see if we need to translate the specified version into a
# "full" version string
self._r_version = version_map.get(r_version, r_version)
# translate to the full version string
self._r_version = version_map.get(r_version)
return self._r_version

Wyświetl plik

@ -5,6 +5,20 @@ import pytest
from repo2docker import buildpacks
def test_unsupported_version(tmpdir):
tmpdir.chdir()
with open("runtime.txt", "w") as f:
f.write("r-3.8-2019-01-01")
r = buildpacks.RBuildPack()
with pytest.raises(ValueError) as excinfo:
# access the property to trigger the exception
_ = r.r_version
# check the version is mentioned in the exception
assert "'3.8'" in str(excinfo.value)
@pytest.mark.parametrize(
"runtime_version, expected", [("", "3.6"), ("3.6", "3.6"), ("3.5.1", "3.5")]
)