Пример #1
0
def test_ForkedFeeder():
	result = ForkedFeeder(blocking_producer) >> StreamMap(f) >> sreduce(operator.add)
	pprint(result)
	assert result == expected
Пример #2
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from src.cstream import ThreadedFeeder, ForkedFeeder, StreamMap, sreduce


## Test scenario based on ../example/feeder.py

def blocking_producer():
	for n in range(25):
		time.sleep(0.01)
		yield 42

f = lambda x: x**2

expected = blocking_producer() >> StreamMap(f) >> sreduce(operator.add)


## Test cases

def test_ThreadedFeeder():
	result = ThreadedFeeder(blocking_producer) >> StreamMap(f) >> sreduce(operator.add)
	pprint(result)
	assert result == expected

def test_ForkedFeeder():
	result = ForkedFeeder(blocking_producer) >> StreamMap(f) >> sreduce(operator.add)
	pprint(result)
	assert result == expected