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

Coding planner.data

It's time to write some code, using the specification document and the unit tests as guides. Specifically, it's time to write the planner.data module, which contains statuses, activities, and schedules.

I made a directory called planner, and within that directory created a file called __init__.py. There's no need to put anything inside __init__.py, but the file itself needs to exist to tell Python that the planner directory is a package.

The following code goes in planner/data.py:

from datetime import timedelta class task_error(Exception): pass class schedule_error(Exception): pass class _tasks: def __init__(self, name, begins, ends): if ends < begins: raise task_error('The begin time must precede the end time') if ends - begins ...

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