def test_get_build_commands(monkeypatch): class Options: catkin_cmake_args = list() catkin_packages = list() catkin_packages_ignore = list() plugin = catkin.CatkinPlugin(part_name="my-part", options=Options()) monkeypatch.setattr(sys, "path", ["", "/test"]) monkeypatch.setattr(sys, "executable", "/test/python3") monkeypatch.setattr(_ros, "__file__", "/test/_ros.py") monkeypatch.setattr(os, "environ", dict()) assert plugin.get_build_commands() == [ "_CATKIN_SETUP_DIR=/opt/ros/$ROS_DISTRO . /opt/ros/$ROS_DISTRO/setup.sh", "if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then sudo rosdep " "init; fi", "rosdep update --include-eol-distros --rosdistro $ROS_DISTRO", "rosdep install --default-yes --ignore-packages-from-source --from-paths .", "catkin_make_isolated --install --merge --install-space $SNAPCRAFT_PART_INSTALL/opt/ros/$ROS_DISTRO " "-j $SNAPCRAFT_PARALLEL_BUILD_COUNT", "env -i LANG=C.UTF-8 LC_ALL=C.UTF-8 /test/python3 -I " "/test/_ros.py " "stage-runtime-dependencies --part-install $SNAPCRAFT_PART_INSTALL " "--ros-distro $ROS_DISTRO", ]
def test_get_build_commands_with_all_properties(monkeypatch): class Options: catkin_cmake_args = ["cmake", "args..."] catkin_packages = ["package1", "package2..."] catkin_packages_ignore = ["ipackage1", "ipackage2..."] plugin = catkin.CatkinPlugin(part_name="my-part", options=Options()) monkeypatch.setattr(sys, "path", ["", "/test"]) monkeypatch.setattr(sys, "executable", "/test/python3") monkeypatch.setattr(_ros, "__file__", "/test/_ros.py") monkeypatch.setattr( os, "environ", dict( FOO="baR", PATH="/bin:/test", SNAP="TESTSNAP", SNAP_ARCH="TESTARCH", SNAP_NAME="TESTSNAPNAME", SNAP_VERSION="TESTV1", http_proxy="http://foo", https_proxy="https://bar", ), ) assert plugin.get_build_commands() == [ 'state="$(set +o)"', "set +u", 'if [ -f "${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}/setup.sh" ]; then', "set -- --local", '_CATKIN_SETUP_DIR="${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}" . "${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}/setup.sh"', "set -- --local --extend", "else", "set -- --local", "fi", '. /opt/ros/"${ROS_DISTRO}"/setup.sh', 'eval "${state}"', "if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then sudo rosdep " "init; fi", 'rosdep update --include-eol-distros --rosdistro "${ROS_DISTRO}"', 'rosdep install --default-yes --ignore-packages-from-source --from-paths "${SNAPCRAFT_PART_SRC}"', "catkin_make_isolated --install --merge " '--source-space "${SNAPCRAFT_PART_SRC}" --build-space "${SNAPCRAFT_PART_BUILD}" ' '--install-space "${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}" ' '-j "${SNAPCRAFT_PARALLEL_BUILD_COUNT}" --pkg package1 package2... ' "--ignore-pkg ipackage1 ipackage2... --cmake-args cmake args...", "env -i LANG=C.UTF-8 LC_ALL=C.UTF-8 PATH=/bin:/test SNAP=TESTSNAP " "SNAP_ARCH=TESTARCH SNAP_NAME=TESTSNAPNAME SNAP_VERSION=TESTV1 " "http_proxy=http://foo https_proxy=https://bar " "/test/python3 -I " "/test/_ros.py " 'stage-runtime-dependencies --part-src "${SNAPCRAFT_PART_SRC}" --part-install "${SNAPCRAFT_PART_INSTALL}" ' '--ros-version "${ROS_VERSION}" --ros-distro "${ROS_DISTRO}" --target-arch "${SNAPCRAFT_TARGET_ARCH}"', ]
def test_get_build_commands_with_all_properties(monkeypatch): class Options: catkin_cmake_args = ["cmake", "args..."] catkin_packages = ["package1", "package2..."] catkin_packages_ignore = ["ipackage1", "ipackage2..."] plugin = catkin.CatkinPlugin(part_name="my-part", options=Options()) monkeypatch.setattr(sys, "path", ["", "/test"]) monkeypatch.setattr(sys, "executable", "/test/python3") monkeypatch.setattr(_ros, "__file__", "/test/_ros.py") monkeypatch.setattr( os, "environ", dict( FOO="baR", PATH="/bin:/test", SNAP="TESTSNAP", SNAP_ARCH="TESTARCH", SNAP_NAME="TESTSNAPNAME", SNAP_VERSION="TESTV1", http_proxy="http://foo", https_proxy="https://bar", ), ) assert plugin.get_build_commands() == [ "_CATKIN_SETUP_DIR=/opt/ros/$ROS_DISTRO . /opt/ros/$ROS_DISTRO/setup.sh", "if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then sudo rosdep " "init; fi", "rosdep update --include-eol-distros --rosdistro $ROS_DISTRO", "rosdep install --default-yes --ignore-packages-from-source --from-paths .", "catkin_make_isolated --install --merge --install-space $SNAPCRAFT_PART_INSTALL/opt/ros/$ROS_DISTRO " "-j $SNAPCRAFT_PARALLEL_BUILD_COUNT --pkg package1 package2... " "--ignore-pkg ipackage1 ipackage2... --cmake-args cmake args...", "env -i LANG=C.UTF-8 LC_ALL=C.UTF-8 PATH=/bin:/test SNAP=TESTSNAP " "SNAP_ARCH=TESTARCH SNAP_NAME=TESTSNAPNAME SNAP_VERSION=TESTV1 " "http_proxy=http://foo https_proxy=https://bar " "/test/python3 -I " "/test/_ros.py " "stage-runtime-dependencies --part-install $SNAPCRAFT_PART_INSTALL " "--ros-distro $ROS_DISTRO", ]
def test_get_build_commands(monkeypatch): class Options: catkin_cmake_args = list() catkin_packages = list() catkin_packages_ignore = list() plugin = catkin.CatkinPlugin(part_name="my-part", options=Options()) monkeypatch.setattr(sys, "path", ["", "/test"]) monkeypatch.setattr(sys, "executable", "/test/python3") monkeypatch.setattr(_ros, "__file__", "/test/_ros.py") monkeypatch.setattr(os, "environ", dict()) assert plugin.get_build_commands() == [ 'state="$(set +o)"', "set +u", 'if [ -f "${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}/setup.sh" ]; then', "set -- --local", '_CATKIN_SETUP_DIR="${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}" . "${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}/setup.sh"', "set -- --local --extend", "else", "set -- --local", "fi", '. /opt/ros/"${ROS_DISTRO}"/setup.sh', 'eval "${state}"', "if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then sudo rosdep " "init; fi", 'rosdep update --include-eol-distros --rosdistro "${ROS_DISTRO}"', 'rosdep install --default-yes --ignore-packages-from-source --from-paths "${SNAPCRAFT_PART_SRC}"', "catkin_make_isolated --install --merge " '--source-space "${SNAPCRAFT_PART_SRC}" --build-space "${SNAPCRAFT_PART_BUILD}" ' '--install-space "${SNAPCRAFT_PART_INSTALL}/opt/ros/${ROS_DISTRO}" ' '-j "${SNAPCRAFT_PARALLEL_BUILD_COUNT}"', "env -i LANG=C.UTF-8 LC_ALL=C.UTF-8 /test/python3 -I " "/test/_ros.py " 'stage-runtime-dependencies --part-src "${SNAPCRAFT_PART_SRC}" --part-install "${SNAPCRAFT_PART_INSTALL}" ' '--ros-version "${ROS_VERSION}" --ros-distro "${ROS_DISTRO}" --target-arch "${SNAPCRAFT_TARGET_ARCH}"', ]
def test_out_of_source_build_property(): plugin = catkin.CatkinPlugin(part_name="my-part", options=lambda: None) assert plugin.out_of_source_build
def test_get_build_environment(): plugin = catkin.CatkinPlugin(part_name="my-part", options=lambda: None) assert plugin.get_build_environment() == { "ROS_PYTHON_VERSION": "3", }
def test_get_build_packages(): plugin = catkin.CatkinPlugin(part_name="my-part", options=lambda: None) assert plugin.get_build_packages() == { "python3-rosdep", "ros-noetic-catkin" }