Skip to content

Commit 935d333

Browse files
committed
smach_viewer/test add test_smach_event.py, to fix ros-visualization#59 (comment)
1 parent 5588ec2 commit 935d333

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

smach_viewer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ if(CATKIN_ENABLE_TESTING)
2323
find_package(rostest REQUIRED)
2424
add_rostest(test/test_smach_py.test)
2525
add_rostest(test/test_smach_image.test)
26+
add_rostest(test/test_smach_event.test)
2627
find_package(roseus QUIET)
2728
if(roseus_FOUND)
2829
add_rostest(test/test_smach_eus.test)
2930
endif()
3031
find_package(roseus_smach QUIET)
3132
if(roseus_smach_FOUND)
3233
add_rostest(test/test_roseus_smach_state_machine_ros_sample.test)
34+
add_rostest(test/test_smach_event.test ARGS target_python:=false target_roseus:=true)
3335
endif()
3436
endif()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
sys.path.insert(0, parent_dir_name + "/scripts")
8+
import smach_viewer
9+
10+
import wx
11+
12+
import rospy
13+
import rostest
14+
import unittest
15+
16+
import time
17+
18+
class TestSmachViewerEvent(unittest.TestCase):
19+
20+
def setUp(self):
21+
rospy.init_node('test_smach_event', anonymous=True)
22+
app = wx.App()
23+
24+
self.frame = smach_viewer.SmachViewerFrame()
25+
self.frame.set_filter('dot')
26+
#/server_namsmach/container_statsup
27+
self.frame.Show()
28+
self.frame.is_button = type('DummyButton', (object, ), {'Disable': lambda self: None, 'Enable': lambda self: None})();
29+
#app.MainLoop()
30+
self.evtloop = wx.GUIEventLoop()
31+
#old = wx.EventLoop.GetActive()
32+
wx.EventLoop.SetActive(self.evtloop)
33+
34+
def test_samch_event(self):
35+
try:
36+
for i in range(10):
37+
self.frame.path_input.SetValue('/SM_ROOT/FOO')
38+
self.frame.selection_changed(None)
39+
time.sleep(1)
40+
self.evtloop.ProcessIdle()
41+
rospy.loginfo("SUCCEEDED: _local_data {}".format(self.frame._containers))
42+
rospy.loginfo("SUCCEEDED: _local_data {}".format([v._local_data._data for v in self.frame._containers.values()]))
43+
self.frame.kill()
44+
except Exception as e:
45+
rospy.logerr(e)
46+
rospy.logerr("FAILED: _local_data {}".format(self.frame._containers))
47+
rospy.logerr("FAILED: _local_data {}".format([v._local_data._data for v in self.frame._containers.values()]))
48+
self.assertFalse(e)
49+
50+
if __name__ == '__main__':
51+
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)