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.
29 def __call__(self
, x
):
35 class WarningsTestCase(unittest
.TestCase
):
36 def test_Warning(self
):
37 """Test warn function."""
40 SCons
.Warnings
._enabled
= []
41 SCons
.Warnings
._warningAsException
= 0
44 SCons
.Warnings
._warningOut
=to
45 SCons
.Warnings
.enableWarningClass(SCons
.Warnings
.SConsWarning
)
46 SCons
.Warnings
.warn(SCons
.Warnings
.DeprecatedWarning
,
48 assert to
.out
== "Foo", to
.out
49 SCons
.Warnings
.warn(SCons
.Warnings
.DependencyWarning
,
51 assert to
.out
== "('Foo', 1)", to
.out
53 def test_WarningAsExc(self
):
54 """Test warnings as exceptions."""
57 SCons
.Warnings
._enabled
= []
58 SCons
.Warnings
._warningAsException
= 0
60 SCons
.Warnings
.enableWarningClass(SCons
.Warnings
.SConsWarning
)
61 old
= SCons
.Warnings
.warningAsException()
65 SCons
.Warnings
.warn(SCons
.Warnings
.SConsWarning
, "Foo")
68 assert exc_caught
== 1
70 old
= SCons
.Warnings
.warningAsException(old
)
74 SCons
.Warnings
.warn(SCons
.Warnings
.SConsWarning
, "Foo")
77 assert exc_caught
== 0
79 def test_Disable(self
):
80 """Test disabling/enabling warnings."""
83 SCons
.Warnings
._enabled
= []
84 SCons
.Warnings
._warningAsException
= 0
87 SCons
.Warnings
._warningOut
=to
90 # No warnings by default
91 SCons
.Warnings
.warn(SCons
.Warnings
.DeprecatedWarning
,
93 assert to
.out
is None, to
.out
95 SCons
.Warnings
.enableWarningClass(SCons
.Warnings
.SConsWarning
)
96 SCons
.Warnings
.warn(SCons
.Warnings
.DeprecatedWarning
,
98 assert to
.out
== "Foo", to
.out
101 SCons
.Warnings
.suppressWarningClass(SCons
.Warnings
.DeprecatedWarning
)
102 SCons
.Warnings
.warn(SCons
.Warnings
.DeprecatedWarning
,
104 assert to
.out
is None, to
.out
106 SCons
.Warnings
.warn(SCons
.Warnings
.MandatoryDeprecatedWarning
,
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
,
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
,
122 assert to
.out
== "Foo", to
.out
124 if __name__
== "__main__":
129 # indent-tabs-mode:nil
131 # vim: set expandtab tabstop=4 shiftwidth=4: