Unverified Commit c737b41f authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

fix downloadIsisData install (#5014)

* fix downloadIsisData install

* used importlib

* temp disable of non-pytests

* reverted Jenkinsfile
parent acf88f5e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -609,7 +609,7 @@ install(FILES ${CMAKE_SOURCE_DIR}/../CHANGELOG.md DESTINATION ${CMAKE_INSTA
install(FILES     ${CMAKE_BINARY_DIR}/version         DESTINATION  ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/scripts         DESTINATION  ${CMAKE_INSTALL_PREFIX})
install(PROGRAMS ${CMAKE_BINARY_DIR}/lib/Camera.plugin DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/downloadIsisData.py DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/downloadIsisData DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/config/rclone.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/isis/)

# Trigger all post-install behavior.
+12 −9
Original line number Diff line number Diff line
@@ -8,7 +8,15 @@ from unittest import mock
from tempfile import TemporaryDirectory
from pathlib import Path

from downloadIsisData import rclone, create_rclone_arguments
from importlib.util import spec_from_loader, module_from_spec
from importlib.machinery import SourceFileLoader 

spec = spec_from_loader("downloadIsisData", SourceFileLoader("downloadIsisData", "../scripts/downloadIsisData"))
downloadIsisData = module_from_spec(spec)
spec.loader.exec_module(downloadIsisData)
did = downloadIsisData

# from downloadIsisData import rclone, create_rclone_arguments

class MockedPopen:
    def __init__(self, args, **kwargs):
@@ -36,27 +44,22 @@ class MockedBustedPopen:
    def __init__(self, args, **kwargs):
        raise Exception("idk what happened")

@mock.patch('downloadIsisData.which', return_value=False)
def test_rclone_not_installed(mock_which):
    with pytest.raises(ProcessLookupError, match="rclone is not installed"):
        rclone("lsf", "test", extra_args=["-l", "-R", "--format", "p", "--files-only"], redirect_stdout=True, redirect_stderr=True)


@mock.patch("subprocess.Popen", MockedPopen)
def test_rclone():
    res = rclone("lsf", "test", extra_args=["-l", "-R", "--format", "p", "--files-only"], redirect_stdout=True, redirect_stderr=True)
    res = did.rclone("lsf", "test", extra_args=["-l", "-R", "--format", "p", "--files-only"], redirect_stdout=True, redirect_stderr=True)
    assert res["out"].decode() == "Success"

@mock.patch("subprocess.Popen", MockedBustedPopen)
def test_rclone_unknown_exception():
    with pytest.raises(Exception, match="idk"):
        res = rclone("lsf", "test", extra_args=["-l", "-R", "--format", "p", "--files-only"], redirect_stdout=True, redirect_stderr=True)
        res = did.rclone("lsf", "test", extra_args=["-l", "-R", "--format", "p", "--files-only"], redirect_stdout=True, redirect_stderr=True)


def test_create_rclone_args():
    with TemporaryDirectory() as tdir: 
        dest = Path(tdir) / "test"
        args = create_rclone_arguments(str(dest), "lro_naifKernels:", dry_run=False, ntransfers=100)
        args = did.create_rclone_arguments(str(dest), "lro_naifKernels:", dry_run=False, ntransfers=100)
        assert args == ['lro_naifKernels:', str(dest/"lro"/"kernels"), '--progress', '--checkers=100', '--transfers=100', '--track-renames', '--log-level=WARNING']
        assert dest.exists()