def pytestcase_load_n_events_too_much_npy(tmpdir):
    """Tests loading too many events"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "load_n_events_too_much",
        "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"
        "199999 4 BB_CREATE 7 97 102 22 21 0.3\n"
        "199999 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199999 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
    events = record.load_n_events(3)
    assert record.done is False
    events = record.load_n_events(10)
    assert all([
        np.allclose(events[name], bboxes[name][3:])
        for name in events.dtype.names
    ])
    # we loaded n_events events, so cursor should have been shifted by 10*8
    assert record.current_event_index() == 0 + record.event_count()
    assert record.done
    # current time should be the timestamp of the last event + 1
    assert record.current_time == 199999 + 1
def pytestcase_load_event_plus_delta_t_npy(tmpdir):
    """Tests loading a define number of events and consecutively a time window"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "load_event_plus_delta_t",
        "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"
        "100000 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199999 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
    events = record.load_n_events(3)
    assert record.done is False
    # current time should be the timestamp of the event that will be loaded next
    assert record.current_time == 99999 + 1
    events = record.load_delta_t(15000)
    assert record.current_event_index() == 0 + 3 + 2
    assert all([
        np.allclose(events[name], bboxes[name][3:5])
        for name in events.dtype.names
    ])
    assert record.done is False
    assert record.current_time == 99999 + 1 + 15000
    assert record.done is False
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
def pytestcase_reset_npy(tmpdir):
    """Tests resetting EventNpyReader object after loading some events"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "reset", "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"
        "199999 4 BB_CREATE 7 97 102 22 21 0.3\n"
        "199999 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199999 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)
    events = record.load_n_events(10)
    record.reset()
    assert record.current_event_index() == 0
    assert record.done is False
    assert record.current_time == 0
def pytestcase_load_n_events_npy(tmpdir):
    """Tests loading a defined number of events"""
    filename, bboxes = create_temporary_npy_file(
        tmpdir, "load_n_events", "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"
        "199999 4 BB_CREATE 7 97 102 22 21 0.3\n"
        "199999 5 BB_CREATE 6 8 69 51 53 0.6\n"
        "199999 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
    n_events = 4
    events = record.load_n_events(n_events)
    assert all([
        np.allclose(events[name], bboxes[name][:n_events])
        for name in events.dtype.names
    ])
    # we loaded n_events events, so cursor should have been shifted by 10*8
    assert record.current_event_index() == 0 + n_events
    assert record.done is False
    # current time should be the timestamp of the event that will be loaded next
    assert record.current_time == 199999