/tests/net/test_pipe.py

https://bitbucket.org/prologic/circuits/ · Python · 47 lines · 31 code · 15 blank · 1 comment · 3 complexity · 1b74567e4cf3476de3e604ae8c2e759b MD5 · raw file

  1. #!/usr/bin/env python
  2. import pytest
  3. if pytest.PLATFORM == "win32":
  4. pytest.skip("Unsupported Platform")
  5. from circuits import Manager
  6. from circuits.net.sockets import Pipe
  7. from circuits.core.pollers import Select
  8. from circuits.net.events import close, write
  9. from .client import Client
  10. def pytest_generate_tests(metafunc):
  11. metafunc.addcall(funcargs={"Poller": Select})
  12. def test_pipe(Poller):
  13. m = Manager() + Poller()
  14. a, b = Pipe("a", "b")
  15. a.register(m)
  16. b.register(m)
  17. a = Client(channel=a.channel).register(m)
  18. b = Client(channel=b.channel).register(m)
  19. m.start()
  20. try:
  21. assert pytest.wait_for(a, "ready")
  22. assert pytest.wait_for(b, "ready")
  23. a.fire(write(b"foo"))
  24. assert pytest.wait_for(b, "data", b"foo")
  25. b.fire(write(b"foo"))
  26. assert pytest.wait_for(a, "data", b"foo")
  27. a.fire(close())
  28. assert pytest.wait_for(a, "disconnected")
  29. b.fire(close())
  30. assert pytest.wait_for(b, "disconnected")
  31. finally:
  32. m.stop()