harbor run -t openthoughts/tasktrove-mix-h11-single-skill-only-v2-mix-h11-single-skill-3818harbor download openthoughts/tasktrove-mix-h11-single-skill-only-v2-mix-h11-single-skill-3818Task Description:
Implement a simple task management system in Python that allows users to create, retrieve, update, and delete tasks. The system should maintain all tasks in memory and provide a way to interact with them through a command-line interface.
Task Model:
id: A unique identifier for the task (integer)title: A brief description of the task (string)completed: A boolean indicating whether the task is completed (default should be False).TaskManager Class:
TaskManager with the following methods:
add_task(title: str) -> int: Adds a new task with the given title and returns the task's unique ID.get_task(task_id: int) -> dict: Retrieves the task with the specified ID, returning its attributes as a dictionary. Raise a ValueError if the task does not exist.update_task(task_id: int, title: str, completed: bool) : Updates the title and completed status of the task with the specified ID. Raise a ValueError if the task does not exist.delete_task(task_id: int): Deletes the task with the specified ID. Raise a ValueError if the task does not exist.list_tasks() -> List[dict]: Returns a list of all tasks with their attributes as dictionaries.Error Handling:
File Structure:
/app/task_manager.py.Suppose this is your test_task_manager.py (the test file):
import unittest
from app.task_manager import TaskManager
class TestTaskManager(unittest.TestCase):
def test_add_task(self):
manager = TaskManager()
task_id = manager.add_task("Test task")
self.assertEqual(task_id, 1)
def test_get_task(self):
manager = TaskManager()
task_id = manager.add_task("Test task")
task = manager.get_task(task_id)
self.assertEqual(task, {'id': 1, 'title': 'Test task', 'completed': False})
def test_update_task(self):
manager = TaskManager()
task_id = manager.add_task("Test task")
manager.update_task(task_id, "Updated task", True)
task = manager.get_task(task_id)
self.assertEqual(task['title'], "Updated task")
self.assertEqual(task['completed'], True)
def test_delete_task(self):
manager = TaskManager()
task_id = manager.add_task("Test task")
manager.delete_task(task_id)
with self.assertRaises(ValueError):
manager.get_task(task_id)
def test_list_tasks(self):
manager = TaskManager()
manager.add_task("Test task 1")
manager.add_task("Test task 2")
tasks = manager.list_tasks()
self.assertEqual(len(tasks), 2)
if __name__ == '__main__':
unittest.main()
Your implementation should ensure all the above tests pass successfully.