Merge branch 'tests' into 'master'
Enhance tracetools_test See merge request micro-ROS/ros2_tracing!14
This commit is contained in:
commit
9d16302f83
7 changed files with 71 additions and 41 deletions
|
@ -134,6 +134,12 @@ class TraceTestCase(unittest.TestCase):
|
|||
self.assertGreater(handle_value, 0, f'invalid handle value: {field_name}')
|
||||
|
||||
def assertValidQueueDepth(self, event: DictEvent, queue_depth_field_name: str = 'queue_depth'):
|
||||
"""
|
||||
Check that the queue depth value is valid.
|
||||
|
||||
:param event: the event with the queue depth field
|
||||
:param queue_depth_field_name: the field name for queue depth
|
||||
"""
|
||||
queue_depth_value = self.get_field(event, 'queue_depth')
|
||||
self.assertIsInstance(queue_depth_value, int, 'invalid queue depth type')
|
||||
self.assertGreater(queue_depth_value, 0, 'invalid queue depth')
|
||||
|
@ -149,6 +155,12 @@ class TraceTestCase(unittest.TestCase):
|
|||
self.assertGreater(len(string_field), 0, 'empty string')
|
||||
|
||||
def assertEventAfterTimestamp(self, event: DictEvent, timestamp: int):
|
||||
"""
|
||||
Check that the event happens after the given timestamp.
|
||||
|
||||
:param event: the event to check
|
||||
:param timestamp: the reference timestamp
|
||||
"""
|
||||
self.assertGreater(get_event_timestamp(event), timestamp, 'event not after timestamp')
|
||||
|
||||
def assertEventOrder(self, first_event: DictEvent, second_event: DictEvent):
|
||||
|
@ -160,6 +172,21 @@ class TraceTestCase(unittest.TestCase):
|
|||
"""
|
||||
self.assertTrue(self.are_events_ordered(first_event, second_event))
|
||||
|
||||
def assertNumEvents(
|
||||
self,
|
||||
events: List[DictEvent],
|
||||
expected_number: int,
|
||||
msg: str = 'wrong number of events'
|
||||
):
|
||||
"""
|
||||
Check number of events.
|
||||
|
||||
:param events: the events to check
|
||||
:param expected_number: the expected number of events
|
||||
:param msg: the message to display on failure
|
||||
"""
|
||||
self.assertEqual(len(events), expected_number, msg)
|
||||
|
||||
def assertMatchingField(
|
||||
self,
|
||||
initial_event: DictEvent,
|
||||
|
@ -200,16 +227,23 @@ class TraceTestCase(unittest.TestCase):
|
|||
1,
|
||||
'matching field event not after initial event')
|
||||
|
||||
def assertFieldEquals(self, event: DictEvent, field_name: str, value: Any):
|
||||
def assertFieldEquals(
|
||||
self,
|
||||
event: DictEvent,
|
||||
field_name: str,
|
||||
value: Any,
|
||||
msg: str = 'wrong field value'
|
||||
):
|
||||
"""
|
||||
Check the value of a field.
|
||||
|
||||
:param event: the event
|
||||
:param field_name: the name of the field to check
|
||||
:param value: to value to compare the field value to
|
||||
:param msg: the message to display on failure
|
||||
"""
|
||||
actual_value = self.get_field(event, field_name)
|
||||
self.assertEqual(actual_value, value, 'invalid field value')
|
||||
self.assertEqual(actual_value, value, msg)
|
||||
|
||||
def get_field(self, event: DictEvent, field_name: str) -> Any:
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue