OLD | NEW |
| (Empty) |
1 # -*- test-case-name: twisted.trial.test.test_tests -*- | |
2 | |
3 import warnings | |
4 | |
5 from twisted.trial import unittest, util | |
6 | |
7 | |
8 """ test to make sure that warning supression works at the module, method, and | |
9 class levels | |
10 """ | |
11 | |
12 METHOD_WARNING_MSG = "method warning message" | |
13 CLASS_WARNING_MSG = "class warning message" | |
14 MODULE_WARNING_MSG = "module warning message" | |
15 | |
16 class MethodWarning(Warning): | |
17 pass | |
18 | |
19 class ClassWarning(Warning): | |
20 pass | |
21 | |
22 class ModuleWarning(Warning): | |
23 pass | |
24 | |
25 class EmitMixin: | |
26 __counter = 0 | |
27 | |
28 def _emit(self): | |
29 warnings.warn(METHOD_WARNING_MSG + '_%s' % (EmitMixin.__counter), Method
Warning) | |
30 warnings.warn(CLASS_WARNING_MSG + '_%s' % (EmitMixin.__counter), ClassWa
rning) | |
31 warnings.warn(MODULE_WARNING_MSG + '_%s' % (EmitMixin.__counter), Module
Warning) | |
32 EmitMixin.__counter += 1 | |
33 | |
34 | |
35 class TestSuppression(unittest.TestCase, EmitMixin): | |
36 def testSuppressMethod(self): | |
37 self._emit() | |
38 testSuppressMethod.suppress = [util.suppress(message=METHOD_WARNING_MSG)] | |
39 | |
40 def testSuppressClass(self): | |
41 self._emit() | |
42 | |
43 def testOverrideSuppressClass(self): | |
44 self._emit() | |
45 testOverrideSuppressClass.suppress = [] | |
46 | |
47 TestSuppression.suppress = [util.suppress(message=CLASS_WARNING_MSG)] | |
48 | |
49 | |
50 class TestSuppression2(unittest.TestCase, EmitMixin): | |
51 def testSuppressModule(self): | |
52 self._emit() | |
53 | |
54 suppress = [util.suppress(message=MODULE_WARNING_MSG)] | |
55 | |
56 | |
OLD | NEW |