1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Tests for L{twisted.internet.abstract}, a collection of APIs for implementing
9 from twisted.trial.unittest import TestCase
11 from twisted.internet.abstract import isIPv6Address
13 class IPv6AddressTests(TestCase):
15 Tests for L{isIPv6Address}, a function for determining if a particular
16 string is an IPv6 address literal.
20 The empty string is not an IPv6 address literal.
22 self.assertFalse(isIPv6Address(""))
27 A single C{":"} is not an IPv6 address literal.
29 self.assertFalse(isIPv6Address(":"))
32 def test_loopback(self):
34 C{"::1"} is the IPv6 loopback address literal.
36 self.assertTrue(isIPv6Address("::1"))
39 def test_scopeID(self):
41 An otherwise valid IPv6 address literal may also include a C{"%"}
42 followed by an arbitrary scope identifier.
44 self.assertTrue(isIPv6Address("fe80::1%eth0"))
45 self.assertTrue(isIPv6Address("fe80::2%1"))
46 self.assertTrue(isIPv6Address("fe80::3%en2"))
49 def test_invalidWithScopeID(self):
51 An otherwise invalid IPv6 address literal is still invalid with a
52 trailing scope identifier.
54 self.assertFalse(isIPv6Address("%eth0"))
55 self.assertFalse(isIPv6Address(":%eth0"))
56 self.assertFalse(isIPv6Address("hello%eth0"))