Exemplo n.º 1
0
 def test_schedule_sensor(self):
     """In this version, we pass the sensor directly to the scheduler and use
     a functional style to compose the filters"""
     s = ValueListSensor(1, value_stream)
     vo = ValidationInputThing(expected_stream, self.test_schedule_sensor)
     scheduler = Scheduler(asyncio.get_event_loop())
     scheduler.schedule_sensor(s, 0.5, where(predicate), passthrough(vo),
                               output())
     scheduler.run_forever()
     self.assertTrue(
         vo.completed,
         "Schedule exited before validation observer completed")
     print("That's all folks")
 def test_thunk_builder_handling(self):
     """We have logic where we can pass a thunk builder into a combinator and
     it will do the right thing. Check that it works"""
     scheduler = Scheduler(asyncio.get_event_loop())
     lux = ValueListSensor('lux-2', lux_data)
     vs = ValidationInputThing(lux_data, self)
     scheduler.schedule_sensor(
         lux,
         0.5,
         passthrough(output()),  # output() evaluates to a thunk
         passthrough(output),  # output is a thunk builder
         passthrough(output(sys.stdout)),  # output can take an arg
         vs,
         print_downstream=True)
     scheduler.run_forever()
     self.assertTrue(vs.completed)
 def test_publish_and_subscribe(self):
     sensor = ValueListSensor(1, sensor_values)
     scheduler = Scheduler(asyncio.get_event_loop())
     pg = PostgresWriter(scheduler, self.connect_string, self.mapping)
     capture = CaptureInputThing()
     scheduler.schedule_sensor(sensor, 0.5,
                               parallel(pg, output, capture))
     scheduler.run_forever()
     print("finish writing to the database")
     row_source = PostgresReader(self.connect_string, self.mapping)
     row_source.output()
     validate = SensorEventValidationInputThing(capture.seq, self)
     row_source.connect(validate)
     scheduler.schedule_recurring(row_source)
     scheduler.run_forever()
     self.assertTrue(validate.completed)
     print("finished reading rows")
Exemplo n.º 4
0
class TestCase(unittest.TestCase):
    def setUp(self):
        self.scheduler = Scheduler(asyncio.get_event_loop())
        self.sensor = ValueListSensor(1, value_stream)
        
    def test_sensor_event_sliding_window(self):
        vs = ValidationInputThing(mean_stream, self)
        self.scheduler.schedule_sensor(self.sensor, 0.1,
                                       transduce(SensorSlidingMean(4)),
                                       parallel(vs, output()))
        self.scheduler.run_forever()
        self.assertTrue(vs.completed)

    def test_periodic_median_transducer(self):
        vs = ValidationInputThing(periodic_median_stream, self)
        self.scheduler.schedule_sensor(self.sensor, 0.1,
                                       transduce(PeriodicMedianTransducer(3)),
                                       parallel(vs, output()))
        self.scheduler.run_forever()
        self.assertTrue(vs.completed)
 def test_complex_workflow(self):
     THRESHOLD = 300
     lux = ValueListSensor('lux-1', lux_data)
     scheduler = Scheduler(asyncio.get_event_loop())
     vs1 = ValidationInputThing(lux_data, self)
     vs2 = ValidationInputThing(
         [False, False, False, True, False, False, True],
         self,
         extract_value_fn=lambda v: v)
     scheduler.schedule_sensor(
         lux,
         0.5,
         passthrough(output()),
         passthrough(vs1),
         map(lambda event: event.val > THRESHOLD),
         passthrough(lambda v: print('ON' if v else 'OFF')),
         vs2,
         print_downstream=True)
     scheduler.run_forever()
     self.assertTrue(vs1.completed)
     self.assertTrue(vs2.completed)
     print("That's all folks")