7 Tests the Dispatch module. 17 def call(self, name, data):
22 Tests xbee.helpers.dispatch for expected behavior 32 After registerring a callback function with a filter function, 33 the callback should be called when data arrives. 41 After registerring a callback function with a filter function, 42 the callback should not be called if a packet which does not 43 satisfy the callback's filter arrives. 51 Many callbacks should be called on the same packet if each 52 callback's filter method is satisfied. 58 callbacks.append(check)
59 self.
dispatch.register(
"test%d" % i, check.call,
lambda data:
True)
63 for callback
in callbacks:
64 if not callback.called:
65 self.fail(
"All callback methods should be called")
69 If a call to register() results in attempting to register a 70 callback with the same name as another callback should result 71 in a ValueError exception being raised. 73 self.
dispatch.register(
"test",
None,
None)
74 self.assertRaises(ValueError, self.
dispatch.register,
"test",
None,
None)
79 Tests Dispatch functionality when it is not constructed with a serial 87 A user may construct a Dispatch with neither a serial port nor 88 an XBee. This allows one to configure an XBee to asynchronously 89 call dispatch() whenever a packet arrives. 95 A ValueError must be raised by a headless Dispatch instance if 96 a user attempts to call run(). 98 self.assertRaises(ValueError, self.headless.run)
def test_callback_name_collisions_raise_valueerror(self)
def test_dispatch_can_be_created(self)
def call(self, name, data)
def test_multiple_callbacks(self)
def test_callback_is_called_when_registered(self)
def test_callback_not_called_when_filter_not_satisfied(self)
def test_run_raises_exception(self)