O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required