Time for action organizing tests from previous chapters

We're going to take our tests from the previous chapters and organize them all into a tree of directories. Then we'll use Nose to run them all. 1. Create a directory to hold our code and tests you can choose any name for it, but I'll refer to it as project here. 2. Put pid.py, operations.py and testable.py inside of project. When we run nosetests in the project directory, modules (and packages) stored in project will be accessible to all of the tests, no matter where the test is stored in the...

Time for action browsing the web with Twill

We'll take Twill for a spin, using its interactive interpreter. 1. Start the interactive Twill interpreter If you're using a version of Python older than 2.6, you won't be able to do a - -user installation, which means you'll need to have write access to the Python installation's site-packages directory. You may notice a couple of warnings about the deprecated md5 module when you start Twill. You may safely ignore them. 2. Get a list of Twill commands. You can get further information about a...

Twill commands

Twill has a number of commands, and so far we've only covered a few of them. In this section you'll find a brief discussion of each of Twill's commands. The help command prints out a list of all of Twill's commands, or tells you the details of a specific command. For example, to get the details of the add_auth command, you should type Help for command add_auth add_auth lt realm gt lt uri gt lt user gt lt passwd gt Add HTTP Basic Authentication information for the given realm uri. If you want to...

Replacing library objects with mocks

Several times, we've seen a need to replace something outside of our own code with a mock object for example, time.time needed to be replaced with something that produced predictable results, in order for the tests on our PID controller to be meaningful. Mocker provides us with a tool to address this common need, and it's quite simple to use. Mocker's mocking contexts contain a method called replace which behaves pretty much like mock from our point of view, but which is able to completely...