/tests/net/test_client.py

https://bitbucket.org/prologic/circuits/ · Python · 47 lines · 25 code · 21 blank · 1 comment · 0 complexity · af4958af6b41cdf9c23f0cda05e6cce1 MD5 · raw file

  1. #!/usr/bin/env python
  2. from socket import gaierror
  3. def test_client_bind_int():
  4. from circuits.net.sockets import Client
  5. class TestClient(Client):
  6. def _create_socket(self):
  7. return None
  8. client = TestClient(1234)
  9. assert client._bind[1] == 1234
  10. def test_client_bind_int_gaierror(monkeypatch):
  11. from circuits.net import sockets
  12. def broken_gethostname():
  13. raise gaierror()
  14. monkeypatch.setattr(sockets, "gethostname", broken_gethostname)
  15. class TestClient(sockets.Client):
  16. def _create_socket(self):
  17. return None
  18. client = TestClient(1234)
  19. assert client._bind == ("0.0.0.0", 1234)
  20. def test_client_bind_str():
  21. from circuits.net.sockets import Client
  22. class TestClient(Client):
  23. def _create_socket(self):
  24. return None
  25. client = TestClient("0.0.0.0:1234")
  26. assert client._bind == ("0.0.0.0", 1234)