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.

skipping.py 5.2KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. # -*- test-case-name: twisted.trial.test.test_tests -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Definitions of test cases with various interesting behaviors, to be used by
  6. L{twisted.trial.test.test_tests} and other test modules to exercise different
  7. features of trial's test runner.
  8. See the L{twisted.trial.test.test_tests} module docstring for details about how
  9. this code is arranged.
  10. """
  11. from __future__ import division, absolute_import
  12. from twisted.trial.unittest import (
  13. SynchronousTestCase, TestCase, SkipTest, FailTest)
  14. class SkippingMixin(object):
  15. def test_skip1(self):
  16. raise SkipTest('skip1')
  17. def test_skip2(self):
  18. raise RuntimeError("I should not get raised")
  19. test_skip2.skip = 'skip2'
  20. def test_skip3(self):
  21. self.fail('I should not fail')
  22. test_skip3.skip = 'skip3'
  23. class SynchronousSkipping(SkippingMixin, SynchronousTestCase):
  24. pass
  25. class AsynchronousSkipping(SkippingMixin, TestCase):
  26. pass
  27. class SkippingSetUpMixin(object):
  28. def setUp(self):
  29. raise SkipTest('skipSetUp')
  30. def test_1(self):
  31. pass
  32. def test_2(self):
  33. pass
  34. class SynchronousSkippingSetUp(SkippingSetUpMixin, SynchronousTestCase):
  35. pass
  36. class AsynchronousSkippingSetUp(SkippingSetUpMixin, TestCase):
  37. pass
  38. class DeprecatedReasonlessSkipMixin(object):
  39. def test_1(self):
  40. raise SkipTest()
  41. class SynchronousDeprecatedReasonlessSkip(
  42. DeprecatedReasonlessSkipMixin, SynchronousTestCase):
  43. pass
  44. class AsynchronousDeprecatedReasonlessSkip(
  45. DeprecatedReasonlessSkipMixin, TestCase):
  46. pass
  47. class SkippedClassMixin(object):
  48. skip = 'class'
  49. def setUp(self):
  50. self.__class__._setUpRan = True
  51. def test_skip1(self):
  52. raise SkipTest('skip1')
  53. def test_skip2(self):
  54. raise RuntimeError("Ought to skip me")
  55. test_skip2.skip = 'skip2'
  56. def test_skip3(self):
  57. pass
  58. def test_skip4(self):
  59. raise RuntimeError("Skip me too")
  60. class SynchronousSkippedClass(SkippedClassMixin, SynchronousTestCase):
  61. pass
  62. class AsynchronousSkippedClass(SkippedClassMixin, TestCase):
  63. pass
  64. class TodoMixin(object):
  65. def test_todo1(self):
  66. self.fail("deliberate failure")
  67. test_todo1.todo = "todo1"
  68. def test_todo2(self):
  69. raise RuntimeError("deliberate error")
  70. test_todo2.todo = "todo2"
  71. def test_todo3(self):
  72. """unexpected success"""
  73. test_todo3.todo = 'todo3'
  74. class SynchronousTodo(TodoMixin, SynchronousTestCase):
  75. pass
  76. class AsynchronousTodo(TodoMixin, TestCase):
  77. pass
  78. class SetUpTodoMixin(object):
  79. def setUp(self):
  80. raise RuntimeError("deliberate error")
  81. def test_todo1(self):
  82. pass
  83. test_todo1.todo = "setUp todo1"
  84. class SynchronousSetUpTodo(SetUpTodoMixin, SynchronousTestCase):
  85. pass
  86. class AsynchronousSetUpTodo(SetUpTodoMixin, TestCase):
  87. pass
  88. class TearDownTodoMixin(object):
  89. def tearDown(self):
  90. raise RuntimeError("deliberate error")
  91. def test_todo1(self):
  92. pass
  93. test_todo1.todo = "tearDown todo1"
  94. class SynchronousTearDownTodo(TearDownTodoMixin, SynchronousTestCase):
  95. pass
  96. class AsynchronousTearDownTodo(TearDownTodoMixin, TestCase):
  97. pass
  98. class TodoClassMixin(object):
  99. todo = "class"
  100. def test_todo1(self):
  101. pass
  102. test_todo1.todo = "method"
  103. def test_todo2(self):
  104. pass
  105. def test_todo3(self):
  106. self.fail("Deliberate Failure")
  107. test_todo3.todo = "method"
  108. def test_todo4(self):
  109. self.fail("Deliberate Failure")
  110. class SynchronousTodoClass(TodoClassMixin, SynchronousTestCase):
  111. pass
  112. class AsynchronousTodoClass(TodoClassMixin, TestCase):
  113. pass
  114. class StrictTodoMixin(object):
  115. def test_todo1(self):
  116. raise RuntimeError("expected failure")
  117. test_todo1.todo = (RuntimeError, "todo1")
  118. def test_todo2(self):
  119. raise RuntimeError("expected failure")
  120. test_todo2.todo = ((RuntimeError, OSError), "todo2")
  121. def test_todo3(self):
  122. raise RuntimeError("we had no idea!")
  123. test_todo3.todo = (OSError, "todo3")
  124. def test_todo4(self):
  125. raise RuntimeError("we had no idea!")
  126. test_todo4.todo = ((OSError, SyntaxError), "todo4")
  127. def test_todo5(self):
  128. self.fail("deliberate failure")
  129. test_todo5.todo = (FailTest, "todo5")
  130. def test_todo6(self):
  131. self.fail("deliberate failure")
  132. test_todo6.todo = (RuntimeError, "todo6")
  133. def test_todo7(self):
  134. pass
  135. test_todo7.todo = (RuntimeError, "todo7")
  136. class SynchronousStrictTodo(StrictTodoMixin, SynchronousTestCase):
  137. pass
  138. class AsynchronousStrictTodo(StrictTodoMixin, TestCase):
  139. pass
  140. class AddCleanupMixin(object):
  141. def setUp(self):
  142. self.log = ['setUp']
  143. def brokenSetUp(self):
  144. self.log = ['setUp']
  145. raise RuntimeError("Deliberate failure")
  146. def skippingSetUp(self):
  147. self.log = ['setUp']
  148. raise SkipTest("Don't do this")
  149. def append(self, thing):
  150. self.log.append(thing)
  151. def tearDown(self):
  152. self.log.append('tearDown')
  153. def runTest(self):
  154. self.log.append('runTest')
  155. class SynchronousAddCleanup(AddCleanupMixin, SynchronousTestCase):
  156. pass
  157. class AsynchronousAddCleanup(AddCleanupMixin, TestCase):
  158. pass