def test_database_events(): A = Alphabet('ACGT') S = A.parse('AACT', name='S') # NOTE python 2 does not support non-local, non-global variables, put it in # the function object. test_database_events.callback_called = 0 def callback(self, *args): test_database_events.callback_called += 1 db = DB(':memory:', A) db.add_event_listener('db-initialized', callback) db.add_event_listener('sequence-inserted', callback) db.initialize() assert test_database_events.callback_called == 1, \ 'event callbacks for "initialize" should be executed' db.insert(S) assert test_database_events.callback_called == 2, \ 'event callbacks for "insert-sequence" should be executed'