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.

pyunitcases.py 3.1KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Sample test cases defined using the standard library L{unittest.TestCase}
  5. class which are used as data by test cases which are actually part of the
  6. trial test suite to verify handling of handling of such cases.
  7. """
  8. import unittest
  9. from sys import exc_info
  10. from twisted.python.failure import Failure
  11. class PyUnitTest(unittest.TestCase):
  12. def test_pass(self):
  13. """
  14. A passing test.
  15. """
  16. def test_error(self):
  17. """
  18. A test which raises an exception to cause an error.
  19. """
  20. raise Exception("pyunit error")
  21. def test_fail(self):
  22. """
  23. A test which uses L{unittest.TestCase.fail} to cause a failure.
  24. """
  25. self.fail("pyunit failure")
  26. @unittest.skip("pyunit skip")
  27. def test_skip(self):
  28. """
  29. A test which uses the L{unittest.skip} decorator to cause a skip.
  30. """
  31. class _NonStringId:
  32. """
  33. A class that looks a little like a TestCase, but not enough so to
  34. actually be used as one. This helps L{BrokenRunInfrastructure} use some
  35. interfaces incorrectly to provoke certain failure conditions.
  36. """
  37. def id(self) -> object:
  38. return object()
  39. class BrokenRunInfrastructure(unittest.TestCase):
  40. """
  41. A test suite that is broken at the level of integration between
  42. L{TestCase.run} and the results object.
  43. """
  44. def run(self, result):
  45. """
  46. Override the normal C{run} behavior to pass the result object
  47. along to the test method. Each test method needs the result object so
  48. that it can implement its particular kind of brokenness.
  49. """
  50. return getattr(self, self._testMethodName)(result)
  51. def test_addSuccess(self, result):
  52. """
  53. Violate the L{TestResult.addSuccess} interface.
  54. """
  55. result.addSuccess(_NonStringId())
  56. def test_addError(self, result):
  57. """
  58. Violate the L{TestResult.addError} interface.
  59. """
  60. try:
  61. raise Exception("test_addError")
  62. except BaseException:
  63. err = exc_info()
  64. result.addError(_NonStringId(), err)
  65. def test_addFailure(self, result):
  66. """
  67. Violate the L{TestResult.addFailure} interface.
  68. """
  69. try:
  70. raise Exception("test_addFailure")
  71. except BaseException:
  72. err = exc_info()
  73. result.addFailure(_NonStringId(), err)
  74. def test_addSkip(self, result):
  75. """
  76. Violate the L{TestResult.addSkip} interface.
  77. """
  78. result.addSkip(_NonStringId(), "test_addSkip")
  79. def test_addExpectedFailure(self, result):
  80. """
  81. Violate the L{TestResult.addExpectedFailure} interface.
  82. """
  83. try:
  84. raise Exception("test_addExpectedFailure")
  85. except BaseException:
  86. err = Failure()
  87. result.addExpectedFailure(_NonStringId(), err)
  88. def test_addUnexpectedSuccess(self, result):
  89. """
  90. Violate the L{TestResult.addUnexpectedSuccess} interface.
  91. """
  92. result.addUnexpectedSuccess(_NonStringId())