Beispiel #1
0
 def test__too_many_open_files(self):
     q1 = PriorityQueue(self.qfactory)
     last = ''
     for i in xrange(0,200):
       last = str(i)
       q1.push(last, i)
     
     self.assertEqual(q1.pop(), str(0))
Beispiel #2
0
 def setUp(self):
     QueuelibTestCase.setUp(self)
     self.q = PriorityQueue(self.qfactory)
Beispiel #3
0
    class PQueueTestBase(QueuelibTestCase):

        def setUp(self):
            QueuelibTestCase.setUp(self)
            self.q = PriorityQueue(self.qfactory)

        def qfactory(self, prio):
            raise NotImplementedError

        def test_len_nonzero(self):
            assert not self.q
            self.assertEqual(len(self.q), 0)
            self.q.push(b'a', 3)
            assert self.q
            self.q.push(b'b', 1)
            self.q.push(b'c', 2)
            self.q.push(b'd', 1)
            self.assertEqual(len(self.q), 4)
            self.q.pop()
            self.q.pop()
            self.q.pop()
            self.q.pop()
            assert not self.q
            self.assertEqual(len(self.q), 0)

        def test_close(self):
            self.q.push(b'a', 3)
            self.q.push(b'b', 1)
            self.q.push(b'c', 2)
            self.q.push(b'd', 1)
            iqueues = self.q.queues.values()
            self.assertEqual(sorted(self.q.close()), [1, 2, 3])
            assert all(q.closed for q in iqueues)

        def test_close_return_active(self):
            self.q.push(b'b', 1)
            self.q.push(b'c', 2)
            self.q.push(b'a', 3)
            self.q.pop()
            self.assertEqual(sorted(self.q.close()), [2, 3])

        def test_popped_internal_queues_closed(self):
            self.q.push(b'a', 3)
            self.q.push(b'b', 1)
            self.q.push(b'c', 2)
            p1queue = self.q.queues[1]
            self.assertEqual(self.q.pop(), b'b')
            self.q.close()
            assert p1queue.closed
Beispiel #4
0
 def test_reopen_with_prio(self):
     q1 = PriorityQueue(self.qfactory)
     q1.push(b'a', 3)
     q1.push(b'b', 1)
     q1.push(b'c', 2)
     active = q1.close()
     q2 = PriorityQueue(self.qfactory, startprios=active)
     self.assertEqual(q2.pop(), b'b')
     self.assertEqual(q2.pop(), b'c')
     self.assertEqual(q2.pop(), b'a')
     self.assertEqual(q2.close(), [])
Beispiel #5
0
 def setUp(self):
     FifoMemoryPriorityQueueTest.setUp(self)
     self.q = PriorityQueue(self.qfactory)
