# Path: thingflow/filters/map.py
# @filtermethod(OutputThing, alias="select")
# def map(this, mapfun):
#     """Returns a stream whose elements are the result of
#     invoking the transform function on each element of source.
#     If the function returns None, no event is passed downstream.
#     """
#     def on_next(self, x):
#         y = mapfun(x)
#         if y is not None:
#             self._dispatch_next(y)
#     return FunctionFilter(this, on_next, name='map')
# 
# Path: thingflow/filters/output.py
# @filtermethod(OutputThing)
# def output(this, file=stdout):
#     """Print each element of the sequence. Exceptions are printed
#     as well. We don't call it print, because that will override the
#     built-in print function.
#     """
#     return Output(this, file=file)
# 
# Path: thingflow/filters/combinators.py
# @filtermethod(OutputThing)
# def passthrough(this, spur):
#     """We wish to have a spur off a chain of filters. For example, a writer that
#     is a InputThing, but does not implement the OutputThing API. Thus, we have no
#     way to put it in the middle of a chain. Or, we might want to implement a
#     "fork" in the chain of filters, with two parallel downstream chains.
#     
#     passthrough takes "this", the previous OutputThing in the chain, and "spur",
#     either a InputThing, a thunk (a function that takes the OutputThing as its
#     single argument), or a plain anonymous function. The spur is connected to
#     the OutputThing and then the OutputThing is returned to continue the chain.
#     """
#     _connect_thunk(this, spur)
#     return this


import unittest
import asyncio
from thingflow.base import *
from utils import ValueListSensor, ValidationInputThing
from thingflow.filters.map import map
from thingflow.filters.output import output
from thingflow.filters.combinators import passthrough
"""Test that tracing works properly.
The automated test only verifies that tracing does not cause
a crash. You have to verify the actual messages manually
"""

values = [1,2,3,4,5]

class TestTracing(unittest.TestCase):
    def test_tracing(self):
        s = ValueListSensor(1, values)
        p = SensorAsOutputThing(s)
        v = ValidationInputThing([v+1 for v in values], self,
                                 extract_value_fn=lambda x:x)

# Path: thingflow/filters/map.py
# @filtermethod(OutputThing, alias="select")
# def map(this, mapfun):
#     """Returns a stream whose elements are the result of
#     invoking the transform function on each element of source.
#     If the function returns None, no event is passed downstream.
#     """
#     def on_next(self, x):
#         y = mapfun(x)
#         if y is not None:
#             self._dispatch_next(y)
#     return FunctionFilter(this, on_next, name='map')
# 
# Path: thingflow/filters/output.py
# @filtermethod(OutputThing)
# def output(this, file=stdout):
#     """Print each element of the sequence. Exceptions are printed
#     as well. We don't call it print, because that will override the
#     built-in print function.
#     """
#     return Output(this, file=file)
# 
# Path: thingflow/filters/combinators.py
# @filtermethod(OutputThing)
# def passthrough(this, spur):
#     """We wish to have a spur off a chain of filters. For example, a writer that
#     is a InputThing, but does not implement the OutputThing API. Thus, we have no
#     way to put it in the middle of a chain. Or, we might want to implement a
#     "fork" in the chain of filters, with two parallel downstream chains.
#     
#     passthrough takes "this", the previous OutputThing in the chain, and "spur",
#     either a InputThing, a thunk (a function that takes the OutputThing as its
#     single argument), or a plain anonymous function. The spur is connected to
#     the OutputThing and then the OutputThing is returned to continue the chain.
#     """
#     _connect_thunk(this, spur)
#     return this


# Path: tests/test_tracing.py
import unittest
import asyncio
from thingflow.base import *
from utils import ValueListSensor, ValidationInputThing
from thingflow.filters.map import map
from thingflow.filters.output import output
from thingflow.filters.combinators import passthrough

"""Test that tracing works properly.
The automated test only verifies that tracing does not cause
a crash. You have to verify the actual messages manually
"""

values = [1,2,3,4,5]

class TestTracing(unittest.TestCase):
    def test_tracing(self):
        s = ValueListSensor(1, values)
        p = SensorAsOutputThing(s)
        v = ValidationInputThing([v+1 for v in values], self,
                                 extract_value_fn=lambda x:x)

        p.passthrough(output).map(lambda x : x.val+1).passthrough(output).connect(v)