O'Reilly logo

Python Testing Cookbook. by Bhaskar N. Das, Greg L. Turnquist

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

How to do it...

With the following steps, we will build some unittests and then run them through the coverage tool:

  1. Create a new file called recipe52.py to contain our test code for this recipe.
  2. Write a simple unit test that injects a single, alarming event into the system:
from network import * import unittestfrom springpython.database.factory import *from springpython.database.core import *class EventCorrelationTest(unittest.TestCase):      def setUp(self):          db_name = "recipe52.db"          factory = Sqlite3ConnectionFactory(db_name)          self.correlator = EventCorrelator(factory)          dt = DatabaseTemplate(factory)          sql = open("network.sql").read().split(";")          for statement in sql:              dt.execute(statement + ";")      def test_process_events(self): evt1 = Event("pyhost1", ...

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