コード例 #1
0
def test_queue_writer_consume():
    names = [spshot_writers_path + '.QueueWriter.create_queue',
             spshot_writers_path + '.QueueWriter.create_consumer']
    with mock.patch(names[0]):
        with mock.patch(names[1]):
            task = mock.MagicMock()
            q = mock.MagicMock()
            q.get = mock.MagicMock(side_effect=[task, task, None])
            w = writing.QueueWriter()
            w.consume(q)

            assert q.get.call_count == 3
            assert task[0].call_count == 2
            assert q.task_done.call_count == 3
コード例 #2
0
def test_queue_writer():
    target = mock.MagicMock()
    q = mock.MagicMock()
    consumer = mock.MagicMock()
    names = [spshot_writers_path + '.QueueWriter.create_queue',
             spshot_writers_path + '.QueueWriter.create_consumer']
    with mock.patch(names[0], return_value=q):
        with mock.patch(names[1], return_value=consumer):
            w = writing.QueueWriter()

            with tempfile.TemporaryDirectory() as tempd:
                w('myfile.dat', tempd, target)
                w('myfile.dat', tempd, target)
                w.finalize()

            assert consumer.start.call_count == 1
            assert q.put.call_count == 3
            assert q.join.call_count, 1
            assert consumer.join.call_count == 1