test_tracing.py 1022 B

123456789101112131415161718192021222324252627282930
  1. """Test that tracing works properly.
  2. The automated test only verifies that tracing does not cause
  3. a crash. You have to verify the actual messages manually
  4. """
  5. import unittest
  6. import asyncio
  7. from thingflow.base import *
  8. from utils import ValueListSensor, ValidationInputThing
  9. from thingflow.filters.map import map
  10. from thingflow.filters.output import output
  11. from thingflow.filters.combinators import passthrough
  12. values = [1,2,3,4,5]
  13. class TestTracing(unittest.TestCase):
  14. def test_tracing(self):
  15. s = ValueListSensor(1, values)
  16. p = SensorAsOutputThing(s)
  17. v = ValidationInputThing([v+1 for v in values], self,
  18. extract_value_fn=lambda x:x)
  19. p.passthrough(output).map(lambda x : x.val+1).passthrough(output).connect(v)
  20. p.trace_downstream()
  21. scheduler = Scheduler(asyncio.get_event_loop())
  22. scheduler.schedule_periodic(p, 0.5) # sample twice every second
  23. scheduler.run_forever()
  24. if __name__ == '__main__':
  25. unittest.main()