-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test case for number of robots in mrs
- Loading branch information
1 parent
fe1fa66
commit f87513b
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
import unittest | ||
import rclpy | ||
from rclpy.node import Node | ||
|
||
class TestNumberOfRobots(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.expected_number_of_robots = int(sys.argv[1]) # Get expected number of robots from arguments | ||
rclpy.init(args=sys.argv) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
rclpy.shutdown() | ||
|
||
def test_robot_count(self): | ||
node = rclpy.create_node('test_robot_count_node') | ||
discovered_robots = [] | ||
|
||
def topic_callback(topic_list): | ||
nonlocal discovered_robots | ||
for topic_name, _ in topic_list: | ||
if 'joint_states' in topic_name and topic_name.startswith('/robot_'): | ||
robot_name = topic_name.split('/')[1] | ||
if robot_name not in discovered_robots: | ||
discovered_robots.append(robot_name) | ||
|
||
node.get_topic_names_and_types(node_name=None, node_namespace=None, no_demangle=False, callback=topic_callback) | ||
rclpy.spin_once(node, timeout_sec=1.0) | ||
self.assertEqual(len(discovered_robots), self.expected_number_of_robots) | ||
node.destroy_node() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |