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

Fixing the code

To fix the first error, add the following code to the _tasks class in planner/data.py:

def __eq__(self, other):
return self.name == other.name and self.begins == other.begins and self.ends == other.ends
def __ne__(self, other):
return not self.__eq__(other)

(Beware of the wrapped line in __eq__)

As you can probably tell, that code overrides the equality comparison between two _tasks, declaring them to be equal if they have the same name, begin time and end time. That's the equality metric that's implicitly assumed by the test code.

The second error can be fixed by fixing the typographical errors in schedules.add:

def add(self, task): for contained in self.tasks: if task.overlaps(contained): if task.excludes(contained) or contained.excludes(task): ...

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