multiplexer_test.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import unittest
  2. from compose.cli.multiplexer import Multiplexer
  3. class MultiplexerTest(unittest.TestCase):
  4. def test_no_iterators(self):
  5. mux = Multiplexer([])
  6. self.assertEqual([], list(mux.loop()))
  7. def test_empty_iterators(self):
  8. mux = Multiplexer([
  9. (x for x in []),
  10. (x for x in []),
  11. ])
  12. self.assertEqual([], list(mux.loop()))
  13. def test_aggregates_output(self):
  14. mux = Multiplexer([
  15. (x for x in [0, 2, 4]),
  16. (x for x in [1, 3, 5]),
  17. ])
  18. self.assertEqual(
  19. [0, 1, 2, 3, 4, 5],
  20. sorted(list(mux.loop())),
  21. )
  22. def test_exception(self):
  23. class Problem(Exception):
  24. pass
  25. def problematic_iterator():
  26. yield 0
  27. yield 2
  28. raise Problem(":(")
  29. mux = Multiplexer([
  30. problematic_iterator(),
  31. (x for x in [1, 3, 5]),
  32. ])
  33. with self.assertRaises(Problem):
  34. list(mux.loop())