class PipelineExecutor: """ pipeline - dictionary with main key `pipeline`, parsed yaml or any other """ def __init__(self, pipeline_wrapper): self.pipeline_raw = pipeline_wrapper.pipeline self.log_manager = pipeline_wrapper.log_manager self.output_method = pipeline_wrapper.output_method self.prepare_output() if pipeline_valid(self.pipeline_raw)['hasError'] is True: pass def prepare_output(self): self.output_publisher = OutputPublisher() self.output_consumer = OutputMethod[self.output_method].value self.output_publisher.add_consumer(self.output_consumer) def start(self): self.parse_pipeline() def parse_pipeline(self): event = OutputEvent( Signal.a, 'Pipeline parsing started', 'Executor initialized correctly, and Pipeline parsing started at ' + str(datetime.datetime.today())) self.output_publisher.collect(event)
def test_should_add_consumer_with_success(self): publisher = OutputPublisher() consumer = TerminalOutputConsumer() publisher.add_consumer(consumer) self.assertIsNotNone(publisher.consumers) self.assertEqual(1, len(publisher.consumers))
def test_should_not_add_observer_because_type_is_not_OutputConsumer(self): publisher = OutputPublisher() bad_type_consumer = 'string' with self.assertRaises(TypeError): publisher.add_consumer(bad_type_consumer) self.assertIsNotNone(publisher.consumers) self.assertEqual(0, len(publisher.consumers))
def test_should_publishing_without_collecting_events_on_queue(self): publisher = OutputPublisher() consumer = TerminalOutputConsumer() publisher.add_consumer(consumer) event = prepare_event() publisher.publish(event=event) self.assertTrue(consumer._received) self.assertEqual(0, publisher.event_queue.qsize()) self.assertEqual(1, len(publisher.consumers))
def test_should_collect_event_and_publish_it_to_each_consumer(self): publisher = OutputPublisher() consumer = TerminalOutputConsumer() publisher.add_consumer(consumer) event = prepare_event() publisher.collect(event) publisher.publish() self.assertTrue(consumer._received) self.assertEqual(0, publisher.event_queue.qsize()) self.assertEqual(1, len(publisher.consumers))