def test_get_last_ix_for_one_record(tub_path): inputs = ['cam/image_array', 'angle', 'throttle'] types = ['image_array', 'float', 'float'] t = Tub(tub_path, inputs=inputs, types=types) record = create_sample_record() t.put_record(record) assert t.get_last_ix() == 0
def create_sample_tub(path, records=10): inputs = ['cam/image_array', 'angle', 'throttle'] types = ['image_array', 'float', 'float'] t = Tub(path, inputs=inputs, types=types) for _ in range(records): record = create_sample_record() t.put_record(record) return t
def test_tub_put_unknown_type(tub_path): """ Creating a record with unknown type should fail """ inputs = ['user/speed'] types = ['bob'] t = Tub(path=tub_path, inputs=inputs, types=types) with pytest.raises(TypeError): t.put_record({ 'user/speed': 0.2, })
def test_recreating_tub(tub): """ Recreating a Tub should restore it to working state """ assert tub.get_num_records() == 10 assert tub.current_ix == 10 assert tub.get_last_ix() == 9 path = tub.path tub = None inputs = ['cam/image_array', 'angle', 'throttle'] types = ['image_array', 'float', 'float'] t = Tub(path, inputs=inputs, types=types) assert t.get_num_records() == 10 assert t.current_ix == 10 assert t.get_last_ix() == 9
def test_tub_put_image(tub_path): """ Add an encoded image to the tub """ inputs = ['user/speed', 'cam/image'] types = ['float', 'image'] img = Image.new('RGB', (120, 160)) t = Tub(path=tub_path, inputs=inputs, types=types) t.put_record({ 'cam/image': img, 'user/speed': 0.2, }) assert t.get_record(t.get_last_ix())['user/speed'] == 0.2
def test_get_last_ix_for_empty_tub(tub_path): inputs = ['cam/image_array', 'angle', 'throttle'] types = ['image_array', 'float', 'float'] t = Tub(tub_path, inputs=inputs, types=types) assert t.get_last_ix() == -1
def test_tub_load(tub, tub_path): """Tub loads from existing tub path.""" t = Tub(tub_path) assert t is not None