Skip to content

Commit f34810d

Browse files
authored
Merge pull request #64 from k-okada/add_test
smach_viewer/test add test_smach_event.py,
2 parents 5588ec2 + c94f02a commit f34810d

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

.github/workflows/config.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ jobs:
122122
source /opt/ros/${{ matrix.ROS_DISTRO }}/setup.bash
123123
set -x
124124
cd ~/ws/
125+
# smach_viewer is not depend on roseus_smach, but we need to build roseus_smach before smach_viewer for tests
126+
[ ${{ matrix.ROS_DISTRO }} != "one" ] || catkin build roseus_smach --no-status -sv ${{ matrix.CATKIN_OPTIONS }} --cmake-args -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ${{ matrix.CMAKE_OPTIONS }}
125127
catkin build --no-status -sv ${{ matrix.CATKIN_OPTIONS }} --cmake-args -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ${{ matrix.CMAKE_OPTIONS }}
126128
shell: bash
127129

@@ -130,9 +132,8 @@ jobs:
130132
run: |
131133
source ~/ws/devel/setup.bash
132134
set -x
133-
cd ~/ws/
134-
[ ${{ matrix.ROS_DISTRO }} != "one" ] || touch src/jsk_roseus/CATKIN_IGNORE
135-
catkin test --no-status -sv ${{ matrix.CATKIN_OPTIONS }} --cmake-args -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ${{ matrix.CMAKE_OPTIONS }}
135+
cd ~/ws/build/smach_viewer
136+
make run_tests
136137
shell: bash
137138

138139
- name: Show Test Results

smach_viewer/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ catkin_install_python(
1818
catkin_install_python(
1919
PROGRAMS test/test_smach.py
2020
test/test_rosout_error.py
21+
test/test_smach_event.py
2122
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/test)
2223
if(CATKIN_ENABLE_TESTING)
2324
find_package(rostest REQUIRED)
2425
add_rostest(test/test_smach_py.test)
2526
add_rostest(test/test_smach_image.test)
27+
add_rostest(test/test_smach_event.test)
2628
find_package(roseus QUIET)
2729
if(roseus_FOUND)
2830
add_rostest(test/test_smach_eus.test)
2931
endif()
3032
find_package(roseus_smach QUIET)
3133
if(roseus_smach_FOUND)
3234
add_rostest(test/test_roseus_smach_state_machine_ros_sample.test)
35+
add_rostest(test/test_smach_event.test ARGS target_python:=false target_roseus:=true)
3336
endif()
3437
endif()

smach_viewer/scripts/smach_viewer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ def selection_changed(self, event):
484484

485485
# Generate the userdata string
486486
ud_str = ''
487+
if not isinstance(container._local_data._data, dict):
488+
rospy.logwarn("userdata is not dictionary({}), please fix sender proram".format(container._local_data._data))
489+
container._local_data._data = {}
487490
for (k,v) in container._local_data._data.items():
488491
ud_str += str(k)+": "
489492
vstr = str(v)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import os
5+
6+
parent_dir_name = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
7+
8+
try:
9+
import importlib.util
10+
file_path = parent_dir_name + "/scripts/smach_viewer.py"
11+
module_name = 'smach_viewer_frame'
12+
spec = importlib.util.spec_from_file_location(module_name, file_path)
13+
smach_viewer_frame = importlib.util.module_from_spec(spec)
14+
sys.modules[module_name] = smach_viewer_frame
15+
spec.loader.exec_module(smach_viewer_frame)
16+
17+
except:
18+
sys.path.insert(0, parent_dir_name + "/scripts")
19+
import smach_viewer as smach_viewer_frame
20+
21+
import wx
22+
23+
import rospy
24+
import rostest
25+
import unittest
26+
27+
import time
28+
29+
class TestSmachViewerEvent(unittest.TestCase):
30+
31+
def setUp(self):
32+
rospy.init_node('test_smach_event', anonymous=True)
33+
app = wx.App()
34+
35+
self.frame = smach_viewer_frame.SmachViewerFrame()
36+
self.frame.set_filter('dot')
37+
#/server_namsmach/container_statsup
38+
self.frame.Show()
39+
self.frame.is_button = type('DummyButton', (object, ), {'Disable': lambda self: None, 'Enable': lambda self: None})();
40+
#app.MainLoop()
41+
self.evtloop = wx.GUIEventLoop()
42+
#old = wx.EventLoop.GetActive()
43+
wx.EventLoop.SetActive(self.evtloop)
44+
45+
def test_samch_event(self):
46+
try:
47+
for i in range(10):
48+
self.frame.path_input.SetValue('/SM_ROOT/FOO')
49+
self.frame.selection_changed(None)
50+
time.sleep(1)
51+
self.evtloop.ProcessIdle()
52+
rospy.loginfo("SUCCEEDED: _local_data {}".format(self.frame._containers))
53+
rospy.loginfo("SUCCEEDED: _local_data {}".format([v._local_data._data for v in self.frame._containers.values()]))
54+
self.frame.kill()
55+
except Exception as e:
56+
rospy.logerr(e)
57+
rospy.logerr("FAILED: _local_data {}".format(self.frame._containers))
58+
rospy.logerr("FAILED: _local_data {}".format([v._local_data._data for v in self.frame._containers.values()]))
59+
self.assertFalse(e)
60+
61+
if __name__ == '__main__':
62+
rostest.run('smach_viewer', 'test_smach_event', TestSmachViewerEvent, sys.argv)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<launch>
2+
<arg name="target_python" default="true" />
3+
<arg name="target_roseus" default="false" />
4+
<node if="$(arg target_python)"
5+
pkg="smach_viewer" name="test_smach_py" type="test_smach.py" />
6+
<node if="$(arg target_roseus)"
7+
pkg="roseus" name="test_smach_eus" type="roseus" args="$(find smach_viewer)/test/test_smach.l" />
8+
<test test-name="smach_viewer_event_test"
9+
pkg="smach_viewer" type="test_smach_event.py" name="smach_viewer_event_test" />
10+
</launch>

0 commit comments

Comments
 (0)