def test_generate_event_if_over_threshold(): monitor = Monitor(triggers={'test_event': 0.5}, notification_delay=0) # Set up test conditions now = datetime.utcnow() image = load_image() generated_events = [] def event_received(sender, **data): generated_events.append(data) trigger_event.connect(event_received) image_analysis.send('test', source="test_source", timestamp=now, image=image, predictions=[('test_event', 0.99)]) # Verify result expected = dict(timestamp=now, source="test_source", image=image, prediction='test_event', probability=0.99) assert len(generated_events) is 1 assert generated_events[0] == expected
def test_return_images_if_less_than_length(): image_buffer_instance = ImageBuffer(buffer_length=4) # Set up test conditions now = datetime.utcnow() test_image = load_image() image.send('test', source="test_source", timestamp=now, image=test_image) result = get_image_buffer() # Verify result assert len(result) is 1 assert result[0] == test_image
def test_generate_event_once_active_cleared(): monitor = Monitor(triggers={'test_event': 0.5}, notification_delay=0) # Set up test conditions now = datetime.utcnow() image = load_image() generated_events = [] def event_received(sender, **data): generated_events.append(data) trigger_event.connect(event_received) # Trigger initial image_analysis.send('test', source="test_source", timestamp=now, image=image, predictions=[('test_event', 0.99)]) # Clear the first alarm. image_analysis.send('test', source="test_source", timestamp=now + timedelta(seconds=1), image=image, predictions=[('test_event', 0.4)]) # Send the third event image_analysis.send('test', source="test_source", timestamp=now + timedelta(seconds=2), image=image, predictions=[('test_event', 0.99)]) # Verify result expected_first = dict(source="test_source", timestamp=now, image=image, prediction='test_event', probability=0.99) expected_second = dict(source="test_source", timestamp=now + timedelta(seconds=2), image=image, prediction='test_event', probability=0.99) assert len(generated_events) is 2 assert generated_events[0] == expected_first assert generated_events[1] == expected_second
def test_return_buffer_length_images(): buffer_length = 4 image_buffer_instance = ImageBuffer(buffer_length=buffer_length) # Set up test conditions now = datetime.utcnow() test_images = [] for i in xrange(0, buffer_length + 1): test_image = load_image() test_images.append(test_image) image.send('test', source="test_source", timestamp=now + timedelta(seconds=i), image=test_image) result = get_image_buffer() # Verify result assert len(result) is buffer_length offset = len(test_images) - buffer_length for i in xrange(0, len(result)): assert result[i] == test_images[i + offset]