Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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 6.0KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 twisted.trial.unittest import FailTest, SkipTest, SynchronousTestCase, TestCase
  12. class SkippingMixin:
  13. def test_skip1(self):
  14. raise SkipTest("skip1")
  15. def test_skip2(self):
  16. raise RuntimeError("I should not get raised")
  17. test_skip2.skip = "skip2" # type: ignore[attr-defined]
  18. def test_skip3(self):
  19. self.fail("I should not fail")
  20. test_skip3.skip = "skip3" # type: ignore[attr-defined]
  21. class SynchronousSkipping(SkippingMixin, SynchronousTestCase):
  22. pass
  23. class AsynchronousSkipping(SkippingMixin, TestCase):
  24. pass
  25. class SkippingSetUpMixin:
  26. def setUp(self):
  27. raise SkipTest("skipSetUp")
  28. def test_1(self):
  29. pass
  30. def test_2(self):
  31. pass
  32. class SynchronousSkippingSetUp(SkippingSetUpMixin, SynchronousTestCase):
  33. pass
  34. class AsynchronousSkippingSetUp(SkippingSetUpMixin, TestCase):
  35. pass
  36. class DeprecatedReasonlessSkipMixin:
  37. def test_1(self):
  38. raise SkipTest()
  39. class SynchronousDeprecatedReasonlessSkip(
  40. DeprecatedReasonlessSkipMixin, SynchronousTestCase
  41. ):
  42. pass
  43. class AsynchronousDeprecatedReasonlessSkip(DeprecatedReasonlessSkipMixin, TestCase):
  44. pass
  45. class SkippedClassMixin:
  46. skip = "class"
  47. def setUp(self):
  48. self.__class__._setUpRan = True
  49. def test_skip1(self):
  50. raise SkipTest("skip1")
  51. def test_skip2(self):
  52. raise RuntimeError("Ought to skip me")
  53. test_skip2.skip = "skip2" # type: ignore
  54. def test_skip3(self):
  55. pass
  56. def test_skip4(self):
  57. raise RuntimeError("Skip me too")
  58. class SynchronousSkippedClass(SkippedClassMixin, SynchronousTestCase):
  59. pass
  60. class AsynchronousSkippedClass(SkippedClassMixin, TestCase):
  61. pass
  62. class TodoMixin:
  63. def test_todo1(self):
  64. self.fail("deliberate failure")
  65. test_todo1.todo = "todo1" # type: ignore[attr-defined]
  66. def test_todo2(self):
  67. raise RuntimeError("deliberate error")
  68. test_todo2.todo = "todo2" # type: ignore[attr-defined]
  69. def test_todo3(self):
  70. """unexpected success"""
  71. test_todo3.todo = "todo3" # type: ignore[attr-defined]
  72. class SynchronousTodo(TodoMixin, SynchronousTestCase):
  73. pass
  74. class AsynchronousTodo(TodoMixin, TestCase):
  75. pass
  76. class SetUpTodoMixin:
  77. def setUp(self):
  78. raise RuntimeError("deliberate error")
  79. def test_todo1(self):
  80. pass
  81. test_todo1.todo = "setUp todo1" # type: ignore[attr-defined]
  82. class SynchronousSetUpTodo(SetUpTodoMixin, SynchronousTestCase):
  83. pass
  84. class AsynchronousSetUpTodo(SetUpTodoMixin, TestCase):
  85. pass
  86. class TearDownTodoMixin:
  87. def tearDown(self):
  88. raise RuntimeError("deliberate error")
  89. def test_todo1(self):
  90. pass
  91. test_todo1.todo = "tearDown todo1" # type: ignore[attr-defined]
  92. class SynchronousTearDownTodo(TearDownTodoMixin, SynchronousTestCase):
  93. pass
  94. class AsynchronousTearDownTodo(TearDownTodoMixin, TestCase):
  95. pass
  96. class TodoClassMixin:
  97. todo = "class"
  98. def test_todo1(self):
  99. pass
  100. test_todo1.todo = "method" # type: ignore[attr-defined]
  101. def test_todo2(self):
  102. pass
  103. def test_todo3(self):
  104. self.fail("Deliberate Failure")
  105. test_todo3.todo = "method" # type: ignore[attr-defined]
  106. def test_todo4(self):
  107. self.fail("Deliberate Failure")
  108. class SynchronousTodoClass(TodoClassMixin, SynchronousTestCase):
  109. pass
  110. class AsynchronousTodoClass(TodoClassMixin, TestCase):
  111. pass
  112. class StrictTodoMixin:
  113. def test_todo1(self):
  114. raise RuntimeError("expected failure")
  115. test_todo1.todo = (RuntimeError, "todo1") # type: ignore[attr-defined]
  116. def test_todo2(self):
  117. raise RuntimeError("expected failure")
  118. test_todo2.todo = ((RuntimeError, OSError), "todo2") # type: ignore[attr-defined]
  119. def test_todo3(self):
  120. raise RuntimeError("we had no idea!")
  121. test_todo3.todo = (OSError, "todo3") # type: ignore[attr-defined]
  122. def test_todo4(self):
  123. raise RuntimeError("we had no idea!")
  124. test_todo4.todo = ((OSError, SyntaxError), "todo4") # type: ignore[attr-defined]
  125. def test_todo5(self):
  126. self.fail("deliberate failure")
  127. test_todo5.todo = (FailTest, "todo5") # type: ignore[attr-defined]
  128. def test_todo6(self):
  129. self.fail("deliberate failure")
  130. test_todo6.todo = (RuntimeError, "todo6") # type: ignore[attr-defined]
  131. def test_todo7(self):
  132. pass
  133. test_todo7.todo = (RuntimeError, "todo7") # type: ignore[attr-defined]
  134. class SynchronousStrictTodo(StrictTodoMixin, SynchronousTestCase):
  135. pass
  136. class AsynchronousStrictTodo(StrictTodoMixin, TestCase):
  137. pass
  138. class AddCleanupMixin:
  139. def setUp(self):
  140. self.log = ["setUp"]
  141. def brokenSetUp(self):
  142. self.log = ["setUp"]
  143. raise RuntimeError("Deliberate failure")
  144. def skippingSetUp(self):
  145. self.log = ["setUp"]
  146. raise SkipTest("Don't do this")
  147. def append(self, thing):
  148. self.log.append(thing)
  149. def tearDown(self):
  150. self.log.append("tearDown")
  151. def runTest(self):
  152. self.log.append("runTest")
  153. class SynchronousAddCleanup(AddCleanupMixin, SynchronousTestCase):
  154. pass
  155. class AsynchronousAddCleanup(AddCleanupMixin, TestCase):
  156. pass
  157. class ExpectedFailure(SynchronousTestCase):
  158. """
  159. Hold a test that has an expected failure with an exception that has a
  160. large string representation.
  161. """
  162. def test_expectedFailureGreaterThan64k(self) -> None:
  163. """
  164. Fail, but expectedly.
  165. """
  166. raise RuntimeError("x" * (2 ** 16 + 1))
  167. test_expectedFailureGreaterThan64k.todo = "short todo string" # type: ignore[attr-defined]