def test_callback_offset_chain(self): """pass a callback in rather than retrieving a keyed collection.""" def cback(collection, window_key, group_by): # pylint: disable=unused-argument """callback to pass in.""" global RESULTS # pylint: disable=global-statement RESULTS = collection timeseries = TimeSeries(DATA) ( Pipeline() .from_source(timeseries.collection()) .offset_by(1, 'value') .offset_by(2) .to(CollectionOut, cback) ) # Spurious lint error due to upstream tinkering # with the global variable # pylint: disable=no-member self.assertEqual(RESULTS.at(0).get(), 55) self.assertEqual(RESULTS.at(1).get(), 21) self.assertEqual(RESULTS.at(2).get(), 29) self.assertEqual(RESULTS.at(3).get(), 96)
def test_simple_offset_chain(self): """test a simple offset chain.""" timeseries = TimeSeries(DATA) kcol = (Pipeline().from_source(timeseries.collection()).offset_by( 1, 'value').offset_by(2).to_keyed_collections()) self.assertEqual(kcol['all'].at(0).get(), 55) self.assertEqual(kcol['all'].at(1).get(), 21) self.assertEqual(kcol['all'].at(2).get(), 29) self.assertEqual(kcol['all'].at(3).get(), 96)
def test_simple_offset_chain(self): """test a simple offset chain.""" timeseries = TimeSeries(DATA) kcol = ( Pipeline() .from_source(timeseries.collection()) .offset_by(1, 'value') .offset_by(2) .to_keyed_collections() ) self.assertEqual(kcol['all'].at(0).get(), 55) self.assertEqual(kcol['all'].at(1).get(), 21) self.assertEqual(kcol['all'].at(2).get(), 29) self.assertEqual(kcol['all'].at(3).get(), 96)
def test_map(self): """test .map()""" def mapper(event): """swap in and out.""" return event.set_data({ 'in': event.get('out'), 'out': event.get('in') }) timeseries = TimeSeries(IN_OUT_DATA) # this pointless bit is for coverage pip = Pipeline() kcol = (Pipeline(pip).from_source(timeseries.collection()).map( mapper).emit_on('flush').to_keyed_collections()) self.assertEqual(kcol.get('all').at(0).get('in'), 37) self.assertEqual(kcol.get('all').at(0).get('out'), 80)
def test_callback_offset_chain(self): """pass a callback in rather than retrieving a keyed collection.""" def cback(collection, window_key, group_by): # pylint: disable=unused-argument """callback to pass in.""" global RESULTS # pylint: disable=global-statement RESULTS = collection timeseries = TimeSeries(DATA) (Pipeline().from_source(timeseries.collection()).offset_by( 1, 'value').offset_by(2).to(CollectionOut, cback)) # Spurious lint error due to upstream tinkering # with the global variable # pylint: disable=no-member self.assertEqual(RESULTS.at(0).get(), 55) self.assertEqual(RESULTS.at(1).get(), 21) self.assertEqual(RESULTS.at(2).get(), 29) self.assertEqual(RESULTS.at(3).get(), 96)
def test_map(self): """test .map()""" def mapper(event): """swap in and out.""" return event.set_data({'in': event.get('out'), 'out': event.get('in')}) timeseries = TimeSeries(IN_OUT_DATA) # this pointless bit is for coverage pip = Pipeline() kcol = ( Pipeline(pip) .from_source(timeseries.collection()) .map(mapper) .emit_on('flush') .to_keyed_collections() ) self.assertEqual(kcol.get('all').at(0).get('in'), 37) self.assertEqual(kcol.get('all').at(0).get('out'), 80)