Ejemplo n.º 1
0
def test_get_closest_message_by_rosbag_time(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_1_info = bag_manager.get_topic_info('topic_1', get_header_time=False)
    topic_2_info = bag_manager.get_topic_info('topic_2', get_header_time=True)

    time_rosbag = topic_1_info['msg_time_list_rosbag'][9]
    msg_topic_2 = bag_manager.get_closest_message_by_rosbag_time(topic='topic_2', time_rosbag=time_rosbag)
    assert msg_topic_2.header.stamp == topic_2_info['msg_time_list_header'][-1]  # checked manually,
Ejemplo n.º 2
0
def test_get_message_count_topic_2_in_interval_5_to_6(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_2_info = bag_manager.get_topic_info('topic_2', get_header_time=False)
    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][5]
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][6]

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 2
Ejemplo n.º 3
0
def test_topic_info_cache(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_1_info = bag_manager.get_topic_info('topic_1', get_header_time=False)
    assert bool(bag_manager._topics_info_cache) == True
    assert 'topic_1' in bag_manager._topics_info_cache
    assert bag_manager._topics_info_cache['topic_1']['msg_time_list_header'] is None
    assert 'topic_2' not in bag_manager._topics_info_cache

    topic_1_info_with_header_time = bag_manager.get_topic_info('topic_1', get_header_time=True)
    assert bool(bag_manager._topics_info_cache) == True
    assert 'topic_1' in bag_manager._topics_info_cache
    assert bag_manager._topics_info_cache['topic_1']['msg_time_list_header'] is not None
    assert 'topic_2' not in bag_manager._topics_info_cache

    topic_2_info_with_header_time = bag_manager.get_topic_info('topic_2', get_header_time=True)
    assert bool(bag_manager._topics_info_cache) == True
    assert 'topic_1' in bag_manager._topics_info_cache
    assert bag_manager._topics_info_cache['topic_1']['msg_time_list_header'] is not None
    assert 'topic_2' in bag_manager._topics_info_cache
    assert bag_manager._topics_info_cache['topic_2']['msg_time_list_header'] is not None
Ejemplo n.º 4
0
def test_get_message_by_index(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_2_info = bag_manager.get_topic_info('topic_2', get_header_time=True)

    with pytest.raises(IndexError) as e:
        msg_topic_2 = bag_manager.get_message_by_index(topic='topic_2', index=7)

    msg_topic_2 = bag_manager.get_message_by_index(topic='topic_2', index=6)
    assert msg_topic_2.header.stamp == topic_2_info['msg_time_list_header'][-1]  # checked manually,
    # We asked for the the msg with index 6 and we verify that is what we get

    msg_topic_2 = bag_manager.get_message_by_index(topic='topic_2', index=0)
    assert msg_topic_2.header.stamp == topic_2_info['msg_time_list_header'][0]  # checked manually,
Ejemplo n.º 5
0
def test_get_closest_message_by_header_time(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_1_info = bag_manager.get_topic_info('topic_1', get_header_time=True)
    topic_2_info = bag_manager.get_topic_info('topic_2', get_header_time=True)

    time_header = topic_1_info['msg_time_list_header'][4]
    msg_topic_2 = bag_manager.get_closest_message_by_header_time(topic='topic_2', time_header=time_header)
    msg_topic_2_idx = topic_2_info['msg_time_list_header'].index(msg_topic_2.header.stamp)
    assert msg_topic_2_idx == 4  # checked manually, since the seed is set to 0 this will always be true

    time_header = topic_2_info['msg_time_list_header'][0]
    msg_topic_1 = bag_manager.get_closest_message_by_header_time(topic='topic_1', time_header=time_header)
    msg_topic_1_idx = topic_1_info['msg_time_list_header'].index(msg_topic_1.header.stamp)
    assert msg_topic_1_idx == 0  # checked manually, since the seed is set to 0 this will always be true
Ejemplo n.º 6
0
def test_get_message_count_topic_2_in_interval_around_msgs(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_2_info = bag_manager.get_topic_info('topic_2', get_header_time=False)
    epsilon = rospy.Duration(1e-8)

    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][6] - epsilon
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][6] + epsilon

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 1

    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] - epsilon
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] + epsilon

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 1

    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] - epsilon
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][1] + epsilon

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 2

    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] - epsilon
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][-1] + epsilon

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 7

    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] - rospy.Duration(5)
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][-1] + rospy.Duration(5)

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 7

    start_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] - epsilon
    end_time_rosbag = topic_2_info['msg_time_list_rosbag'][0] - epsilon

    message_count = bag_manager.get_message_count_in_interval(topics='topic_2', start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 0
Ejemplo n.º 7
0
def test_get_message_count_all_topics_all_times(bag_file):
    from bagmanager import BagManager
    bag_manager = BagManager(bag_file=bag_file)
    topic_1_info = bag_manager.get_topic_info('topic_1', get_header_time=False)
    epsilon = rospy.Duration(1e-8)

    start_time_rosbag = topic_1_info['msg_time_list_rosbag'][0] - epsilon
    end_time_rosbag = topic_1_info['msg_time_list_rosbag'][9] + epsilon

    message_count = bag_manager.get_message_count_in_interval(topics=['topic_1', 'topic_2'],
                                                              start_time_rosbag=start_time_rosbag,
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 17

    message_count = bag_manager.get_message_count_in_interval(topics=['topic_1', 'topic_2'],
                                                              start_time_rosbag=start_time_rosbag)
    assert message_count == 17

    message_count = bag_manager.get_message_count_in_interval(topics=['topic_1', 'topic_2'],
                                                              end_time_rosbag=end_time_rosbag)
    assert message_count == 17

    message_count = bag_manager.get_message_count_in_interval(topics=['topic_1', 'topic_2'])
    assert message_count == 17