import json from .task import Task class TaskManager: def __init__(self): # lower I added pragma, because if you look into my tests, you will see # that I added if statements for cases, if tasks are None, but not empty list # because mutmut tells that this line survives mutation on self.tasks = None, # however, I added checking for None, and it wasn't fixed self.tasks = [] # pragma: no mutate self.load_tasks() def add_task(self, task_text, priority, due_date): task = Task(task_text, priority, due_date) self.tasks.append(task) print("Task added successfully!") # pragma: no mutate def remove_task(self, task_index): if 0 <= task_index < len(self.tasks): removed_task = self.tasks.pop(task_index) print(f"Removed task: {removed_task.task_text}") # pragma: no mutate else: print("Invalid task number!") # pragma: no mutate def complete_task(self, task_index): if 0 <= task_index < len(self.tasks): self.tasks[task_index].mark_completed() print("Task marked as completed!") # pragma: no mutate else: print("Invalid task number!") # pragma: no mutate def list_tasks(self): if not self.tasks: print("No tasks found.") # pragma: no mutate else: print("\nTask List:") # pragma: no mutate for i, task in enumerate(self.tasks, start=1): # pragma: no mutate status = "Completed" if task.completed else "Not Completed" # pragma: no mutate print(f"{i}. Task: {task.task_text}") # pragma: no mutate print(f" Priority: {task.priority}") # pragma: no mutate print(f" Due Date: {task.due_date}") # pragma: no mutate print(f" Status: {status}\n") # pragma: no mutate def save_tasks(self): with open("tasks.json", "w") as file: json.dump([task.to_dict() for task in self.tasks], file) def load_tasks(self): try: with open("tasks.json", "r") as file: self.tasks = [Task.from_dict(task_data) for task_data in json.load(file)] except (FileNotFoundError, json.JSONDecodeError): self.tasks = []