Exemplo n.º 1
0
def test_queue_getitem(tmpdir):
    (tmpdir / 'sophie'
     ).write_text('{"args": ["foo", "bar"], "message": "Sophie is cute"}')
    queue = queuelib.Queue(tmpdir)
    got = queue['sophie']
    assert isinstance(got, queuelib.Message)
    assert got.args == ['foo', 'bar']
    assert got.message == 'Sophie is cute'
Exemplo n.º 2
0
def test_queue_setitem(tmpdir):
    (tmpdir / 'sophie'
     ).write_text('{"args": ["foo", "bar"], "message": "Sophie is cute"}')
    queue = queuelib.Queue(tmpdir)
    message = queuelib.Message(
        args=['foo', 'bar'],
        message='Sophie is cute',
    )
    queue['sophie'] = message
    with (tmpdir / 'sophie').open() as file:
        got = json.load(file)
    assert got == {"args": ["foo", "bar"], "message": "Sophie is cute"}
Exemplo n.º 3
0
def test_queue_add(tmpdir):
    queue = queuelib.Queue(tmpdir)
    message = queuelib.Message(
        args=['foo', 'bar'],
        message='Sophie is cute',
    )
    with mock.patch.object(type(message),
                           'key',
                           new_callable=mock.PropertyMock) as key_mock:
        key_mock.return_value = 'message_key'
        got = queue.add(message)
    assert got == 'message_key'
    with (tmpdir / 'message_key').open() as file:
        got = json.load(file)
    assert got == {"args": ["foo", "bar"], "message": "Sophie is cute"}
Exemplo n.º 4
0
def test_queue_iter(tmpdir):
    queue = queuelib.Queue(tmpdir)
    assert list(queue) == []
    (tmpdir / 'sophie').write_text('')
    assert list(queue) == ['sophie']
Exemplo n.º 5
0
def test_queue_len(tmpdir):
    queue = queuelib.Queue(tmpdir)
    assert len(queue) == 0
    (tmpdir / 'sophie').write_text('')
    assert len(queue) == 1
Exemplo n.º 6
0
def test_queue_delitem(tmpdir):
    (tmpdir / 'sophie').write_text('')
    queue = queuelib.Queue(tmpdir)
    del queue['sophie']
    assert not (tmpdir / 'sophie').exists()
Exemplo n.º 7
0
def test_queue_getitem_missing(tmpdir):
    queue = queuelib.Queue(tmpdir)
    with pytest.raises(KeyError):
        queue['sophie']
Exemplo n.º 8
0
def test_queue_repr():
    queue = queuelib.Queue('/foo/bar')
    got = repr(queue)
    assert got == "Queue(PosixPath('/foo/bar'))"
Exemplo n.º 9
0
def _get_queue():
    return queuelib.Queue(QUEUE_DIR)