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", ...

Get Python Testing Cookbook. now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.