buge avatar buge committed 7464d17

Added init and license.

Comments (0)

Files changed (4)

+Copyright (c) 2011, Philipp Bunge
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+  * The names of the contributors may be used to endorse or promote
+    products derived from this software without specific prior written
+    permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
+

addrinfo/__init__.py

+# -*- coding: ascii -*-
+"""
+    addrinfo
+    ~~~~~~~~
+
+    TODO add documentation
+
+    :copyright: Copyright (c) 2011, Philipp Bunge.
+    :license: BSD, ses LICENSE for details
+"""
+
+

tests/addresses_testcase.py

+#!/usr/bin/env python
+
+# Copyright (C) 2011  Philipp Bunge
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import unittest
+
+from addrinfo.addresses import *
+from addrinfo.addresses import _AddressFormatter
+
+
+class TestAddress(Address):
+    """Short address for Address unit tests."""
+
+    BIT_SIZE = 16
+
+    def __str__(self):
+        # FIXME implement correctly
+        return _AddressFormatter(
+            address_size = TestAddress.BIT_SIZE,
+            group_size = 8,
+            group_format = "%02X",
+            separator = '-'
+        ).format(self)
+
+    def __eq__(self, other):
+        if not isinstance(other, TestAddress):
+            return False
+        return self.get_address() == other.get_address()
+
+    def __hash__(self):
+        return hash(self.get_address())
+
+
+class AddressTestCase(unittest.TestCase):
+
+#   def test__value_of__mac_hypens(self):
+#       expected = EUI48Address(1250999896491)
+#       actual = Address.value_of("01-23-45-67-89-ab")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__mac_colons(self):
+#       expected = EUI48Address(1250999896491)
+#       actual = Address.value_of("01:23:45:67:89:ab")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_dot_decimal(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("192.0.2.235")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_dot_hexadecimal(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("0xC0.0x00.0x02.0xEB")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_dot_octal(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("0300.0000.0002.0353")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_dot_mixed(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("192.0x00.0002.235")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_hexadecimal(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("0xC00002EB")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_decimal(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("3221226219")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv4_octal(self):
+#       expected = IPv4Address(3221226219)
+#       actual = Address.value_of("030000001353")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv6_full(self):
+#       expected = IPv6Address(42540766452641154071740215577757643572L)
+#       actual = Address.value_of("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv6_no_leading_zeros(self):
+#       expected = IPv6Address(42540766452641154071740215577757643572L)
+#       actual = Address.value_of("2001:db8:85a3:0:0:8a2e:370:7334")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv6_grouped(self):
+#       expected = IPv6Address(42540766452641154071740215577757643572L)
+#       actual = Address.value_of("2001:db8:85a3::8a2e:370:7334")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv6_loopback(self):
+#       expected = IPv6Address(1)
+#       actual = Address.value_of("::1")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv6_unspecified(self):
+#       expected = IPv6Address(0)
+#       actual = Address.value_of("::")
+#       self.assertEqual(expected, actual)
+
+#   def test__value_of__ipv6_dotted_quad(self):
+#       expected = IPv6Address(3221226112)
+#       actual = Address.value_of("::ffff:192.0.2.128")
+#       self.assertEqual(expected, actual)
+
+    def test__repr(self):
+        self.assertEquals("TestAddress(42)", repr(TestAddress(42)))
+
+    def test__lshift_1(self):
+        expected = TestAddress(0x1ffe)
+        actual = TestAddress(0x0fff) << 1
+        self.assertEquals(expected, actual)
+
+    def test__lshift_3(self):
+        expected = TestAddress(0x7ff8)
+        actual = TestAddress(0x0fff) << 3
+        self.assertEquals(expected, actual)
+
+    def test__lshift_overflow(self):
+        expected = TestAddress(0xffe0)
+        actual = TestAddress(0x0fff) << 5
+        self.assertEquals(expected, actual)
+
+    def test__rshift_1(self):
+        expected = TestAddress(0x7ff8)
+        actual = TestAddress(0xfff0) >> 1
+        self.assertEquals(expected, actual)
+
+    def test__rshift_3(self):
+        expected = TestAddress(0x1ffe)
+        actual = TestAddress(0xfff0) >> 3
+        self.assertEquals(expected, actual)
+
+    def test__rshift_underflow(self):
+        expected = TestAddress(0x07ff)
+        actual = TestAddress(0xfff0) >> 5
+        self.assertEquals(expected, actual)
+
+    def test__and__numeric(self):
+        expected = TestAddress(0x0204)
+        actual = TestAddress(0x1234) & 0xabcd
+        self.assertEquals(expected, actual)
+
+    def test__and__address(self):
+        expected = TestAddress(0x0204)
+        actual = TestAddress(0x1234) & TestAddress(0xabcd)
+        self.assertEquals(expected, actual)
+
+    def test__or__numeric(self):
+        expected = TestAddress(0xbbfd)
+        actual = TestAddress(0x1234) | 0xabcd
+        self.assertEquals(expected, actual)
+
+    def test__or__address(self):
+        expected = TestAddress(0xbbfd)
+        actual = TestAddress(0x1234) | TestAddress(0xabcd)
+        self.assertEquals(expected, actual)
+
+    def test__xor__numeric(self):
+        expected = TestAddress(0xb9f9)
+        actual = TestAddress(0x1234) ^ 0xabcd
+        self.assertEquals(expected, actual)
+
+    def test__xor__address(self):
+        expected = TestAddress(0xb9f9)
+        actual = TestAddress(0x1234) ^ TestAddress(0xabcd)
+        self.assertEquals(expected, actual)
+
+    def test__rand(self):
+        expected = 0x0204
+        actual = 0xabcd & TestAddress(0x1234)
+        self.assertEquals(expected, actual)
+
+    def test__ror(self):
+        expected = 0xbbfd
+        actual = 0xabcd | TestAddress(0x1234)
+        self.assertEquals(expected, actual)
+
+    def test__rxor(self):
+        expected = 0xb9f9
+        actual = 0xabcd ^ TestAddress(0x1234)
+        self.assertEquals(expected, actual)
+
+    def test__invert(self):
+        expected = TestAddress(0xedcb)
+        actual = ~TestAddress(0x1234)
+        self.assertEquals(expected, actual)
+
+    def test__complex(self):
+        expected = complex(0x0123, 0)
+        actual = complex(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+    def test__int(self):
+        expected = 0x0123
+        actual = int(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+    def test__long(self):
+        expected = 0x0123L
+        actual = long(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+    def test__long(self):
+        expected = 0x0123L
+        actual = long(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+    def test__oct(self):
+        expected = "0443"
+        actual = oct(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+    def test__hex(self):
+        expected = "0x123"
+        actual = hex(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+    def test__bin(self):
+        expected = "0b100100011"
+        actual = bin(TestAddress(0x0123))
+        self.assertEquals(expected, actual)
+
+
+class EUI48AddressTestCase(unittest.TestCase):
+
+    def test__bit_size(self):
+        self.assertEquals(48, EUI48Address.BIT_SIZE)
+
+    def test__init__address(self):
+        address = EUI48Address(42)
+        self.assertEquals(42, address.get_address())
+
+    def test__init__address_min(self):
+        address = EUI48Address(0)
+        self.assertEquals(0, address.get_address())
+
+    def test__init__address_max(self):
+        address = EUI48Address(2 ** 48 - 1)
+        self.assertEquals(2 ** 48 - 1, address.get_address())
+
+    def test__init__address_under_min(self):
+        try:
+            EUI48Address(-1)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**48-1", str(e))
+
+    def test__init__address_over_max(self):
+        try:
+            EUI48Address(2**48)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**48-1", str(e))
+
+    def test__as_eui48(self):
+        expected = EUI48Address(1250999896491)
+        actual = expected.as_eui48()
+        self.assertEquals(expected, actual)
+
+    def test__as_eui64(self):
+        # 01-23-45-67-89-AB -> 01-23-45-[FF-FE]-67-89-AB
+        # Same as eui64_from_eui48()
+        expected = EUI64Address(81986184009976235)
+        actual = EUI48Address(1250999896491).as_eui64()
+        self.assertEquals(expected, actual)
+
+    def test__as_eui64_from_eui48(self):
+        # 01-23-45-67-89-AB -> 01-23-45-[FF-FE]-67-89-AB
+        expected = EUI64Address(81986184009976235)
+        actual = EUI48Address(1250999896491).as_eui64_from_eui48()
+        self.assertEquals(expected, actual)
+
+    def test__as_eui64_from_mac48(self):
+        # 01-23-45-67-89-AB -> 01-23-45-[FF-FF]-67-89-AB
+        expected = EUI64Address(81986184026753451)
+        actual = EUI48Address(1250999896491).as_eui64_from_mac48()
+        self.assertEquals(expected, actual)
+
+    def test__str__address(self):
+        expected = "01-23-45-67-89-AB"
+        actual = str(EUI48Address(1250999896491))
+        self.assertEquals(expected, actual)
+
+    def test__str__address_min(self):
+        expected = "00-00-00-00-00-00"
+        actual = str(EUI48Address(0))
+        self.assertEquals(expected, actual)
+
+    def test__str__address_max(self):
+        expected = "FF-FF-FF-FF-FF-FF"
+        actual = str(EUI48Address(2 ** 48 - 1))
+        self.assertEquals(expected, actual)
+
+
+class EUI64AddressTestCase(unittest.TestCase):
+
+    def test__bit_size(self):
+        self.assertEquals(64, EUI64Address.BIT_SIZE)
+
+    def test__init__address(self):
+        address = EUI64Address(42)
+        self.assertEquals(42, address.get_address())
+
+    def test__init__address_min(self):
+        address = EUI64Address(0)
+        self.assertEquals(0, address.get_address())
+
+    def test__init__address_max(self):
+        address = EUI64Address(2 ** 64 - 1)
+        self.assertEquals(2 ** 64 - 1, address.get_address())
+
+    def test__init__address_under_min(self):
+        try:
+            EUI64Address(-1)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**64-1", str(e))
+
+    def test__init__address_over_max(self):
+        try:
+            EUI64Address(2**64)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**64-1", str(e))
+
+    def test__as_eui48__from_eui48_encapsulated(self):
+        # 01-23-45-[FF-FE]-67-89-AB -> 01-23-45-67-89-AB
+        expected = EUI48Address(1250999896491)
+        actual = EUI64Address(81986184009976235).as_eui48()
+        self.assertEquals(expected, actual)
+
+    def test__as_eui48__from_mac48_encapsulated(self):
+        # 01-23-45-[FF-FF]-67-89-AB -> 01-23-45-67-89-AB
+        expected = EUI48Address(1250999896491)
+        actual = EUI64Address(81986184026753451).as_eui48()
+        self.assertEquals(expected, actual)
+
+    def test__as_eui48__from_incompatible(self):
+        try:
+            EUI64Address(81985529216486895).as_eui48()
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals(
+                "01-23-45-67-89-AB-CD-EF is not an EUI-48 encapsulated " +
+                "EUI-64 value", str(e))
+
+    def test__as_eui64(self):
+        expected = EUI64Address(81986184009976235)
+        actual = expected.as_eui64()
+        self.assertEquals(expected, actual)
+
+    def test__str__address(self):
+        expected = "01-23-45-67-89-AB-CD-EF"
+        actual = str(EUI64Address(81985529216486895))
+        self.assertEquals(expected, actual)
+
+    def test__str__address_min(self):
+        expected = "00-00-00-00-00-00-00-00"
+        actual = str(EUI64Address(0))
+        self.assertEquals(expected, actual)
+
+    def test__str__address_max(self):
+        expected = "FF-FF-FF-FF-FF-FF-FF-FF"
+        actual = str(EUI64Address(2 ** 64 - 1))
+        self.assertEquals(expected, actual)
+
+
+class IPv4AddressTestCase(unittest.TestCase):
+
+    def test__init__address(self):
+        address = IPv4Address(42)
+        self.assertEquals(42, address.get_address())
+
+    def test__init__address_min(self):
+        address = IPv4Address(0)
+        self.assertEquals(0, address.get_address())
+
+    def test__init__address_max(self):
+        address = IPv4Address(2 ** 32 - 1)
+        self.assertEquals(2 ** 32 - 1, address.get_address())
+
+    def test__init__address_under_min(self):
+        try:
+            IPv4Address(-1)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**32-1", str(e))
+
+    def test__init__address_over_max(self):
+        try:
+            IPv4Address(2**32)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**32-1", str(e))
+
+    def test__str__address(self):
+        expected = "192.0.2.235"
+        actual = str(IPv4Address(3221226219))
+        self.assertEquals(expected, actual)
+
+    def test__str__address_min(self):
+        expected = "0.0.0.0"
+        actual = str(IPv4Address(0))
+        self.assertEquals(expected, actual)
+
+    def test__str__address_max(self):
+        expected = "255.255.255.255"
+        actual = str(IPv4Address(2 ** 32 - 1))
+        self.assertEquals(expected, actual)
+
+
+class IPv6AddressTestCase(unittest.TestCase):
+
+    def test__get_link_local_address(self):
+        eui = EUI64Address(0x0123456789abcdef)
+        expected = IPv6Address(0xfe800000000000000323456789abcdef)
+        actual = IPv6Address.get_link_local_address(eui)
+        self.assertEquals(expected, actual)
+
+    def test__get_link_local_address__inverts_u_bit(self):
+        """Tests that the EUI-64 u-bit is inverted rather than set to 1."""
+        eui = EUI64Address(0xffffffffffffffff)
+        expected = IPv6Address(0xfe80000000000000fdffffffffffffff)
+        actual = IPv6Address.get_link_local_address(eui)
+        self.assertEquals(expected, actual)
+
+    def test__get_link_local_address__from_number(self):
+        expected = IPv6Address(0xfe800000000000000323456789abcdef)
+        actual = IPv6Address.get_link_local_address(0x0123456789abcdef)
+        self.assertEquals(expected, actual)
+
+    def test__get_link_local_address__from_None(self):
+        # Mock the get_hardware_address method
+        org_f = EUIAddress.get_hardware_address
+        eui = EUI48Address(0x00236c802131)
+        EUIAddress.get_hardware_address = classmethod(lambda x: eui)
+        try:
+            expected = IPv6Address(0xfe8000000000000002236cfffe802131)
+            actual = IPv6Address.get_link_local_address()
+            self.assertEquals(expected, actual)
+        finally:
+            EUIAddress.get_hardware_address = org_f
+
+    def test__init__address(self):
+        address = IPv6Address(42)
+        self.assertEquals(42, address.get_address())
+
+    def test__init__address_min(self):
+        address = IPv6Address(0)
+        self.assertEquals(0, address.get_address())
+
+    def test__init__address_max(self):
+        address = IPv6Address(2 ** 128 - 1)
+        self.assertEquals(2 ** 128 - 1, address.get_address())
+
+    def test__init__address_under_min(self):
+        try:
+            IPv6Address(-1)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**128-1", str(e))
+
+    def test__init__address_over_max(self):
+        try:
+            IPv6Address(2**128)
+            self.fail("failed to raise ValueError")
+        except ValueError, e:
+            self.assertEquals("address must be between 0 and 2**128-1", str(e))
+
+
+if __name__ == '__main__':
+    unittest.main()
+

tests/addrinfo_testcase.py

-#!/usr/bin/env python
-
-# Copyright (C) 2011  Philipp Bunge
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-import unittest
-
-from addrinfo import *
-from addrinfo import _AddressFormatter
-
-
-class TestAddress(Address):
-    """Short address for Address unit tests."""
-
-    BIT_SIZE = 16
-
-    def __str__(self):
-        # FIXME implement correctly
-        return _AddressFormatter(
-            address_size = TestAddress.BIT_SIZE,
-            group_size = 8,
-            group_format = "%02X",
-            separator = '-'
-        ).format(self)
-
-    def __eq__(self, other):
-        if not isinstance(other, TestAddress):
-            return False
-        return self.get_address() == other.get_address()
-
-    def __hash__(self):
-        return hash(self.get_address())
-
-
-class AddressTestCase(unittest.TestCase):
-
-#   def test__value_of__mac_hypens(self):
-#       expected = EUI48Address(1250999896491)
-#       actual = Address.value_of("01-23-45-67-89-ab")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__mac_colons(self):
-#       expected = EUI48Address(1250999896491)
-#       actual = Address.value_of("01:23:45:67:89:ab")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_dot_decimal(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("192.0.2.235")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_dot_hexadecimal(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("0xC0.0x00.0x02.0xEB")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_dot_octal(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("0300.0000.0002.0353")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_dot_mixed(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("192.0x00.0002.235")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_hexadecimal(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("0xC00002EB")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_decimal(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("3221226219")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv4_octal(self):
-#       expected = IPv4Address(3221226219)
-#       actual = Address.value_of("030000001353")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv6_full(self):
-#       expected = IPv6Address(42540766452641154071740215577757643572L)
-#       actual = Address.value_of("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv6_no_leading_zeros(self):
-#       expected = IPv6Address(42540766452641154071740215577757643572L)
-#       actual = Address.value_of("2001:db8:85a3:0:0:8a2e:370:7334")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv6_grouped(self):
-#       expected = IPv6Address(42540766452641154071740215577757643572L)
-#       actual = Address.value_of("2001:db8:85a3::8a2e:370:7334")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv6_loopback(self):
-#       expected = IPv6Address(1)
-#       actual = Address.value_of("::1")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv6_unspecified(self):
-#       expected = IPv6Address(0)
-#       actual = Address.value_of("::")
-#       self.assertEqual(expected, actual)
-
-#   def test__value_of__ipv6_dotted_quad(self):
-#       expected = IPv6Address(3221226112)
-#       actual = Address.value_of("::ffff:192.0.2.128")
-#       self.assertEqual(expected, actual)
-
-    def test__repr(self):
-        self.assertEquals("TestAddress(42)", repr(TestAddress(42)))
-
-    def test__lshift_1(self):
-        expected = TestAddress(0x1ffe)
-        actual = TestAddress(0x0fff) << 1
-        self.assertEquals(expected, actual)
-
-    def test__lshift_3(self):
-        expected = TestAddress(0x7ff8)
-        actual = TestAddress(0x0fff) << 3
-        self.assertEquals(expected, actual)
-
-    def test__lshift_overflow(self):
-        expected = TestAddress(0xffe0)
-        actual = TestAddress(0x0fff) << 5
-        self.assertEquals(expected, actual)
-
-    def test__rshift_1(self):
-        expected = TestAddress(0x7ff8)
-        actual = TestAddress(0xfff0) >> 1
-        self.assertEquals(expected, actual)
-
-    def test__rshift_3(self):
-        expected = TestAddress(0x1ffe)
-        actual = TestAddress(0xfff0) >> 3
-        self.assertEquals(expected, actual)
-
-    def test__rshift_underflow(self):
-        expected = TestAddress(0x07ff)
-        actual = TestAddress(0xfff0) >> 5
-        self.assertEquals(expected, actual)
-
-    def test__and__numeric(self):
-        expected = TestAddress(0x0204)
-        actual = TestAddress(0x1234) & 0xabcd
-        self.assertEquals(expected, actual)
-
-    def test__and__address(self):
-        expected = TestAddress(0x0204)
-        actual = TestAddress(0x1234) & TestAddress(0xabcd)
-        self.assertEquals(expected, actual)
-
-    def test__or__numeric(self):
-        expected = TestAddress(0xbbfd)
-        actual = TestAddress(0x1234) | 0xabcd
-        self.assertEquals(expected, actual)
-
-    def test__or__address(self):
-        expected = TestAddress(0xbbfd)
-        actual = TestAddress(0x1234) | TestAddress(0xabcd)
-        self.assertEquals(expected, actual)
-
-    def test__xor__numeric(self):
-        expected = TestAddress(0xb9f9)
-        actual = TestAddress(0x1234) ^ 0xabcd
-        self.assertEquals(expected, actual)
-
-    def test__xor__address(self):
-        expected = TestAddress(0xb9f9)
-        actual = TestAddress(0x1234) ^ TestAddress(0xabcd)
-        self.assertEquals(expected, actual)
-
-    def test__rand(self):
-        expected = 0x0204
-        actual = 0xabcd & TestAddress(0x1234)
-        self.assertEquals(expected, actual)
-
-    def test__ror(self):
-        expected = 0xbbfd
-        actual = 0xabcd | TestAddress(0x1234)
-        self.assertEquals(expected, actual)
-
-    def test__rxor(self):
-        expected = 0xb9f9
-        actual = 0xabcd ^ TestAddress(0x1234)
-        self.assertEquals(expected, actual)
-
-    def test__invert(self):
-        expected = TestAddress(0xedcb)
-        actual = ~TestAddress(0x1234)
-        self.assertEquals(expected, actual)
-
-    def test__complex(self):
-        expected = complex(0x0123, 0)
-        actual = complex(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-    def test__int(self):
-        expected = 0x0123
-        actual = int(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-    def test__long(self):
-        expected = 0x0123L
-        actual = long(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-    def test__long(self):
-        expected = 0x0123L
-        actual = long(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-    def test__oct(self):
-        expected = "0443"
-        actual = oct(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-    def test__hex(self):
-        expected = "0x123"
-        actual = hex(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-    def test__bin(self):
-        expected = "0b100100011"
-        actual = bin(TestAddress(0x0123))
-        self.assertEquals(expected, actual)
-
-
-class EUI48AddressTestCase(unittest.TestCase):
-
-    def test__bit_size(self):
-        self.assertEquals(48, EUI48Address.BIT_SIZE)
-
-    def test__init__address(self):
-        address = EUI48Address(42)
-        self.assertEquals(42, address.get_address())
-
-    def test__init__address_min(self):
-        address = EUI48Address(0)
-        self.assertEquals(0, address.get_address())
-
-    def test__init__address_max(self):
-        address = EUI48Address(2 ** 48 - 1)
-        self.assertEquals(2 ** 48 - 1, address.get_address())
-
-    def test__init__address_under_min(self):
-        try:
-            EUI48Address(-1)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**48-1", str(e))
-
-    def test__init__address_over_max(self):
-        try:
-            EUI48Address(2**48)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**48-1", str(e))
-
-    def test__as_eui48(self):
-        expected = EUI48Address(1250999896491)
-        actual = expected.as_eui48()
-        self.assertEquals(expected, actual)
-
-    def test__as_eui64(self):
-        # 01-23-45-67-89-AB -> 01-23-45-[FF-FE]-67-89-AB
-        # Same as eui64_from_eui48()
-        expected = EUI64Address(81986184009976235)
-        actual = EUI48Address(1250999896491).as_eui64()
-        self.assertEquals(expected, actual)
-
-    def test__as_eui64_from_eui48(self):
-        # 01-23-45-67-89-AB -> 01-23-45-[FF-FE]-67-89-AB
-        expected = EUI64Address(81986184009976235)
-        actual = EUI48Address(1250999896491).as_eui64_from_eui48()
-        self.assertEquals(expected, actual)
-
-    def test__as_eui64_from_mac48(self):
-        # 01-23-45-67-89-AB -> 01-23-45-[FF-FF]-67-89-AB
-        expected = EUI64Address(81986184026753451)
-        actual = EUI48Address(1250999896491).as_eui64_from_mac48()
-        self.assertEquals(expected, actual)
-
-    def test__str__address(self):
-        expected = "01-23-45-67-89-AB"
-        actual = str(EUI48Address(1250999896491))
-        self.assertEquals(expected, actual)
-
-    def test__str__address_min(self):
-        expected = "00-00-00-00-00-00"
-        actual = str(EUI48Address(0))
-        self.assertEquals(expected, actual)
-
-    def test__str__address_max(self):
-        expected = "FF-FF-FF-FF-FF-FF"
-        actual = str(EUI48Address(2 ** 48 - 1))
-        self.assertEquals(expected, actual)
-
-
-class EUI64AddressTestCase(unittest.TestCase):
-
-    def test__bit_size(self):
-        self.assertEquals(64, EUI64Address.BIT_SIZE)
-
-    def test__init__address(self):
-        address = EUI64Address(42)
-        self.assertEquals(42, address.get_address())
-
-    def test__init__address_min(self):
-        address = EUI64Address(0)
-        self.assertEquals(0, address.get_address())
-
-    def test__init__address_max(self):
-        address = EUI64Address(2 ** 64 - 1)
-        self.assertEquals(2 ** 64 - 1, address.get_address())
-
-    def test__init__address_under_min(self):
-        try:
-            EUI64Address(-1)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**64-1", str(e))
-
-    def test__init__address_over_max(self):
-        try:
-            EUI64Address(2**64)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**64-1", str(e))
-
-    def test__as_eui48__from_eui48_encapsulated(self):
-        # 01-23-45-[FF-FE]-67-89-AB -> 01-23-45-67-89-AB
-        expected = EUI48Address(1250999896491)
-        actual = EUI64Address(81986184009976235).as_eui48()
-        self.assertEquals(expected, actual)
-
-    def test__as_eui48__from_mac48_encapsulated(self):
-        # 01-23-45-[FF-FF]-67-89-AB -> 01-23-45-67-89-AB
-        expected = EUI48Address(1250999896491)
-        actual = EUI64Address(81986184026753451).as_eui48()
-        self.assertEquals(expected, actual)
-
-    def test__as_eui48__from_incompatible(self):
-        try:
-            EUI64Address(81985529216486895).as_eui48()
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals(
-                "01-23-45-67-89-AB-CD-EF is not an EUI-48 encapsulated " +
-                "EUI-64 value", str(e))
-
-    def test__as_eui64(self):
-        expected = EUI64Address(81986184009976235)
-        actual = expected.as_eui64()
-        self.assertEquals(expected, actual)
-
-    def test__str__address(self):
-        expected = "01-23-45-67-89-AB-CD-EF"
-        actual = str(EUI64Address(81985529216486895))
-        self.assertEquals(expected, actual)
-
-    def test__str__address_min(self):
-        expected = "00-00-00-00-00-00-00-00"
-        actual = str(EUI64Address(0))
-        self.assertEquals(expected, actual)
-
-    def test__str__address_max(self):
-        expected = "FF-FF-FF-FF-FF-FF-FF-FF"
-        actual = str(EUI64Address(2 ** 64 - 1))
-        self.assertEquals(expected, actual)
-
-
-class IPv4AddressTestCase(unittest.TestCase):
-
-    def test__init__address(self):
-        address = IPv4Address(42)
-        self.assertEquals(42, address.get_address())
-
-    def test__init__address_min(self):
-        address = IPv4Address(0)
-        self.assertEquals(0, address.get_address())
-
-    def test__init__address_max(self):
-        address = IPv4Address(2 ** 32 - 1)
-        self.assertEquals(2 ** 32 - 1, address.get_address())
-
-    def test__init__address_under_min(self):
-        try:
-            IPv4Address(-1)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**32-1", str(e))
-
-    def test__init__address_over_max(self):
-        try:
-            IPv4Address(2**32)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**32-1", str(e))
-
-    def test__str__address(self):
-        expected = "192.0.2.235"
-        actual = str(IPv4Address(3221226219))
-        self.assertEquals(expected, actual)
-
-    def test__str__address_min(self):
-        expected = "0.0.0.0"
-        actual = str(IPv4Address(0))
-        self.assertEquals(expected, actual)
-
-    def test__str__address_max(self):
-        expected = "255.255.255.255"
-        actual = str(IPv4Address(2 ** 32 - 1))
-        self.assertEquals(expected, actual)
-
-
-class IPv6AddressTestCase(unittest.TestCase):
-
-    def test__get_link_local_address(self):
-        eui = EUI64Address(0x0123456789abcdef)
-        expected = IPv6Address(0xfe800000000000000323456789abcdef)
-        actual = IPv6Address.get_link_local_address(eui)
-        self.assertEquals(expected, actual)
-
-    def test__get_link_local_address__inverts_u_bit(self):
-        """Tests that the EUI-64 u-bit is inverted rather than set to 1."""
-        eui = EUI64Address(0xffffffffffffffff)
-        expected = IPv6Address(0xfe80000000000000fdffffffffffffff)
-        actual = IPv6Address.get_link_local_address(eui)
-        self.assertEquals(expected, actual)
-
-    def test__get_link_local_address__from_number(self):
-        expected = IPv6Address(0xfe800000000000000323456789abcdef)
-        actual = IPv6Address.get_link_local_address(0x0123456789abcdef)
-        self.assertEquals(expected, actual)
-
-    def test__get_link_local_address__from_None(self):
-        # Mock the get_hardware_address method
-        org_f = EUIAddress.get_hardware_address
-        eui = EUI48Address(0x00236c802131)
-        EUIAddress.get_hardware_address = classmethod(lambda x: eui)
-        try:
-            expected = IPv6Address(0xfe8000000000000002236cfffe802131)
-            actual = IPv6Address.get_link_local_address()
-            self.assertEquals(expected, actual)
-        finally:
-            EUIAddress.get_hardware_address = org_f
-
-    def test__init__address(self):
-        address = IPv6Address(42)
-        self.assertEquals(42, address.get_address())
-
-    def test__init__address_min(self):
-        address = IPv6Address(0)
-        self.assertEquals(0, address.get_address())
-
-    def test__init__address_max(self):
-        address = IPv6Address(2 ** 128 - 1)
-        self.assertEquals(2 ** 128 - 1, address.get_address())
-
-    def test__init__address_under_min(self):
-        try:
-            IPv6Address(-1)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**128-1", str(e))
-
-    def test__init__address_over_max(self):
-        try:
-            IPv6Address(2**128)
-            self.fail("failed to raise ValueError")
-        except ValueError, e:
-            self.assertEquals("address must be between 0 and 2**128-1", str(e))
-
-
-if __name__ == '__main__':
-    unittest.main()
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.