O'Reilly logo

Test-Driven Python Development by Siddharta Govindaraj

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

Chapter 4. Using Mock Objects to Test Interactions

Having looked at the Rule and Stock classes, let us now turn our attention to the Event class. The Event class is very simple: receivers can register with the event to be notified when the event occurs. When the event fires, all the receivers are notified of the event.

A more detailed description is as follows:

  • Event classes have a connect method, which takes a method or function to be called when the event fires
  • When the fire method is called, all the registered callbacks are called with the same parameters that are passed to the fire method

Writing tests for the connect method is fairly straightforward—we just need to check that the receivers are being stored properly. But, how do we write the tests ...

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