def test_assertInStdout_notices_too_many_matching_procs(self): with self.assertRaisesRegex(Exception, 'Found multiple processes') as cm: assertInStdout(self.proc_output, self.EXPECTED_TEXT, 'terminating_proc') # Make sure the assertion method lists the names of the duplicate procs: self.assertIn('terminating_proc-1', str(cm.exception)) self.assertIn('terminating_proc-2', str(cm.exception)) self.assertIn('terminating_proc-3', str(cm.exception))
def test_subscribe_vel_topics(self, launch_service, commands, proc_output): input_velocities = [] input_timestamps = [] smoothed_velocities = [] smoothed_timestamps = [] def received_input_data(msg): input_velocities.append(msg.linear.x) input_timestamps.append(time.monotonic()) def received_smoothed_data(msg): smoothed_velocities.append(msg.linear.x) smoothed_timestamps.append(time.monotonic()) input_subscriber = self.node.create_subscription( geometry_msgs.msg.Twist, '/commands/cmd_vel', received_input_data, 10, ) smoothed_subscriber = self.node.create_subscription( geometry_msgs.msg.Twist, '/cmd_vel', received_smoothed_data, 10, ) try: done = False while rclpy.ok() and not done: rclpy.spin_once(self.node, timeout_sec=0.1) try: # this works by virtue of having been printed dt seconds # (0.1s) after the last publication, which is sufficient # time for final subscription callbacks here to be # processed assertInStdout(proc_output, 'PROFILE_SENT', commands) done = True except launch_testing.util.proc_lookup.NoMatchingProcessException: pass except AssertionError: pass finally: self.assertAlmostEqual(0.5, max(input_velocities)) self.assertTrue(0.5 > max(smoothed_velocities)) self.assertTrue(0.4 < max(smoothed_velocities)) # plot a graph for easy viz plt.plot(input_timestamps, input_velocities, label='input') plt.plot(smoothed_timestamps, smoothed_velocities, label='smooth') plt.xlabel('time') plt.ylabel('velocity') plt.title('Raw Input vs Smoothed Velocities') plt.legend() plt.savefig('profiles.png') self.node.destroy_subscription(input_subscriber) self.node.destroy_subscription(smoothed_subscriber)
def test_assertInStdout_notices_no_matching_proc(self): with self.assertRaisesRegex(Exception, 'Did not find any process') as cm: assertInStdout(self.proc_output, self.EXPECTED_TEXT, 'bad_proc_name') print(cm.exception) # Make sure the assertion method lists the names of the process it does have: self.assertIn('terminating_proc-1', str(cm.exception)) self.assertIn('terminating_proc-2', str(cm.exception)) self.assertIn('terminating_proc-3', str(cm.exception))
def test_asserts_on_missing_text_by_proc(self): with self.assertRaisesRegex(AssertionError, self.NOT_FOUND_TEXT): assertInStdout(self.proc_output, self.NOT_FOUND_TEXT, self.proc_2)
def test_arguments_disambiguate_processes(self): txt = self.EXPECTED_TEXT assertInStdout(self.proc_output, txt, 'terminating_proc', '--extra') assertInStdout(self.proc_output, txt, 'terminating_proc', 'node:=different_name')
def test_regex_matching(self): assertInStdout(self.proc_output, re.compile(r'Called with arguments \S+'), 'terminating_proc-2')
def test_strict_proc_matching_false(self): assertInStdout(self.proc_output, self.EXPECTED_TEXT, 'terminating_proc', strict_proc_matching=False)