-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish testing the WorkingSet API (#28)
Aside from a missing `__repr__`, this API was already in good shape, but not completely tested.
- Loading branch information
Showing
5 changed files
with
79 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,71 @@ | ||
from taskchampion import Replica, WorkingSet, Status, Operations | ||
from pathlib import Path | ||
import pytest | ||
import re | ||
import uuid | ||
|
||
|
||
@pytest.fixture | ||
def working_set(): | ||
def uuids(): | ||
return [str(uuid.uuid4()) for _ in range(0, 5)] | ||
|
||
|
||
@pytest.fixture | ||
def working_set(uuids: list[str]): | ||
r = Replica.new_in_memory() | ||
|
||
ops = Operations() | ||
task = r.create_task(str(uuid.uuid4()), ops) | ||
task.set_status(Status.Pending, ops) | ||
task = r.create_task(str(uuid.uuid4()), ops) | ||
task.set_status(Status.Pending, ops) | ||
task.start(ops) | ||
task1 = r.create_task(uuids[1], ops) | ||
task1.set_status(Status.Pending, ops) | ||
task2 = r.create_task(uuids[2], ops) | ||
task2.set_status(Status.Pending, ops) | ||
task2.start(ops) | ||
task3 = r.create_task(uuids[3], ops) | ||
task3.set_status(Status.Pending, ops) | ||
task4 = r.create_task(uuids[4], ops) | ||
task4.set_status(Status.Pending, ops) | ||
r.commit_operations(ops) | ||
|
||
# Remove task 3 from working set | ||
ops = Operations() | ||
task3.set_status(Status.Completed, ops) | ||
r.commit_operations(ops) | ||
r.rebuild_working_set(False) | ||
|
||
return r.working_set() | ||
|
||
|
||
def test_len(working_set: WorkingSet): | ||
assert len(working_set) == 2 | ||
assert len(working_set) == 3 | ||
|
||
|
||
def test_repr(working_set: WorkingSet): | ||
# The Rust Debug output contains lots of internal details that we do not | ||
# need to check for here. | ||
assert re.match(r"^WorkingSet {.*}$", repr(working_set)) | ||
|
||
|
||
def test_largest_index(working_set: WorkingSet): | ||
assert working_set.largest_index() == 2 | ||
assert working_set.largest_index() == 4 | ||
|
||
|
||
def test_is_empty(working_set: WorkingSet): | ||
assert not working_set.is_empty() | ||
|
||
|
||
def test_by_index(working_set: WorkingSet): | ||
assert working_set.by_index(1) is not None | ||
|
||
def test_by_index(working_set: WorkingSet, uuids: list[str]): | ||
assert working_set.by_index(1) == uuids[1] | ||
assert working_set.by_index(2) == uuids[2] | ||
assert working_set.by_index(3) == None | ||
assert working_set.by_index(4) == uuids[4] | ||
|
||
def test_iter(working_set: WorkingSet): | ||
assert iter(working_set) | ||
|
||
def test_by_uuid(working_set: WorkingSet, uuids: list[str]): | ||
assert working_set.by_uuid(uuids[1]) == 1 | ||
assert working_set.by_uuid(uuids[2]) == 2 | ||
assert working_set.by_uuid(uuids[3]) == None | ||
assert working_set.by_uuid(uuids[4]) == 4 | ||
|
||
def test_next(working_set: WorkingSet): | ||
working_set_iterator = iter(working_set) | ||
|
||
assert next(working_set_iterator)[0] == 1 | ||
assert next(working_set_iterator)[0] == 2 | ||
with pytest.raises(StopIteration): | ||
next(working_set_iterator) | ||
def test_iter(working_set: WorkingSet, uuids: list[str]): | ||
assert list(working_set) == [(1, uuids[1]), (2, uuids[2]), (4, uuids[4])] |