logging working in NewParallel, but changed to be default. Need to figure out how...
[scons.git] / SCons / WarningsTests.py
blobc22b049bdad6a386e26b5209d02e1c22cdc1bfc9
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 import unittest
26 import SCons.Warnings
28 class TestOutput:
29 def __call__(self, x):
30 args = x.args[0]
31 if len(args) == 1:
32 args = args[0]
33 self.out = str(args)
35 class WarningsTestCase(unittest.TestCase):
36 def test_Warning(self):
37 """Test warn function."""
39 # Reset global state
40 SCons.Warnings._enabled = []
41 SCons.Warnings._warningAsException = 0
43 to = TestOutput()
44 SCons.Warnings._warningOut=to
45 SCons.Warnings.enableWarningClass(SCons.Warnings.SConsWarning)
46 SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
47 "Foo")
48 assert to.out == "Foo", to.out
49 SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
50 "Foo", 1)
51 assert to.out == "('Foo', 1)", to.out
53 def test_WarningAsExc(self):
54 """Test warnings as exceptions."""
56 # Reset global state
57 SCons.Warnings._enabled = []
58 SCons.Warnings._warningAsException = 0
60 SCons.Warnings.enableWarningClass(SCons.Warnings.SConsWarning)
61 old = SCons.Warnings.warningAsException()
62 assert old == 0, old
63 exc_caught = 0
64 try:
65 SCons.Warnings.warn(SCons.Warnings.SConsWarning, "Foo")
66 except:
67 exc_caught = 1
68 assert exc_caught == 1
70 old = SCons.Warnings.warningAsException(old)
71 assert old == 1, old
72 exc_caught = 0
73 try:
74 SCons.Warnings.warn(SCons.Warnings.SConsWarning, "Foo")
75 except:
76 exc_caught = 1
77 assert exc_caught == 0
79 def test_Disable(self):
80 """Test disabling/enabling warnings."""
82 # Reset global state
83 SCons.Warnings._enabled = []
84 SCons.Warnings._warningAsException = 0
86 to = TestOutput()
87 SCons.Warnings._warningOut=to
88 to.out = None
90 # No warnings by default
91 SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
92 "Foo")
93 assert to.out is None, to.out
95 SCons.Warnings.enableWarningClass(SCons.Warnings.SConsWarning)
96 SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
97 "Foo")
98 assert to.out == "Foo", to.out
100 to.out = None
101 SCons.Warnings.suppressWarningClass(SCons.Warnings.DeprecatedWarning)
102 SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
103 "Foo")
104 assert to.out is None, to.out
106 SCons.Warnings.warn(SCons.Warnings.MandatoryDeprecatedWarning,
107 "Foo")
108 assert to.out is None, to.out
110 # Dependency warnings should still be enabled though
111 SCons.Warnings.enableWarningClass(SCons.Warnings.SConsWarning)
112 SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
113 "Foo")
114 assert to.out == "Foo", to.out
116 # Try reenabling all warnings...
117 SCons.Warnings.enableWarningClass(SCons.Warnings.SConsWarning)
119 SCons.Warnings.enableWarningClass(SCons.Warnings.SConsWarning)
120 SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
121 "Foo")
122 assert to.out == "Foo", to.out
124 if __name__ == "__main__":
125 unittest.main()
127 # Local Variables:
128 # tab-width:4
129 # indent-tabs-mode:nil
130 # End:
131 # vim: set expandtab tabstop=4 shiftwidth=4: