def test_create(): from kwiver.vital.config import config from kwiver.sprokit.pipeline import pipeline c = config.empty_config() pipeline.Pipeline() pipeline.Pipeline(c)
def test_register(): from kwiver.vital.config import config from kwiver.vital.modules import modules from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import scheduler_factory modules.load_known_modules() sched_type = 'python_example' sched_desc = 'simple description' scheduler_factory.add_scheduler(sched_type, sched_desc, example_scheduler(True)) if not sched_desc == scheduler_factory.description(sched_type): test_error("Description was not preserved when registering") p = pipeline.Pipeline() try: s = scheduler_factory.create_scheduler(sched_type, p) if s is None: raise Exception() except: test_error("Could not create newly registered scheduler type")
def test_python_to_python(sched_type): from kwiver.vital.config import config from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import process name_source = 'source' name_sink = 'sink' port_output = 'number' port_input = 'number' min = 0 max = 10 output_file = 'test-python-run-python_to_python.txt' c = config.empty_config() c.set_value(process.PythonProcess.config_name, name_source) c.set_value('start', str(min)) c.set_value('end', str(max)) s = make_source(c) c = config.empty_config() c.set_value(process.PythonProcess.config_name, name_sink) c.set_value('output', output_file) t = make_sink(c) p = pipeline.Pipeline(c) p.add_process(s) p.add_process(t) p.connect(name_source, port_output, name_sink, port_input) p.setup_pipeline() run_pipeline(sched_type, p, c) check_file(output_file, list(range(min, max))) if t.stepped and not t.finalized: test_error("sink process not finalized")
def test_api_calls(): from kwiver.vital.config import config from kwiver.vital.modules import modules from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import scheduler_factory modules.load_known_modules() sched_type = 'thread_per_process' c = config.empty_config() p = pipeline.Pipeline() scheduler_factory.create_scheduler(sched_type, p) scheduler_factory.create_scheduler(sched_type, p, c) scheduler_factory.types() scheduler_factory.description(sched_type) scheduler_factory.default_type
def test_wrapper_api(): from kwiver.vital.config import config from kwiver.vital.modules import modules from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import process_factory from kwiver.sprokit.pipeline import scheduler_factory sched_type = 'python_example' sched_desc = 'simple description' modules.load_known_modules() scheduler_factory.add_scheduler(sched_type, sched_desc, example_scheduler(False)) p = pipeline.Pipeline() proc_type = 'orphan' proc_name = 'orphan' proc = process_factory.create_process(proc_type, proc_name) p.add_process(proc) def check_scheduler(s): if s is None: test_error("Got a 'None' scheduler") return s.start() s.pause() s.resume() s.stop() s.start() s.wait() del s p.reset() p.setup_pipeline() s = scheduler_factory.create_scheduler(sched_type, p) check_scheduler(s)
def test_python_to_cpp(sched_type): from kwiver.vital.config import config from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import process name_source = 'source' name_sink = 'sink' port_output = 'number' port_input = 'number' min = 0 max = 10 output_file = 'test-python-run-python_to_cpp.txt' c = config.empty_config() c.set_value(process.PythonProcess.config_name, name_source) c.set_value('start', str(min)) c.set_value('end', str(max)) s = make_source(c) c = config.empty_config() c.set_value('output', output_file) t = create_process('print_number', name_sink, c) p = pipeline.Pipeline() p.add_process(s) p.add_process(t) p.connect(name_source, port_output, name_sink, port_input) p.setup_pipeline() run_pipeline(sched_type, p, c) check_file(output_file, list(range(min, max)))
def test_api_calls(): from kwiver.vital.config import config from kwiver.sprokit.pipeline import edge from kwiver.vital.modules import modules from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import process from kwiver.sprokit.pipeline import process_cluster from kwiver.sprokit.pipeline import process_factory p = pipeline.Pipeline() proc_type1 = 'numbers' proc_type2 = 'print_number' proc_type3 = 'orphan_cluster' proc_name1 = 'src' proc_name2 = 'snk' proc_name3 = 'orp' port_name1 = 'number' port_name2 = 'number' modules.load_known_modules() proc1 = process_factory.create_process(proc_type1, proc_name1) conf_name = 'output' c = config.empty_config() c.set_value(conf_name, 'test-python-pipeline-api_calls-print_number.txt') proc2 = process_factory.create_process(proc_type2, proc_name2, c) proc3 = process_factory.create_process(proc_type3, proc_name3) p.add_process(proc1) p.add_process(proc2) p.add_process(proc3) p.connect(proc_name1, port_name1, proc_name2, port_name2) p.process_names() p.process_by_name(proc_name1) p.cluster_names() p.cluster_by_name(proc_name3) p.connections_from_addr(proc_name1, port_name1) p.connection_to_addr(proc_name2, port_name2) p.disconnect(proc_name1, port_name1, proc_name2, port_name2) p.remove_process(proc_name1) p.remove_process(proc_name3) # Restore the pipeline so that setup_pipeline works. p.add_process(proc1) p.connect(proc_name1, port_name1, proc_name2, port_name2) p.setup_pipeline() p.upstream_for_process(proc_name2) p.upstream_for_port(proc_name2, port_name2) p.downstream_for_process(proc_name1) p.downstream_for_port(proc_name1, port_name1) p.sender_for_port(proc_name2, port_name2) p.receivers_for_port(proc_name1, port_name1) p.edge_for_connection(proc_name1, port_name1, proc_name2, port_name2) p.input_edges_for_process(proc_name2) p.input_edge_for_port(proc_name2, port_name2) p.output_edges_for_process(proc_name1) p.output_edges_for_port(proc_name1, port_name1) p.is_setup() p.setup_successful() c = config.empty_config() p.reconfigure(c) p.reset()
def test_python_via_cpp(sched_type): from kwiver.vital.config import config from kwiver.sprokit.pipeline import pipeline from kwiver.sprokit.pipeline import process name_source1 = 'source1' name_source2 = 'source2' name_mult = 'mult' name_sink = 'sink' port_output = 'number' port_input1 = 'src/1' port_input2 = 'src/2' port_output1 = 'out/1' port_output2 = 'out/2' port_factor1 = 'factor1' port_factor2 = 'factor2' port_product = 'product' port_input = 'number' min1 = 0 max1 = 10 min2 = 10 max2 = 15 output_file = 'test-python-run-python_via_cpp.txt' c = config.empty_config() c.set_value(process.PythonProcess.config_name, name_source1) c.set_value('start', str(min1)) c.set_value('end', str(max1)) s1 = make_source(c) c = config.empty_config() c.set_value(process.PythonProcess.config_name, name_source2) c.set_value('start', str(min2)) c.set_value('end', str(max2)) s2 = make_source(c) c = config.empty_config() m = create_process('multiplication', name_mult, c) c = config.empty_config() c.set_value(process.PythonProcess.config_name, name_sink) c.set_value('output', output_file) t = make_sink(c) p = pipeline.Pipeline() p.add_process(s1) p.add_process(s2) p.add_process(m) p.add_process(t) p.connect(name_source1, port_output, name_mult, port_factor1) p.connect(name_source2, port_output, name_mult, port_factor2) p.connect(name_mult, port_product, name_sink, port_input) p.setup_pipeline() run_pipeline(sched_type, p, c) check_file(output_file, [a * b for a, b in zip(list(range(min1, max1)), list(range(min2, max2)))])