1
# Copyright (c) 2007 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Tests for generic file descriptor based reactor support code.
8
from twisted.trial.unittest import TestCase
10
from twisted.internet.abstract import isIPAddress
13
class AddressTests(TestCase):
15
Tests for address-related functionality.
17
def test_decimalDotted(self):
19
L{isIPAddress} should return C{True} for any decimal dotted
20
representation of an IPv4 address.
22
self.assertTrue(isIPAddress('0.1.2.3'))
23
self.assertTrue(isIPAddress('252.253.254.255'))
26
def test_shortDecimalDotted(self):
28
L{isIPAddress} should return C{False} for a dotted decimal
29
representation with fewer or more than four octets.
31
self.assertFalse(isIPAddress('0'))
32
self.assertFalse(isIPAddress('0.1'))
33
self.assertFalse(isIPAddress('0.1.2'))
34
self.assertFalse(isIPAddress('0.1.2.3.4'))
37
def test_invalidLetters(self):
39
L{isIPAddress} should return C{False} for any non-decimal dotted
40
representation including letters.
42
self.assertFalse(isIPAddress('a.2.3.4'))
43
self.assertFalse(isIPAddress('1.b.3.4'))
46
def test_invalidPunctuation(self):
48
L{isIPAddress} should return C{False} for a string containing
51
self.assertFalse(isIPAddress(','))
52
self.assertFalse(isIPAddress('1,2'))
53
self.assertFalse(isIPAddress('1,2,3'))
54
self.assertFalse(isIPAddress('1.,.3,4'))
57
def test_emptyString(self):
59
L{isIPAddress} should return C{False} for the empty string.
61
self.assertFalse(isIPAddress(''))
64
def test_invalidNegative(self):
66
L{isIPAddress} should return C{False} for negative decimal values.
68
self.assertFalse(isIPAddress('-1'))
69
self.assertFalse(isIPAddress('1.-2'))
70
self.assertFalse(isIPAddress('1.2.-3'))
71
self.assertFalse(isIPAddress('1.2.-3.4'))
74
def test_invalidPositive(self):
76
L{isIPAddress} should return C{False} for a string containing
77
positive decimal values greater than 255.
79
self.assertFalse(isIPAddress('256.0.0.0'))
80
self.assertFalse(isIPAddress('0.256.0.0'))
81
self.assertFalse(isIPAddress('0.0.256.0'))
82
self.assertFalse(isIPAddress('0.0.0.256'))
83
self.assertFalse(isIPAddress('256.256.256.256'))