Exemple #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'
Exemple #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"}
Exemple #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"}
Exemple #4
0
def test_queue_iter(tmpdir):
    queue = queuelib.Queue(tmpdir)
    assert list(queue) == []
    (tmpdir / 'sophie').write_text('')
    assert list(queue) == ['sophie']
Exemple #5
0
def test_queue_len(tmpdir):
    queue = queuelib.Queue(tmpdir)
    assert len(queue) == 0
    (tmpdir / 'sophie').write_text('')
    assert len(queue) == 1
Exemple #6
0
def test_queue_delitem(tmpdir):
    (tmpdir / 'sophie').write_text('')
    queue = queuelib.Queue(tmpdir)
    del queue['sophie']
    assert not (tmpdir / 'sophie').exists()
Exemple #7
0
def test_queue_getitem_missing(tmpdir):
    queue = queuelib.Queue(tmpdir)
    with pytest.raises(KeyError):
        queue['sophie']
Exemple #8
0
def test_queue_repr():
    queue = queuelib.Queue('/foo/bar')
    got = repr(queue)
    assert got == "Queue(PosixPath('/foo/bar'))"
Exemple #9
0
def _get_queue():
    return queuelib.Queue(QUEUE_DIR)