Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_socket.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # mypy: always-true=inet_pton
  2. try:
  3. from socket import inet_pton
  4. except ImportError:
  5. inet_pton = None # type: ignore[assignment]
  6. if not inet_pton:
  7. import socket
  8. from .common import HyperlinkTestCase
  9. from .._socket import inet_pton
  10. class TestSocket(HyperlinkTestCase):
  11. def test_inet_pton_ipv4_valid(self):
  12. # type: () -> None
  13. data = inet_pton(socket.AF_INET, "127.0.0.1")
  14. assert isinstance(data, bytes)
  15. def test_inet_pton_ipv4_bogus(self):
  16. # type: () -> None
  17. with self.assertRaises(socket.error):
  18. inet_pton(socket.AF_INET, "blah")
  19. def test_inet_pton_ipv6_valid(self):
  20. # type: () -> None
  21. data = inet_pton(socket.AF_INET6, "::1")
  22. assert isinstance(data, bytes)
  23. def test_inet_pton_ipv6_bogus(self):
  24. # type: () -> None
  25. with self.assertRaises(socket.error):
  26. inet_pton(socket.AF_INET6, "blah")
  27. def test_inet_pton_bogus_family(self):
  28. # type: () -> None
  29. # Find an integer not associated with a known address family
  30. i = int(socket.AF_INET6)
  31. while True:
  32. if i != socket.AF_INET and i != socket.AF_INET6:
  33. break
  34. i += 100
  35. with self.assertRaises(socket.error):
  36. inet_pton(i, "127.0.0.1")