def setUp(self): self.cbRunner = CallbackRunner()
def setUp(self): self.cbRunner = CallbackRunner()
class TestCallbackRunner(unittest.TestCase): def setUp(self): self.cbRunner = CallbackRunner() def test_addingCallback(self): """ Add a callback and trigger it """ callback = LogingCallback() self.cbRunner.add_callback(callback) self.cbRunner._run_callbacks() self.assertEqual([(tuple() , { })], callback.log) def test_callbackArgs(self): """ Add a callback, with some args, and trigger it """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'foo', 'bar') self.cbRunner._run_callbacks() self.assertEqual([(('foo', 'bar') , { })], callback.log) def test_callbackKWArgs(self): """ Add a callback, with some KWArgs, and trigger it """ callback = LogingCallback() self.cbRunner.add_callback(callback, foo='bar') self.cbRunner._run_callbacks() self.assertEqual([(tuple() , {'foo' : 'bar'})], callback.log) def test_callbackArgsAndKWargs(self): """ Add a callback, with both Args and KWArgs, and trigger it. """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'empathy', foo='bar') self.cbRunner._run_callbacks() self.assertEqual([(('empathy', ) , {'foo' : 'bar'})], callback.log) def test_multipleCallbacks(self): """ Add two callbacks. Each should be run with its specified arguments """ cb1 = LogingCallback() cb2 = LogingCallback() self.cbRunner.add_callback(cb1, 'cb1 called') self.cbRunner.add_callback(cb2, 'cb2 called') self.cbRunner._run_callbacks() self.assertEqual([(('cb1 called',), {})], cb1.log) self.assertEqual([(('cb2 called',), {})], cb2.log) def test_registerCallbackMultipleTimes(self): """ Registering a callback twice should update the args and kwargs, but NOT cause it to be called twice """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'foo') self.cbRunner.add_callback(callback, 'bar') self.cbRunner._run_callbacks() self.assertEqual([(('bar', ) , {})], callback.log) def test_callbackOnlyRunOnce(self): """ Callbacks should be removed after they are run. Each call to add_callback should trigger at most one callback """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'foo') self.cbRunner._run_callbacks() self.cbRunner._run_callbacks() self.assertEqual([(('foo', ) , {})], callback.log)
class TestCallbackRunner(unittest.TestCase): def setUp(self): self.cbRunner = CallbackRunner() def test_addingCallback(self): """ Add a callback and trigger it """ callback = LogingCallback() self.cbRunner.add_callback(callback) self.cbRunner._run_callbacks() self.assertEqual([(tuple(), {})], callback.log) def test_callbackArgs(self): """ Add a callback, with some args, and trigger it """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'foo', 'bar') self.cbRunner._run_callbacks() self.assertEqual([(('foo', 'bar'), {})], callback.log) def test_callbackKWArgs(self): """ Add a callback, with some KWArgs, and trigger it """ callback = LogingCallback() self.cbRunner.add_callback(callback, foo='bar') self.cbRunner._run_callbacks() self.assertEqual([(tuple(), {'foo': 'bar'})], callback.log) def test_callbackArgsAndKWargs(self): """ Add a callback, with both Args and KWArgs, and trigger it. """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'empathy', foo='bar') self.cbRunner._run_callbacks() self.assertEqual([(('empathy', ), {'foo': 'bar'})], callback.log) def test_multipleCallbacks(self): """ Add two callbacks. Each should be run with its specified arguments """ cb1 = LogingCallback() cb2 = LogingCallback() self.cbRunner.add_callback(cb1, 'cb1 called') self.cbRunner.add_callback(cb2, 'cb2 called') self.cbRunner._run_callbacks() self.assertEqual([(('cb1 called', ), {})], cb1.log) self.assertEqual([(('cb2 called', ), {})], cb2.log) def test_registerCallbackMultipleTimes(self): """ Registering a callback twice should update the args and kwargs, but NOT cause it to be called twice """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'foo') self.cbRunner.add_callback(callback, 'bar') self.cbRunner._run_callbacks() self.assertEqual([(('bar', ), {})], callback.log) def test_callbackOnlyRunOnce(self): """ Callbacks should be removed after they are run. Each call to add_callback should trigger at most one callback """ callback = LogingCallback() self.cbRunner.add_callback(callback, 'foo') self.cbRunner._run_callbacks() self.cbRunner._run_callbacks() self.assertEqual([(('foo', ), {})], callback.log)