Raise exception for unsupported R versions
MODIFY
repo2docker/buildpacks/r.py
repo2docker/buildpacks/r.py
@@ -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

MODIFY
tests/unit/test_r.py
tests/unit/test_r.py
@@ -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")]
)

Raise exception for unsupported R versions