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_abstract.py 3.4KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for generic file descriptor based reactor support code.
  5. """
  6. from socket import AF_IPX
  7. from twisted.internet.abstract import isIPAddress
  8. from twisted.trial.unittest import TestCase
  9. class AddressTests(TestCase):
  10. """
  11. Tests for address-related functionality.
  12. """
  13. def test_decimalDotted(self):
  14. """
  15. L{isIPAddress} should return C{True} for any decimal dotted
  16. representation of an IPv4 address.
  17. """
  18. self.assertTrue(isIPAddress("0.1.2.3"))
  19. self.assertTrue(isIPAddress("252.253.254.255"))
  20. def test_shortDecimalDotted(self):
  21. """
  22. L{isIPAddress} should return C{False} for a dotted decimal
  23. representation with fewer or more than four octets.
  24. """
  25. self.assertFalse(isIPAddress("0"))
  26. self.assertFalse(isIPAddress("0.1"))
  27. self.assertFalse(isIPAddress("0.1.2"))
  28. self.assertFalse(isIPAddress("0.1.2.3.4"))
  29. def test_invalidLetters(self):
  30. """
  31. L{isIPAddress} should return C{False} for any non-decimal dotted
  32. representation including letters.
  33. """
  34. self.assertFalse(isIPAddress("a.2.3.4"))
  35. self.assertFalse(isIPAddress("1.b.3.4"))
  36. def test_invalidPunctuation(self):
  37. """
  38. L{isIPAddress} should return C{False} for a string containing
  39. strange punctuation.
  40. """
  41. self.assertFalse(isIPAddress(","))
  42. self.assertFalse(isIPAddress("1,2"))
  43. self.assertFalse(isIPAddress("1,2,3"))
  44. self.assertFalse(isIPAddress("1.,.3,4"))
  45. def test_emptyString(self):
  46. """
  47. L{isIPAddress} should return C{False} for the empty string.
  48. """
  49. self.assertFalse(isIPAddress(""))
  50. def test_invalidNegative(self):
  51. """
  52. L{isIPAddress} should return C{False} for negative decimal values.
  53. """
  54. self.assertFalse(isIPAddress("-1"))
  55. self.assertFalse(isIPAddress("1.-2"))
  56. self.assertFalse(isIPAddress("1.2.-3"))
  57. self.assertFalse(isIPAddress("1.2.-3.4"))
  58. def test_invalidPositive(self):
  59. """
  60. L{isIPAddress} should return C{False} for a string containing
  61. positive decimal values greater than 255.
  62. """
  63. self.assertFalse(isIPAddress("256.0.0.0"))
  64. self.assertFalse(isIPAddress("0.256.0.0"))
  65. self.assertFalse(isIPAddress("0.0.256.0"))
  66. self.assertFalse(isIPAddress("0.0.0.256"))
  67. self.assertFalse(isIPAddress("256.256.256.256"))
  68. def test_unicodeAndBytes(self):
  69. """
  70. L{isIPAddress} evaluates ASCII-encoded bytes as well as text.
  71. """
  72. self.assertFalse(isIPAddress(b"256.0.0.0"))
  73. self.assertFalse(isIPAddress("256.0.0.0"))
  74. self.assertTrue(isIPAddress(b"252.253.254.255"))
  75. self.assertTrue(isIPAddress("252.253.254.255"))
  76. def test_nonIPAddressFamily(self):
  77. """
  78. All address families other than C{AF_INET} and C{AF_INET6} result in a
  79. L{ValueError} being raised.
  80. """
  81. self.assertRaises(ValueError, isIPAddress, b"anything", AF_IPX)
  82. def test_nonASCII(self):
  83. """
  84. All IP addresses must be encodable as ASCII; non-ASCII should result in
  85. a L{False} result.
  86. """
  87. self.assertFalse(isIPAddress(b"\xff.notascii"))
  88. self.assertFalse(isIPAddress("\u4321.notascii"))