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.

suppression.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # -*- test-case-name: twisted.trial.test.test_tests -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Test cases used to make sure that warning suppression works at the module,
  6. method, and class levels.
  7. See the L{twisted.trial.test.test_tests} module docstring for details about how
  8. this code is arranged.
  9. """
  10. import warnings
  11. from twisted.trial import unittest, util
  12. METHOD_WARNING_MSG = "method warning message"
  13. CLASS_WARNING_MSG = "class warning message"
  14. MODULE_WARNING_MSG = "module warning message"
  15. class MethodWarning(Warning):
  16. pass
  17. class ClassWarning(Warning):
  18. pass
  19. class ModuleWarning(Warning):
  20. pass
  21. class EmitMixin:
  22. """
  23. Mixin for emiting a variety of warnings.
  24. """
  25. def _emit(self):
  26. warnings.warn(METHOD_WARNING_MSG, MethodWarning)
  27. warnings.warn(CLASS_WARNING_MSG, ClassWarning)
  28. warnings.warn(MODULE_WARNING_MSG, ModuleWarning)
  29. class SuppressionMixin(EmitMixin):
  30. suppress = [util.suppress(message=CLASS_WARNING_MSG)]
  31. def testSuppressMethod(self):
  32. self._emit()
  33. testSuppressMethod.suppress = [util.suppress(message=METHOD_WARNING_MSG)] # type: ignore[attr-defined]
  34. def testSuppressClass(self):
  35. self._emit()
  36. def testOverrideSuppressClass(self):
  37. self._emit()
  38. testOverrideSuppressClass.suppress = [] # type: ignore[attr-defined]
  39. class SetUpSuppressionMixin:
  40. def setUp(self):
  41. self._emit()
  42. class TearDownSuppressionMixin:
  43. def tearDown(self):
  44. self._emit()
  45. class TestSuppression2Mixin(EmitMixin):
  46. def testSuppressModule(self):
  47. self._emit()
  48. suppress = [util.suppress(message=MODULE_WARNING_MSG)]
  49. class SynchronousTestSuppression(SuppressionMixin, unittest.SynchronousTestCase):
  50. pass
  51. class SynchronousTestSetUpSuppression(
  52. SetUpSuppressionMixin, SynchronousTestSuppression
  53. ):
  54. pass
  55. class SynchronousTestTearDownSuppression(
  56. TearDownSuppressionMixin, SynchronousTestSuppression
  57. ):
  58. pass
  59. class SynchronousTestSuppression2(TestSuppression2Mixin, unittest.SynchronousTestCase):
  60. pass
  61. class AsynchronousTestSuppression(SuppressionMixin, unittest.TestCase):
  62. pass
  63. class AsynchronousTestSetUpSuppression(
  64. SetUpSuppressionMixin, AsynchronousTestSuppression
  65. ):
  66. pass
  67. class AsynchronousTestTearDownSuppression(
  68. TearDownSuppressionMixin, AsynchronousTestSuppression
  69. ):
  70. pass
  71. class AsynchronousTestSuppression2(TestSuppression2Mixin, unittest.TestCase):
  72. pass