forked from RobotWebTools/rosbridge_suite
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle ROS 2 types properly (RobotWebTools#883)
- Loading branch information
Showing
3 changed files
with
132 additions
and
23 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
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
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,46 @@ | ||
#!/usr/bin/env python | ||
import unittest | ||
|
||
import rosapi.objectutils as objectutils | ||
|
||
# Globally defined ros_loader, used inside the setUp and teardown functions | ||
ros_loader = None | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
def setUp(self): | ||
global ros_loader | ||
self.original_ros_loader = ros_loader | ||
ros_loader = self._mock_get_message_instance("default") | ||
|
||
def tearDown(self): | ||
global ros_loader | ||
ros_loader = self.original_ros_loader | ||
|
||
def _mock_get_message_instance(self, type): | ||
class MockInstance(object): | ||
__slots__ = ["_" + type] | ||
_fields_and_field_types = {type: type} | ||
|
||
return MockInstance() | ||
|
||
def test_get_typedef_for_atomic_types(self): | ||
# Test for boolean type | ||
actual_typedef = objectutils.get_typedef("boolean") | ||
# should be None for an atomic | ||
self.assertEqual(actual_typedef, None) | ||
|
||
# Test for float type | ||
actual_typedef = objectutils.get_typedef("float") | ||
# should be None for an atomic | ||
self.assertEqual(actual_typedef, None) | ||
|
||
def test_handle_sequences(self): | ||
# Test for boolean sequence type | ||
actual_typedef = objectutils.get_typedef("sequence<boolean>") | ||
# should be None for an atomic | ||
self.assertEqual(actual_typedef, None) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |