def test_map_errors_log(): a = Stream(asynchronous=True) b = a.delay(0.001).map(lambda x: 1 / x) # noqa: F841 with captured_logger('streamz') as logger: a._emit(0) yield gen.sleep(0.1) out = logger.getvalue() assert 'ZeroDivisionError' in out
def test_accumulate_errors_log(): a = Stream() b = a.delay(0.001).accumulate(lambda x, y: x / y) with captured_logger('streamz') as logger: a._emit(1) a._emit(0) yield gen.sleep(0.1) out = logger.getvalue() assert 'ZeroDivisionError' in out
def test_accumulate_errors_log(): a = Stream(asynchronous=True) b = a.delay(0.001).accumulate(lambda x, y: x / y, with_state=True) # noqa: F841 with captured_logger('streamz') as logger: a._emit(1) a._emit(0) yield gen.sleep(0.1) out = logger.getvalue() assert 'ZeroDivisionError' in out
def test_delay_ref_counts(): source = Stream(asynchronous=True) _ = source.delay(0.01) refs = [] for i in range(5): r = RefCounter() refs.append(r) source.emit(i, metadata=[{'ref': r}]) assert all(r.count == 1 for r in refs) yield gen.sleep(0.05) assert all(r.count == 0 for r in refs)
def test_delay(): source = Stream() L = source.delay(0.02).sink_to_list() for i in range(5): yield source.emit(i) assert not L yield gen.sleep(0.04) assert len(L) < 5 yield gen.sleep(0.1) assert len(L) == 5