You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

receiver.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Receivers for use in tests.
  5. """
  6. from __future__ import absolute_import, division
  7. from twisted.positioning import base, ipositioning
  8. class MockPositioningReceiver(base.BasePositioningReceiver):
  9. """
  10. A mock positioning receiver.
  11. Mocks all the L{IPositioningReceiver} methods with stubs that don't do
  12. anything but register that they were called.
  13. @ivar called: A mapping of names of callbacks that have been called to
  14. C{True}.
  15. @type called: C{dict}
  16. """
  17. def __init__(self):
  18. self.clear()
  19. for methodName in ipositioning.IPositioningReceiver:
  20. self._addCallback(methodName)
  21. def clear(self):
  22. """
  23. Forget all the methods that have been called on this receiver, by
  24. emptying C{self.called}.
  25. """
  26. self.called = {}
  27. def _addCallback(self, name):
  28. """
  29. Adds a callback of the given name, setting C{self.called[name]} to
  30. C{True} when called.
  31. """
  32. def callback(*a, **kw):
  33. self.called[name] = True
  34. setattr(self, name, callback)