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