def test_set_loop_iter_from(self): set = IPSet() iter = set.loop_iter_from('10.8.2.5') self.assertRaises(StopIteration, iter.next) set.add(['10.8.1.5', '10.8.1.7']) set.add(['10.9.2.2', '10.9.2.4']) set.add(['10.9.2.3', '10.9.2.5']) iter = set.loop_iter_from('9.8.7.6') exp = [i for i in itertools.chain(set, set)] self.comp_iters(iter, exp) iter = set.loop_iter_from('10.8.1.6') self.comp_iters(iter, exp, 1) iter = set.loop_iter_from('10.8.1.9') self.comp_iters(iter, exp, 3) iter = set.loop_iter_from('10.9.9.9') self.comp_iters(iter, exp)
def test_set_basic(self): set = IPSet() set.add(['160.228.152.1', '160.228.154.4']) self.assertEqual(len(set.ranges), 1) self.assertTrue(set.contains('160.228.153.252')) self.assertFalse(set.contains('1.2.3.4')) self.assertFalse(set.contains('160.228.152.0')) self.assertFalse(set.contains('160.228.154.5')) self.assertFalse(set.contains('192.168.1.24')) set.add(['192.168.0.2', '192.168.2.200']) self.assertTrue(set.contains('192.168.1.24'))
def test_set_compact(self): set = IPSet() set.add(['160.228.152.1', '160.228.154.4']) self.assertEqual(set.ranges, [ IPRange('160.228.152.1', '160.228.154.4'), ]) set.add(['192.168.0.2', '192.168.2.200']) self.assertEqual(set.ranges, [ IPRange('160.228.152.1', '160.228.154.4'), IPRange('192.168.0.2', '192.168.2.200'), ]) set.add(['160.228.153.255', '170.2.3.4']) self.assertEqual(set.ranges, [ IPRange('160.228.152.1', '170.2.3.4'), IPRange('192.168.0.2', '192.168.2.200'), ]) set.add(['170.2.3.5', '193.2.3.4']) self.assertEqual(set.ranges, [ IPRange('160.228.152.1', '193.2.3.4'), ])
def test_set_iter(self): set = IPSet() iter = set.__iter__() self.assertRaises(StopIteration, iter.next) set.add(['10.8.1.5', '10.8.1.7']) set.add(['10.9.2.2', '10.9.2.4']) set.add(['10.9.2.3', '10.9.2.5']) iter = set.__iter__() self.assertEqual(iter.next(), IP('10.8.1.5')) self.assertEqual(iter.next(), IP('10.8.1.6')) self.assertEqual(iter.next(), IP('10.8.1.7')) self.assertEqual(iter.next(), IP('10.9.2.2')) self.assertEqual(iter.next(), IP('10.9.2.3')) self.assertEqual(iter.next(), IP('10.9.2.4')) self.assertEqual(iter.next(), IP('10.9.2.5')) self.assertRaises(StopIteration, iter.next)
def test_simpleset(self): set = IPSet() self.assertEqual(len(set.ranges), 0) self.assertFalse(set.contains('192.168.0.3')) self.assertEqual(len(set), 0)
def test_ipset(self): set = IPSet() self.assertRaises(InvalidAddress, lambda: set.contains('160.228.153.256'))