def pytestcase_seek_event_future_npy(tmpdir):
    """Tests seeking at a define position (after n events)"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "seek_event_future", "99999 0 BB_CREATE 7 96 102 22 21 0.3\n"
        "99999 2 BB_CREATE 7 127 87 53 53 0.3\n"
        "99999 3 BB_CREATE 7 141 81 119 78 0.7\n"
        "100000 4 BB_CREATE 7 97 102 22 21 0.3\n"
        "100001 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199998 6 BB_CREATE 7 127 87 53 53 0.4\n"
        "199999 7 BB_CREATE 7 141 81 119 78 0.7\n")
    record = EventNpyReader(filename)
    assert record.current_event_index() == 0
    assert record.event_count() == 7
    assert record.current_time == 0
    record.seek_event(3)
    assert record.current_event_index() == 0 + 3
    assert record.done is False
    # current_time should be the timestamp of the fourth event
    assert record.current_time == 100000
def pytestcase_seek_event_too_large_npy(tmpdir):
    """Tests seeking in the file after a number of events superior to the
    number of events in the whole file"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "seek_event_too_large",
        "99999 0 BB_CREATE 7 96 102 22 21 0.3\n"
        "99999 2 BB_CREATE 7 127 87 53 53 0.3\n"
        "99999 3 BB_CREATE 7 141 81 119 78 0.7\n"
        "100000 4 BB_CREATE 7 97 102 22 21 0.3\n"
        "100001 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199998 6 BB_CREATE 7 127 87 53 53 0.4\n"
        "199999 7 BB_CREATE 7 141 81 119 78 0.7\n")
    record = EventNpyReader(filename)
    assert record.current_event_index() == 0
    assert record.event_count() == 7
    assert record.current_time == 0
    record.seek_event(900)
    assert record.current_event_index() == 0 + 7
    assert record.done
    # current_time should be last event timestamp + 1
    assert record.current_time == 199999 + 1
def pytestcase_seek_event_negative_npy(tmpdir):
    """Tests seeking in the file after a negative number of events"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "seek_event_negative", "100 0 BB_CREATE 7 96 102 22 21 0.3\n"
        "200 2 BB_CREATE 7 127 87 53 53 0.3\n"
        "99999 3 BB_CREATE 7 141 81 119 78 0.7\n"
        "100000 4 BB_CREATE 7 97 102 22 21 0.3\n"
        "100001 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199998 6 BB_CREATE 7 127 87 53 53 0.4\n"
        "199999 7 BB_CREATE 7 141 81 119 78 0.7\n")
    record = EventNpyReader(filename)
    assert record.current_event_index() == 0
    assert record.event_count() == 7
    assert record.current_time == 0
    record.load_n_events(6)
    assert record.current_event_index() == 0 + 6
    assert record.done is False
    # current_time should be the timestamp of the seventh event
    assert record.current_time == 199999
    events = record.seek_event(-4)
    assert record.current_event_index() == 0 + 0
    assert record.done is False
    assert record.current_time == 0