Exemplo n.º 1
0
def test_mran_date(tmpdir, runtime, expected):
    tmpdir.chdir()

    with open("runtime.txt", "w") as f:
        f.write(runtime)

    r = buildpacks.RBuildPack()
    assert r.checkpoint_date == date(*expected)
Exemplo n.º 2
0
def test_version_completion(tmpdir):
    tmpdir.chdir()

    with open("runtime.txt", "w") as f:
        f.write(f"r-3.6-2019-01-01")

    r = buildpacks.RBuildPack()
    assert r.r_version == "3.6.3-1bionic"
Exemplo n.º 3
0
def test_install_from_base(tmpdir):
    # check that for R==3.4 we install from ubuntu
    tmpdir.chdir()

    with open("runtime.txt", "w") as f:
        f.write("r-3.4-2019-01-02")

    r = buildpacks.RBuildPack()
    assert "r-base" in r.get_packages()
Exemplo n.º 4
0
def test_install_from_ppa(tmpdir):
    # check that for R>3.4 we don't install r-base from Ubuntu
    tmpdir.chdir()

    with open("runtime.txt", "w") as f:
        f.write("r-3.5-2019-01-02")

    r = buildpacks.RBuildPack()
    assert "r-base" not in r.get_packages()
Exemplo n.º 5
0
def test_version_specification(tmpdir, runtime_version, expected):
    tmpdir.chdir()

    with open("runtime.txt", "w") as f:
        if runtime_version:
            runtime_version += "-"
        f.write(f"r-{runtime_version}2019-01-01")

    r = buildpacks.RBuildPack()
    assert r.r_version.startswith(expected)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def test_snapshot_mran_date(requested, expected):
    def mock_request_head(url):
        r = Response()
        if url == "https://mran.microsoft.com/snapshot/" + expected.isoformat():
            r.status_code = 200
        else:
            r.status_code = 404
            r.reason = "Mock MRAN no snapshot"
        return r

    with patch("requests.head", side_effect=mock_request_head):
        r = buildpacks.RBuildPack()
        assert r.get_mran_snapshot_url(
            requested
        ) == "https://mran.microsoft.com/snapshot/{}".format(expected.isoformat())
def test_combine_preassemble_steps(tmpdir, binder_dir):
    tmpdir.chdir()
    if binder_dir:
        os.mkdir(binder_dir)

    # create two empty files for the build pack to use for pre-assembly
    open(os.path.join(binder_dir, "requirements.txt"), "w").close()
    open(os.path.join(binder_dir, "install.R"), "w").close()

    # trigger R build pack detection
    with open(os.path.join(binder_dir, "runtime.txt"), "w") as f:
        f.write("r-2019-01-30")

    bp = buildpacks.RBuildPack()
    files = bp.get_preassemble_script_files()

    assert len(files) == 2
    assert os.path.join(binder_dir, "requirements.txt") in files
    assert os.path.join(binder_dir, "install.R") in files
Exemplo n.º 9
0
def test_mran_latestdate(tmpdir, expected):
    def mock_request_head(url):
        r = Response()
        if url == "https://mran.microsoft.com/snapshot/" + expected:
            r.status_code = 200
        else:
            r.status_code = 404
            r.reason = "Mock MRAN no snapshot"
        return r

    tmpdir.chdir()

    with open("DESCRIPTION", "w") as f:
        f.write("")

    with patch("requests.head", side_effect=mock_request_head):
        with patch("datetime.date") as mockdate:
            mockdate.today.return_value = date(2019, 12, 31)
            r = buildpacks.RBuildPack()
            r.detect()
    assert r.checkpoint_date.isoformat() == expected
Exemplo n.º 10
0
def test_snapshot_rspm_date():
    test_dates = {
        # Even though there is no snapshot specified in the interface at https://packagemanager.rstudio.com/client/#/repos/1/overview
        # For 2021 Oct 22, the API still returns a valid URL that one can install
        # packages from - probably some server side magic that repeats our client side logic.
        # No snapshot for this date from
        date(2021, 10, 22): date(2021, 10, 22),
        # Snapshot exists for this date
        date(2022, 1, 1): date(2022, 1, 1),
    }

    r = buildpacks.RBuildPack()
    for requested, expected in test_dates.items():
        snapshot_url = r.get_rspm_snapshot_url(requested)
        assert snapshot_url.startswith(
            "https://packagemanager.rstudio.com/all/__linux__/bionic/"
            + expected.strftime("%Y-%m-%d")
        )

    with pytest.raises(ValueError):
        r.get_rspm_snapshot_url(date(1691, 9, 5))
Exemplo n.º 11
0
def test_custom_ppa(tmpdir):
    tmpdir.chdir()

    with open("runtime.txt", "w") as f:
        f.write("r-3.5-2019-01-02")

    r = buildpacks.RBuildPack()

    scripts = r.get_build_scripts()

    # check that at least one of the build scripts adds this new PPA
    for user, script in scripts:
        if "https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/" in script:
            break
    else:
        assert False, "Should have added a new PPA"

    # check that we install the right package
    for user, script in scripts:
        if "r-base=3.5" in script:
            break
    else:
        assert False, "Should have installed base R"