def test_submitting_list(label1, label2):
    q = SimpleLabellingQueue()
    q.enqueue(1)
    with pytest.raises(ValueError):
        q.submit(0, label1)
    id_, val = q.pop()
    q.submit(id_, [label1, label2])
    assert q.list_labels() == {label1, label2}
def test_progress():
    inps = [str(i) for i in range(50)]
    q = SimpleLabellingQueue()
    # assert my little hack for dividing by zero
    assert q.progress == 0
    q.enqueue_many(inps)

    for i, (id_, val) in enumerate(q):
        assert q.progress == i / len(inps)
        q.submit(id_, str(i))
def test_undo():
    inp = "input 1"
    q = SimpleLabellingQueue()
    q.enqueue(inp)
    id_, val = q.pop()
    q.submit(id_, "label 1")
    # ensure the queue is empty now:
    with pytest.raises(IndexError):
        q.pop()
    q.undo()
    # see if it's possible to pop now:
    id_, val = q.pop()
    assert val == "input 1"
def test_list_uncompleted(inputs, labels):
    q = SimpleLabellingQueue()
    q.enqueue_many(inputs)

    popped_ids = []
    for i in range(5):
        id_, val = q.pop()
        q.submit(id_, labels[i])

        popped_ids.append(id_)

    ids, x = q.list_uncompleted()

    assert len(ids) == (len(inputs) - 5)
    # test that the popped IDs and completed IDs don't share members
    assert pytest.helpers.no_shared_members(ids, popped_ids)
    assert pytest.helpers.same_elements(x, inputs[5:])
def test_list_completed(inputs, labels):
    q = SimpleLabellingQueue()
    q.enqueue_many(inputs)

    popped_ids = []
    for i in range(5):
        id_, val = q.pop()
        q.submit(id_, labels[i])

        popped_ids.append(id_)

    ids, x, y = q.list_completed()

    assert len(ids) == 5
    # test that the popped IDs and completed IDs have the same members
    assert pytest.helpers.same_elements(ids, popped_ids)
    assert pytest.helpers.same_elements(y, labels[:5])
def test_list_all(inputs, labels):
    q = SimpleLabellingQueue()
    q.enqueue_many(inputs)

    popped_ids = []
    for i in range(5):
        id_, val = q.pop()
        q.submit(id_, labels[i])

        popped_ids.append(id_)

    ids, x, y = q.list_all()

    assert len(ids) == len(inputs)
    assert all(label in labels for label in y if label is not None)
    assert all(label is None or id_ in popped_ids
               for id_, label in zip(ids, y))
    assert Counter(y)[None] == (len(inputs) - 5)
    assert pytest.helpers.same_elements(ids, range(len(inputs)))
def test_enqueue_dataframe(inputs):
    n = len(inputs)
    q = SimpleLabellingQueue()
    q.enqueue_many(inputs)
    assert len(q.data) == n
    # assert we can pop everything:
    for _ in range(n):
        id_, val = q.pop()
        assert isinstance(val, pd.Series)
    # assert there's nothing else to pop:
    with pytest.raises(IndexError):
        q.pop()
    # assert it re-constructs a df on list all
    if n > 0:
        ids, X, y = q.list_all()
        assert isinstance(X, pd.DataFrame) or len(X) == 0
        # assert it re-constructs a df on list uncomplete
        q.submit(ids[0], "hello")
        ids, X = q.list_uncompleted()
        assert isinstance(X, pd.DataFrame) or len(X) == 0
        # assert it re-constructs a df on list uncomplete
        ids, X, y = q.list_completed()
        assert isinstance(X, pd.DataFrame) or len(X) == 0
def test_submitting_text(label1, label2):
    q = SimpleLabellingQueue()
    q.enqueue(1)
    q.enqueue(2)
    with pytest.raises(ValueError):
        q.submit(0, label1)
    id_, val = q.pop()
    q.submit(id_, label1)
    assert q.progress == 0.5
    id_, val = q.pop()
    q.submit(id_, label2)
    assert q.progress == 1
    assert q.list_labels() == {label1, label2}