def test_stream_accumulate(): ''' test the accumulate function and what it expects as input. ''' # define an acc def myacc(prevstate, newstate): ''' Accumulate on a state and return a next state. Note that accumulator could have returned a newstate, nextout pair. Howevever, in that case, an initializer needs to be defined. This may be unnecessary overhead. ''' nextstate = newstate + prevstate return nextstate s = Stream() sacc = s.accumulate(myacc) # check the start keyword sacc2 = s.accumulate(myacc, start=1) L = sacc.sink_to_list() L2 = sacc2.sink_to_list() s.emit(1) s.emit(1) s.emit(4) # print(L) # should emit on first assert L == [1, 2, 6] # should emit on first assert L2 == [2, 3, 7]
def test_stream_accumulate(): ''' This tests that the dispatching on the streamdoc's accumulate routine is working properly.''' def myacc(prevstate, newstate): return prevstate + newstate s = Stream() sout = s.accumulate(psda(myacc)) L = sout.sink_to_list() sout.emit(StreamDoc(args=[1])) sout.emit(StreamDoc(args=[2])) sout.emit(StreamDoc(args=[3])) print(L)
def test_accumulate_errors_raises(): a = Stream() b = a.accumulate(lambda x, y: x / y) with pytest.raises(ZeroDivisionError): a.emit(1) a.emit(0)
def example2(): source = Stream() source.accumulate(add).sink(print) source.emit(1) source.emit(2) source.emit(3)
def test_accumulate_errors_raises(): a = Stream() b = a.accumulate(lambda x, y: x / y, with_state=True) # noqa: F841 with pytest.raises(ZeroDivisionError): a.emit(1) a.emit(0)