Created
March 18, 2024 17:25
-
-
Save jangia/660af2c3417c40d7c55229a0b54217b5 to your computer and use it in GitHub Desktop.
Testing behavior, not implementation details – In-Memory Store
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
# behavior/store.py | |
class TaskStoreInMemory(TaskStore): | |
def __init__(self): | |
self._tasks = [] | |
def add_task(self, task: Task) -> None: | |
self._tasks.append(task) | |
def list_tasks(self) -> list[Task]: | |
return self._tasks |
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
# behavior/tests.py | |
@pytest.fixture | |
def store_() -> TaskStoreInMemory: | |
return TaskStoreInMemory() | |
def test_added_task_listed_(store_: TaskStoreInMemory): | |
task = Task(title="Do the dishes", status=TaskStatus.OPEN) | |
store_.add_task(task) | |
assert store_.list_tasks() == [task] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment