~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/test/test_abstract.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2007 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
"""
 
5
Tests for generic file descriptor based reactor support code.
 
6
"""
 
7
 
 
8
from twisted.trial.unittest import TestCase
 
9
 
 
10
from twisted.internet.abstract import isIPAddress
 
11
 
 
12
 
 
13
class AddressTests(TestCase):
 
14
    """
 
15
    Tests for address-related functionality.
 
16
    """
 
17
    def test_decimalDotted(self):
 
18
        """
 
19
        L{isIPAddress} should return C{True} for any decimal dotted
 
20
        representation of an IPv4 address.
 
21
        """
 
22
        self.assertTrue(isIPAddress('0.1.2.3'))
 
23
        self.assertTrue(isIPAddress('252.253.254.255'))
 
24
 
 
25
 
 
26
    def test_shortDecimalDotted(self):
 
27
        """
 
28
        L{isIPAddress} should return C{False} for a dotted decimal
 
29
        representation with fewer or more than four octets.
 
30
        """
 
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'))
 
35
 
 
36
 
 
37
    def test_invalidLetters(self):
 
38
        """
 
39
        L{isIPAddress} should return C{False} for any non-decimal dotted
 
40
        representation including letters.
 
41
        """
 
42
        self.assertFalse(isIPAddress('a.2.3.4'))
 
43
        self.assertFalse(isIPAddress('1.b.3.4'))
 
44
 
 
45
 
 
46
    def test_invalidPunctuation(self):
 
47
        """
 
48
        L{isIPAddress} should return C{False} for a string containing
 
49
        strange punctuation.
 
50
        """
 
51
        self.assertFalse(isIPAddress(','))
 
52
        self.assertFalse(isIPAddress('1,2'))
 
53
        self.assertFalse(isIPAddress('1,2,3'))
 
54
        self.assertFalse(isIPAddress('1.,.3,4'))
 
55
 
 
56
 
 
57
    def test_emptyString(self):
 
58
        """
 
59
        L{isIPAddress} should return C{False} for the empty string.
 
60
        """
 
61
        self.assertFalse(isIPAddress(''))
 
62
 
 
63
 
 
64
    def test_invalidNegative(self):
 
65
        """
 
66
        L{isIPAddress} should return C{False} for negative decimal values.
 
67
        """
 
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'))
 
72
 
 
73
 
 
74
    def test_invalidPositive(self):
 
75
        """
 
76
        L{isIPAddress} should return C{False} for a string containing
 
77
        positive decimal values greater than 255.
 
78
        """
 
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'))