示例#1
0
 def test_init_success(self):
     """Ensures __init__ accepts valid arguments."""
     host1 = HostEntity()
     host1.name = "host1"
     PeerTableEntry(dst=host1, latency=10, expire_time=300)
     PeerTableEntry(dst=host1, latency=0.1, expire_time=0.2)
     PeerTableEntry(dst=host1,
                    latency=10,
                    expire_time=PeerTableEntry.FOREVER)
示例#2
0
    def test_init_None(self):
        """Ensures __init__ doesn't accept None arguments."""
        host1 = HostEntity()
        host1.name = "host1"

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst=None, port=5, latency=10)

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst=host1, port=None, latency=10)

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst=host1, port=5, latency=None)
示例#3
0
    def test_init_types(self):
        """Ensures __init__ rejects incorrectly typed arguments."""
        host1 = HostEntity()
        host1.name = "host1"

        with self.assertRaises(ValueError):
            PeerTableEntry(dst="host1", latency=10, expire_time=300)

        with self.assertRaises(ValueError):
            PeerTableEntry(dst=host1, latency="hi", expire_time=300)

        with self.assertRaises(ValueError):
            PeerTableEntry(dst=host1, latency=10, expire_time="oops")
示例#4
0
    def test_init_None(self):
        """Ensures __init__ doesn't accept None arguments."""
        host1 = HostEntity()
        host1.name = "host1"

        with self.assertRaises(ValueError):
            PeerTableEntry(dst=None, latency=10, expire_time=300)

        with self.assertRaises(ValueError):
            PeerTableEntry(dst=host1, latency=None, expire_time=300)

        with self.assertRaises(ValueError):
            PeerTableEntry(dst=host1, latency=10, expire_time=None)
示例#5
0
    def test_equality_forever(self):
        """Makes sure expire_time=FOREVER doesn't mess with equality tests."""
        host1 = HostEntity()
        host1.name = "host1"

        rte1 = PeerTableEntry(dst=host1,
                              latency=10,
                              expire_time=PeerTableEntry.FOREVER)
        rte2 = PeerTableEntry(dst=host1,
                              latency=10,
                              expire_time=PeerTableEntry.FOREVER)
        self.assertEqual(rte1, rte2)
        self.assertTrue(rte1 == rte2)
        self.assertFalse(rte1 != rte2)
        self.assertEqual(hash(rte1), hash(rte2))
示例#6
0
    def test_init_types(self):
        """Ensures __init__ rejects incorrectly typed arguments."""
        host1 = HostEntity()
        host1.name = "host1"

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst="host1", port=5, latency=10)

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst=host1, port=0.1, latency=10)

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst=host1, port="hi", latency=10)

        with self.assertRaises(ValueError):
            ForwardingTableEntry(dst=host1, port=5, latency="hi")
示例#7
0
    def test_equality(self):
        """Tests __eq__, __ne__, and __hash__ implementations."""
        host1 = HostEntity()
        host1.name = "host1"
        host2 = HostEntity()
        host2.name = "host2"

        fte1 = ForwardingTableEntry(dst=host1, port=5, latency=10)
        fte2 = ForwardingTableEntry(dst=host1, port=5, latency=10)
        self.assertEqual(fte1, fte2)
        self.assertTrue(fte1 == fte2)
        self.assertFalse(fte1 != fte2)
        self.assertEqual(hash(fte1), hash(fte2))

        fte3 = ForwardingTableEntry(dst=host2, port=5, latency=10)
        self.assertNotEqual(fte1, fte3)
        self.assertFalse(fte1 == fte3)
        self.assertTrue(fte1 != fte3)

        fte4 = ForwardingTableEntry(dst=host1, port=1, latency=10)
        self.assertNotEqual(fte1, fte4)
        self.assertFalse(fte1 == fte4)
        self.assertTrue(fte1 != fte4)

        fte5 = ForwardingTableEntry(dst=host1, port=5, latency=100)
        self.assertNotEqual(fte1, fte5)
        self.assertFalse(fte1 == fte5)
        self.assertTrue(fte1 != fte5)
示例#8
0
    def test_equality(self):
        """Tests __eq__, __ne__, and __hash__ implementations."""
        host1 = HostEntity()
        host1.name = "host1"
        host2 = HostEntity()
        host2.name = "host2"

        rte1 = PeerTableEntry(dst=host1, latency=10, expire_time=300)
        rte2 = PeerTableEntry(dst=host1, latency=10, expire_time=300)
        self.assertEqual(rte1, rte2)
        self.assertTrue(rte1 == rte2)
        self.assertFalse(rte1 != rte2)
        self.assertEqual(hash(rte1), hash(rte2))

        rte3 = PeerTableEntry(dst=host2, latency=10, expire_time=300)
        self.assertNotEqual(rte1, rte3)
        self.assertFalse(rte1 == rte3)
        self.assertTrue(rte1 != rte3)

        rte4 = PeerTableEntry(dst=host1, latency=0, expire_time=300)
        self.assertNotEqual(rte1, rte4)
        self.assertFalse(rte1 == rte4)
        self.assertTrue(rte1 != rte4)

        rte5 = PeerTableEntry(dst=host1, latency=10, expire_time=500)
        self.assertNotEqual(rte1, rte5)
        self.assertFalse(rte1 == rte5)
        self.assertTrue(rte1 != rte5)
示例#9
0
 def test_init_success(self):
     """Ensures __init__ accepts valid arguments."""
     host1 = HostEntity()
     host1.name = "host1"
     ForwardingTableEntry(dst=host1, port=5, latency=10)
     ForwardingTableEntry(dst=host1, port=1, latency=0.8)