Exceptional scenario: Limit of events reached
Summary
If the sum_events()
method happens to reach the maximum number of events in the source, the last reference event will not be associated with any image.
This is because the exception here will be reached and stop the loop. In this case, we know the last image has not been added in the result because the condition here never passed for the latest reference event.
What is the expected correct behavior?
In case the StopIteration
exception in catched, the last element of reference_events
should be discarded if the images
list is one element off such as
except StopIteration:
reference_events = reference_events[:len(images)] # Cut the last reference event if no associated image
self.log.info('End of file reached')
break