Finishing up

Now, Nose only reports one failed test, the check to see whether the original schedules instance and the one loaded from the file are equal. The problem here is that, once again, there's a need to redefine what it means to be equal.

That can be fixed by adding the following to the definition of schedules in planner/data.py:

def __eq__(self, other):
if len(self.tasks) != len(other.tasks):
return False
left_tasks = list(self.tasks)
left_tasks.sort(key = (lambda task: task.begins))
right_tasks = list(other.tasks)
right_tasks.sort(key = (lambda task: task.begins))
return tuple(left_tasks) == tuple(right_tasks)
def __ne__(self, other):
return not self.__eq__(other)

Note

The key parameter of sort was added in Python 2.4. Prior to that version, ...

Get Python Testing Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.