def setup_module(module): """ setup any state specific to the execution of the given module.""" # Reset default class interpreter.PIPELINE_CLASS = None interpreter.Pipeline.PIPELINE_OPS['source'] = AVSourceElement _TestPipeline.PIPELINE_OPS['source'] = AVSourceElement config_manager.stop()
def _configure(env_work_dir=None): """Load configuration settings. :returns config dict if configuration was loaded without issues. None or a specific exception otherwise. """ assert env_work_dir, 'Working directory required.' assert os.path.exists(env_work_dir), \ 'working directory invalid: {}'.format(env_work_dir) config_manager.stop() def logging_config_handler(config): # configure logging logging_config = None if config: logging_config = config.get('logging', None) _configure_logging(logging_config) config_manager.register_handler(logging_config_handler) def timeline_config_handler(config): # configure pipeline timeline event log timeline_config = None if config: timeline_config = config.get('timeline', None) timeline.configure_timeline(timeline_config) config_manager.register_handler(timeline_config_handler) config_manager.load(env_work_dir) return config_manager.get()
def test_pipeline_reload_delete_source_ref(): """Test that when a source reference changes, the pipeline reload""" interpreter.PIPELINE_CLASS = _TestPipeline config_manager.stop() config_manager.set({ "sources": { "source1": { "uri": "test", "type": "video", "live": False } }, "pipelines": { "pipeline1": [{ "source": "source1" }] } }) config = config_manager.get() p = _one_pipeline_setup(config.get("pipelines")) p[0].start() pe = p[0]._pipe_elements[0] assert p[0]._pipe_elements[0].state == pipeline.PIPE_STATE_RUNNING assert pe.start_called del config["sources"]["source1"] assert p[0].restart_called assert len(p[0]._pipe_elements) == 0
def test_pipeline_ai_model_config(): """Test the source ref is resolved""" config_manager.stop() config_manager.set({ "ai_models": { "test": { "labels": "ai_models/coco_labels.txt", "model": { "tflite": "ai_models/mobilenet_ssd_v2_coco_quant_postprocess.tflite", } } }, "pipelines": { "pipeline1": [{ "source": { "uri": "test" } }, { "detect_objects": { "ai_model": "test", "confidence_threshold": 0.0 } }] } }) p = _one_pipeline_setup(config_manager.get_pipelines()) p[0].load_elements() log.debug(p[0]._pipe_elements[1]) assert len(p[0]._pipe_elements) == 2 assert p[0]._pipe_elements[1]._tfengine._confidence_threshold == 0.0
def test_pipeline_reload_sources_ref(): """Test that when a source reference changes, the pipeline reload""" config_manager.stop() config_manager.set({ "sources": { "source1": { "uri": "test", "type": "video", "live": False } }, "pipelines": { "pipeline1": [{ "source": "source1" }] } }) config = config_manager.get() p = _one_pipeline_setup(config.get("pipelines")) p[0].start() pe = p[0]._pipe_elements[0] assert p[0]._pipe_elements[0].state == pipeline.PIPE_STATE_RUNNING assert pe.start_called config["sources"]["source1"]["uri"] = "test2" log.debug(p[0]._pipe_elements[0].config) assert p[0]._pipe_elements[0].config['uri'] == 'test2'
def get_test_config(): config_manager.stop() config_manager.CONFIG_FILE = 'test-sources.yaml' _dir = os.path.dirname(os.path.abspath(__file__)) config = config_manager.load(_dir) assert config is not None return config
def teardown_module(module): """ teardown any state that was previously setup with a setup_module method.""" # Reset default class interpreter.PIPELINE_CLASS = None interpreter.Pipeline.PIPELINE_OPS['source'] = AVSourceElement _TestPipeline.PIPELINE_OPS['source'] = AVSourceElement config_manager.stop()
def test_handlers_mgm(): def test1(config): pass # reset state config_manager.stop() assert len(config_manager.handlers) == 0 config_manager.register_handler(test1) assert len(config_manager.handlers) == 1 config_manager.unregister_handler(test1) assert len(config_manager.handlers) == 0
def test_config_getters(): config_manager.stop() config_manager.CONFIG_FILE = 'test-config2.yaml' _dir = os.path.dirname(os.path.abspath(__file__)) config_manager.load(_dir) assert config_manager.get_ai_models() is not None assert config_manager.get_ai_model("image_detection") is not None assert config_manager.get_sources() is not None assert config_manager.get_source("front_door_camera") is not None assert config_manager.get_data_dir() is not None
def _configure(env_work_dir=None): """Load configuration settings. :returns config dict if configuration was loaded without issues. None or a specific exception otherwise. """ assert env_work_dir, 'Working directory required.' assert os.path.exists(env_work_dir), \ 'working directory invalid: {}'.format(env_work_dir) config_manager.stop() config = config_manager.load(env_work_dir) if config is None: return None def logging_config_handler(event: ConfigChangedEvent): # configure logging log.info("Reconfiguring logging") _configure_logging(config.get("logging")) def timeline_config_handler(event: ConfigChangedEvent): # configure pipeline timeline event log log.info("Reconfiguring pipeline timeline event log") timeline.configure_timeline(config.get("timeline")) # set callback to react to specific configuration changes if config.get("logging", None) is not None: config.get("logging").add_callback(logging_config_handler) if config.get("timeline", None) is not None: config.get("timeline").add_callback(timeline_config_handler) # initialize logging logging_config_handler(None) timeline_config_handler(None) return config
def _stop_servers(self, servers): log.debug('Stopping servers...') for srv in servers.values(): srv.stop() config_manager.stop()
def teardown_module(module): """ teardown any state that was previously setup with a setup_module method.""" config_manager.stop()
def setup_module(module): """ setup any state specific to the execution of the given module.""" config_manager.stop()
def test_clean_stop(): config_manager.CONFIG_FILE = 'test-config.yaml' _dir = os.path.dirname(os.path.abspath(__file__)) config_manager.load(_dir) config_manager.stop() assert config_manager.watch_thread is None
def reset_config(): config_manager.stop() config_manager.set({"data_dir": "./data", "sources": {}})