Skip to content

Commit

Permalink
Added common test to rqt_py_common (#310)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
  • Loading branch information
ahcorde authored Jul 8, 2024
1 parent 220e29d commit 1705b63
Show file tree
Hide file tree
Showing 18 changed files with 242 additions and 235 deletions.
3 changes: 3 additions & 0 deletions rqt_py_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ install(DIRECTORY resource
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(rosidl_default_generators REQUIRED)
find_package(ament_cmake_pytest REQUIRED)
# Provides PYTHON_EXECUTABLE_DEBUG
Expand Down
2 changes: 2 additions & 0 deletions rqt_py_common/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<exec_depend>qt_gui</exec_depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>python_cmake_module</test_depend>
<test_depend>rosidl_default_generators</test_depend>
<test_depend>rosidl_default_runtime</test_depend>
Expand Down
49 changes: 24 additions & 25 deletions rqt_py_common/src/rqt_py_common/ini_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


def pack(data):
"""
Packs 'data' into a form that can be easily and readably written to an ini file
Packs 'data' into a form that can be easily and readably written to an ini file.
:param data:
A list of strings or a list of items with a 'text' method to be flattened into a
Expand All @@ -46,7 +45,7 @@ def pack(data):
def _get_str(item):
try:
return item.text()
except:
except Exception:
return item

data = [_get_str(value) for value in data]
Expand All @@ -57,7 +56,7 @@ def _get_str(item):

def unpack(data):
"""
Unpacks the values read from an ini file
Unpacks the values read from an ini file.
:param data: An entry taken from an ini file ''list or string''
:return: A list of strings ''list''
Expand Down
2 changes: 1 addition & 1 deletion rqt_py_common/src/rqt_py_common/item_delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DelegateUtil(object):
def _get_hierarchy_level(model_index):
hierarchyLevel = 1
seek_root = model_index
while(seek_root.parent() != QModelIndex()):
while seek_root.parent() != QModelIndex():
seek_root = seek_root.parent()
hierarchyLevel += 1
return hierarchyLevel
56 changes: 29 additions & 27 deletions rqt_py_common/src/rqt_py_common/layout_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Author: Isaac Saito

from python_qt_binding.QtCore import Qt
from python_qt_binding.QtWidgets import QWidgetItem, QSpacerItem
from python_qt_binding.QtWidgets import QSpacerItem, QWidgetItem

from rclpy import logging

Expand All @@ -44,8 +43,9 @@ class LayoutUtil(object):
@staticmethod
def alternate_color(list_widgets, colors_alter=[Qt.white, Qt.gray]):
"""
Alternate the background color of the widgets that are ordered
linearly, by the given list of colors.
Alternate the background color of the widgets.
Widgets are ordered linearly, by the given list of colors.
Originally intended for the elements of QHBoxLayout & QVBoxLayout.
Expand Down Expand Up @@ -75,8 +75,10 @@ def alternate_color(list_widgets, colors_alter=[Qt.white, Qt.gray]):
@staticmethod
def clear_layout(layout):
"""
Clear all items in the given layout. Currently, only the instances of
QWidgetItem get cleared (ie. QSpaceItem is ignored).
Clear all items in the given layout.
Currently, only the instances of QWidgetItem get cleared
(ie. QSpaceItem is ignored).
Originally taken from http://stackoverflow.com/a/9375273/577001
Expand Down
20 changes: 10 additions & 10 deletions rqt_py_common/src/rqt_py_common/message_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def get_all_rosidl_types_of_type(rosidl_type):
:returns: a dictionary mapping packages to the rosidl interfaces of a specific type
"""
if rosidl_type not in ROSIDL_FILTERS:
raise ValueError('Invalid rosidl_type type "{}". Needs to be one of {}'.format(
filter_type, ROSIDL_FILTERS.keys()))
raise ValueError('Invalid rosidl_type type {}. Needs to be one of {}'.format(
rosidl_type, ROSIDL_FILTERS.keys()))

all_rosidl_types = get_all_rosidl_types()
return {
Expand All @@ -151,7 +151,7 @@ def get_all_rosidl_types_of_type(rosidl_type):

def get_all_service_types():
"""
Uses the ament index to iterate through packages and calls get_service_types on each one.
Use the ament index to iterate through packages and calls get_service_types on each one.
:returns: a dictionary of the form {'package_name', ['srv1', 'srv2', ...]}
"""
Expand All @@ -160,7 +160,7 @@ def get_all_service_types():

def get_service_types(package_name):
"""
Uses the ament index gind all services avialable in the package.
Use the ament index gind all services avialable in the package.
:param package_name: a string eg 'std_srvs'
:returns: a dictionary of the form {'package_name', ['srv1', 'srv2', ...]}
Expand All @@ -170,7 +170,7 @@ def get_service_types(package_name):

def get_all_message_types():
"""
Uses the ament index to iterate through packages and calls get_message_types on each one.
Use the ament index to iterate through packages and calls get_message_types on each one.
:returns: a dictionary of the form {'package_name', ['msg1', 'msg2', ...]}
"""
Expand All @@ -179,7 +179,7 @@ def get_all_message_types():

def get_message_types(package_name):
"""
Uses the ament index to find all messages avialable in the package.
Use the ament index to find all messages avialable in the package.
:param package_name: a string eg 'std_msgs'
:returns: a dictionary of the form {'std_msgs', ['Bool', 'String', ...]}
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_action_types(package_name):

def _get_rosidl_class_helper(message_type, mode, logger=None): # noqa: C901
"""
A helper function for common logic to be used by get_message_class and get_service_class.
Logic to be used by get_message_class and get_service_class.
:param message_type: name of the message or service class in the form
'package_name/MessageName' or 'package_name/msg/MessageName'
Expand Down Expand Up @@ -266,7 +266,7 @@ def _get_rosidl_class_helper(message_type, mode, logger=None): # noqa: C901

def get_service_class(srv_type):
"""
Gets the service class from a string representation.
Get the service class from a string representation.
:param srv_type: the type of service in the form
`package_name/ServiceName` or `package_name/srv/ServiceName`
Expand All @@ -291,7 +291,7 @@ def get_service_class(srv_type):

def get_message_class(message_type):
"""
Gets the message class from a string representation.
Get the message class from a string representation.
:param message_type: the type of message in the form `msg_pkg/Message`
:type message_type: str
Expand All @@ -316,7 +316,7 @@ def get_message_class(message_type):

def get_action_class(action_type):
"""
Gets the action class from a string representation.
Get the action class from a string representation.
:param action_type: the type of action in the form `action_pkg/Action`
:type action_type: str
Expand Down
6 changes: 3 additions & 3 deletions rqt_py_common/src/rqt_py_common/message_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _recursive_create_items(

return (row, is_leaf_node)

'''
"""
NOTE: I (Isaac Saito) suspect that this function might have same/similar
functionality with _recursive_create_items.
Expand All @@ -128,7 +128,7 @@ def _recursive_create_items(
[ top_node, sub_node, subsub_node ]
@author: Isaac Saito
'''
"""
@staticmethod
def _build_tree_recursive(stditem_parent, names_on_branch):
name_curr = names_on_branch.pop(0)
Expand All @@ -152,7 +152,7 @@ def _build_tree_recursive(stditem_parent, names_on_branch):

MessageTreeModel._logger.debug(
'add_tree_node 1 name_curr={} \n\t\tname_prev={} row_index_parent={}'.format(
(name_curr, name_prev, row_index_parent)))
name_curr, name_prev, row_index_parent))

if (0 < len(names_on_branch)):
MessageTreeModel._build_tree_recursive(stditem, names_on_branch)
2 changes: 1 addition & 1 deletion rqt_py_common/src/rqt_py_common/message_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from python_qt_binding.QtCore import Slot, QMimeData, QModelIndex, Qt, qWarning
from python_qt_binding.QtCore import QMimeData, QModelIndex, Qt, qWarning, Slot
from python_qt_binding.QtGui import QDrag, QIcon
from python_qt_binding.QtWidgets import QAction, QHeaderView, QMenu, QTreeView

Expand Down
45 changes: 23 additions & 22 deletions rqt_py_common/src/rqt_py_common/plugin_container_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Author: Isaac Saito
Expand Down Expand Up @@ -68,6 +67,8 @@ class PluginContainerWidget(QWidget):
def __init__(self, plugin_widget,
on_sys_msg=True, on_sysprogress_bar=True):
"""
Contruct PluginContainerWidget.
@param plugin_widget: The main widget of an rqt plugin.
@type plugin_widget: QWidget
@type on_sys_msg: bool
Expand Down
Loading

0 comments on commit 1705b63

Please sign in to comment.