|
| 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) |
0 commit comments