blakeblackshear.frigate/frigate/test/test_config.py

182 lines
5.3 KiB
Python
Raw Normal View History

2020-11-01 13:17:44 +01:00
import json
from unittest import TestCase, main
import voluptuous as vol
2020-11-03 15:15:58 +01:00
from frigate.config import FRIGATE_CONFIG_SCHEMA, FrigateConfig
2020-11-01 13:17:44 +01:00
class TestConfig(TestCase):
2020-11-03 15:15:58 +01:00
def setUp(self):
self.minimal = {
'mqtt': {
'host': 'mqtt'
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
},
'height': 1080,
'width': 1920
}
}
}
2020-11-01 13:17:44 +01:00
def test_empty(self):
FRIGATE_CONFIG_SCHEMA({})
def test_minimal(self):
2020-11-03 15:15:58 +01:00
FRIGATE_CONFIG_SCHEMA(self.minimal)
def test_config_class(self):
FrigateConfig(config=self.minimal)
def test_inherit_tracked_objects(self):
config = {
'mqtt': {
'host': 'mqtt'
},
'objects': {
'track': ['person', 'dog']
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
},
'height': 1080,
'width': 1920
}
}
}
frigate_config = FrigateConfig(config=config)
assert('dog' in frigate_config.cameras['back'].objects.track)
def test_override_tracked_objects(self):
config = {
'mqtt': {
'host': 'mqtt'
},
'objects': {
'track': ['person', 'dog']
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
},
'height': 1080,
'width': 1920,
'objects': {
'track': ['cat']
}
}
}
}
frigate_config = FrigateConfig(config=config)
assert('cat' in frigate_config.cameras['back'].objects.track)
def test_default_object_filters(self):
config = {
'mqtt': {
'host': 'mqtt'
},
'objects': {
'track': ['person', 'dog']
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
},
'height': 1080,
'width': 1920
}
}
}
frigate_config = FrigateConfig(config=config)
assert('dog' in frigate_config.cameras['back'].objects.filters)
def test_inherit_object_filters(self):
config = {
'mqtt': {
'host': 'mqtt'
},
'objects': {
'track': ['person', 'dog'],
'filters': {
'dog': {
'threshold': 0.7
}
}
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
},
'height': 1080,
'width': 1920
}
}
}
frigate_config = FrigateConfig(config=config)
assert('dog' in frigate_config.cameras['back'].objects.filters)
assert(frigate_config.cameras['back'].objects.filters['dog'].threshold == 0.7)
def test_override_object_filters(self):
config = {
'mqtt': {
'host': 'mqtt'
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
},
'height': 1080,
'width': 1920,
'objects': {
'track': ['person', 'dog'],
'filters': {
'dog': {
'threshold': 0.7
}
}
}
}
}
}
frigate_config = FrigateConfig(config=config)
assert('dog' in frigate_config.cameras['back'].objects.filters)
assert(frigate_config.cameras['back'].objects.filters['dog'].threshold == 0.7)
def test_ffmpeg_params(self):
config = {
'ffmpeg': {
'input_args': ['-re']
},
2020-11-01 13:17:44 +01:00
'mqtt': {
'host': 'mqtt'
},
'cameras': {
'back': {
'ffmpeg': {
'input': 'rtsp://10.0.0.1:554/video'
2020-11-03 15:15:58 +01:00
},
'height': 1080,
'width': 1920,
'objects': {
'track': ['person', 'dog'],
'filters': {
'dog': {
'threshold': 0.7
}
}
2020-11-01 13:17:44 +01:00
}
}
}
}
2020-11-03 15:15:58 +01:00
frigate_config = FrigateConfig(config=config)
assert('-re' in frigate_config.cameras['back'].ffmpeg_cmd)
2020-11-01 13:17:44 +01:00
if __name__ == '__main__':
main(verbosity=2)