Beispiel #6
0
class FifoMemoryPriorityQueueTest(QueuelibTestCase):

    def setUp(self):
        QueuelibTestCase.setUp(self)
        self.q = PriorityQueue(self.qfactory)

    def qfactory(self, prio):
        return track_closed(FifoMemoryQueue)()

    def test_push_pop_noprio(self):
        self.q.push('a')
        self.q.push('b')
        self.q.push('c')
        self.assertEqual(self.q.pop(), 'a')
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(self.q.pop(), 'c')
        self.assertEqual(self.q.pop(), None)

    def test_push_pop_prio(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('d', 1)
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(self.q.pop(), 'd')
        self.assertEqual(self.q.pop(), 'c')
        self.assertEqual(self.q.pop(), 'a')
        self.assertEqual(self.q.pop(), None)

    def test_len_nonzero(self):
        assert not self.q
        self.assertEqual(len(self.q), 0)
        self.q.push('a', 3)
        assert self.q
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('d', 1)
        self.assertEqual(len(self.q), 4)
        self.q.pop()
        self.q.pop()
        self.q.pop()
        self.q.pop()
        assert not self.q
        self.assertEqual(len(self.q), 0)

    def test_close(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('d', 1)
        iqueues = self.q.queues.values()
        self.assertEqual(sorted(self.q.close()), [1, 2, 3])
        assert all(q.closed for q in iqueues)

    def test_close_return_active(self):
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('a', 3)
        self.q.pop()
        self.assertEqual(sorted(self.q.close()), [2, 3])

    def test_popped_internal_queues_closed(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.q.push('c', 2)
        p1queue = self.q.queues[1]
        self.assertEqual(self.q.pop(), 'b')
        self.q.close()
        assert p1queue.closed
Beispiel #7
0
class FifoDiskPriorityQueueTest(FifoMemoryPriorityQueueTest):

    def setUp(self):
        FifoMemoryPriorityQueueTest.setUp(self)
        self.q = PriorityQueue(self.qfactory)

    def qfactory(self, prio):
        return track_closed(FifoDiskQueue)(self.mktemp())

    def test_nonserializable_object_one(self):
        self.assertRaises(TypeError, self.q.push, lambda x: x, 0)
        self.assertEqual(self.q.close(), [])

    def test_nonserializable_object_many_close(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.assertRaises(TypeError, self.q.push, lambda x: x, 0)
        self.q.push('c', 2)
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(sorted(self.q.close()), [2, 3])

    def test_nonserializable_object_many_pop(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.assertRaises(TypeError, self.q.push, lambda x: x, 0)
        self.q.push('c', 2)
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(self.q.pop(), 'c')
        self.assertEqual(self.q.pop(), 'a')
        self.assertEqual(self.q.pop(), None)
        self.assertEqual(self.q.close(), [])
Beispiel #8
0
 def test_reopen_with_prio(self):
     q1 = PriorityQueue(self.qfactory)
     q1.push(b"a", 3)
     q1.push(b"b", 1)
     q1.push(b"c", 2)
     active = q1.close()
     q2 = PriorityQueue(self.qfactory, startprios=active)
     self.assertEqual(q2.pop(), b"b")
     self.assertEqual(q2.pop(), b"c")
     self.assertEqual(q2.pop(), b"a")
     self.assertEqual(q2.close(), [])
Beispiel #9
0
class FifoMemoryPriorityQueueTest(QueuelibTestCase):
    def setUp(self):
        QueuelibTestCase.setUp(self)
        self.q = PriorityQueue(self.qfactory)

    def qfactory(self, prio):
        return track_closed(FifoMemoryQueue)()

    def test_push_pop_noprio(self):
        self.q.push('a')
        self.q.push('b')
        self.q.push('c')
        self.assertEqual(self.q.pop(), 'a')
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(self.q.pop(), 'c')
        self.assertEqual(self.q.pop(), None)

    def test_push_pop_prio(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('d', 1)
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(self.q.pop(), 'd')
        self.assertEqual(self.q.pop(), 'c')
        self.assertEqual(self.q.pop(), 'a')
        self.assertEqual(self.q.pop(), None)

    def test_len_nonzero(self):
        assert not self.q
        self.assertEqual(len(self.q), 0)
        self.q.push('a', 3)
        assert self.q
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('d', 1)
        self.assertEqual(len(self.q), 4)
        self.q.pop()
        self.q.pop()
        self.q.pop()
        self.q.pop()
        assert not self.q
        self.assertEqual(len(self.q), 0)

    def test_close(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('d', 1)
        iqueues = self.q.queues.values()
        self.assertEqual(sorted(self.q.close()), [1, 2, 3])
        assert all(q.closed for q in iqueues)

    def test_close_return_active(self):
        self.q.push('b', 1)
        self.q.push('c', 2)
        self.q.push('a', 3)
        self.q.pop()
        self.assertEqual(sorted(self.q.close()), [2, 3])

    def test_popped_internal_queues_closed(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.q.push('c', 2)
        p1queue = self.q.queues[1]
        self.assertEqual(self.q.pop(), 'b')
        self.q.close()
        assert p1queue.closed
Beispiel #10
0
 def setUp(self):
     FifoMemoryPriorityQueueTest.setUp(self)
     self.q = PriorityQueue(self.qfactory)
Beispiel #11
0
class FifoDiskPriorityQueueTest(FifoMemoryPriorityQueueTest):
    def setUp(self):
        FifoMemoryPriorityQueueTest.setUp(self)
        self.q = PriorityQueue(self.qfactory)

    def qfactory(self, prio):
        return track_closed(FifoDiskQueue)(self.mktemp())

    def test_nonserializable_object_one(self):
        self.assertRaises(TypeError, self.q.push, lambda x: x, 0)
        self.assertEqual(self.q.close(), [])

    def test_nonserializable_object_many_close(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.assertRaises(TypeError, self.q.push, lambda x: x, 0)
        self.q.push('c', 2)
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(sorted(self.q.close()), [2, 3])

    def test_nonserializable_object_many_pop(self):
        self.q.push('a', 3)
        self.q.push('b', 1)
        self.assertRaises(TypeError, self.q.push, lambda x: x, 0)
        self.q.push('c', 2)
        self.assertEqual(self.q.pop(), 'b')
        self.assertEqual(self.q.pop(), 'c')
        self.assertEqual(self.q.pop(), 'a')
        self.assertEqual(self.q.pop(), None)
        self.assertEqual(self.q.close(), [])