test_convenience.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Test cases for convenience functionality in L{twisted._threads._convenience}.
  5. """
  6. from __future__ import absolute_import, division, print_function
  7. from twisted.trial.unittest import SynchronousTestCase
  8. from .._convenience import Quit
  9. from .._ithreads import AlreadyQuit
  10. class QuitTests(SynchronousTestCase):
  11. """
  12. Tests for L{Quit}
  13. """
  14. def test_isInitiallySet(self):
  15. """
  16. L{Quit.isSet} starts as L{False}.
  17. """
  18. quit = Quit()
  19. self.assertEqual(quit.isSet, False)
  20. def test_setSetsSet(self):
  21. """
  22. L{Quit.set} sets L{Quit.isSet} to L{True}.
  23. """
  24. quit = Quit()
  25. quit.set()
  26. self.assertEqual(quit.isSet, True)
  27. def test_checkDoesNothing(self):
  28. """
  29. L{Quit.check} initially does nothing and returns L{None}.
  30. """
  31. quit = Quit()
  32. self.assertIs(quit.check(), None)
  33. def test_checkAfterSetRaises(self):
  34. """
  35. L{Quit.check} raises L{AlreadyQuit} if L{Quit.set} has been called.
  36. """
  37. quit = Quit()
  38. quit.set()
  39. self.assertRaises(AlreadyQuit, quit.check)
  40. def test_setTwiceRaises(self):
  41. """
  42. L{Quit.set} raises L{AlreadyQuit} if it has been called previously.
  43. """
  44. quit = Quit()
  45. quit.set()
  46. self.assertRaises(AlreadyQuit, quit.set)