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 class ErrorsTestCase(unittest
.TestCase
):
30 def test_BuildError(self
):
31 """Test the BuildError exception."""
33 raise SCons
.Errors
.BuildError(
34 errstr
= "foo", status
=57, filename
="file", exc_info
=(1,2,3),
35 node
= "n", executor
="e", action
="a", command
="c")
36 except SCons
.Errors
.BuildError
as e
:
37 assert e
.errstr
== "foo"
39 assert e
.exitstatus
== 2, e
.exitstatus
40 assert e
.filename
== "file"
41 assert e
.exc_info
== (1,2,3)
44 assert e
.executor
== "e"
45 assert e
.action
== "a"
46 assert e
.command
== "c"
49 raise SCons
.Errors
.BuildError("n", "foo", 57, 3, "file",
50 "e", "a", "c", (1,2,3))
51 except SCons
.Errors
.BuildError
as e
:
52 assert e
.errstr
== "foo", e
.errstr
53 assert e
.status
== 57, e
.status
54 assert e
.exitstatus
== 3, e
.exitstatus
55 assert e
.filename
== "file", e
.filename
56 assert e
.exc_info
== (1,2,3), e
.exc_info
59 assert e
.executor
== "e"
60 assert e
.action
== "a"
61 assert e
.command
== "c"
64 raise SCons
.Errors
.BuildError()
65 except SCons
.Errors
.BuildError
as e
:
66 assert e
.errstr
== "Unknown error"
68 assert e
.exitstatus
== 2
69 assert e
.filename
is None
70 assert e
.exc_info
== (None, None, None)
73 assert e
.executor
is None
74 assert e
.action
is None
75 assert e
.command
is None
77 def test_InternalError(self
):
78 """Test the InternalError exception."""
80 raise SCons
.Errors
.InternalError("test internal error")
81 except SCons
.Errors
.InternalError
as e
:
82 assert e
.args
== ("test internal error",)
84 def test_UserError(self
):
85 """Test the UserError exception."""
87 raise SCons
.Errors
.UserError("test user error")
88 except SCons
.Errors
.UserError
as e
:
89 assert e
.args
== ("test user error",)
91 def test_ExplicitExit(self
):
92 """Test the ExplicitExit exception."""
94 raise SCons
.Errors
.ExplicitExit("node")
95 except SCons
.Errors
.ExplicitExit
as e
:
96 assert e
.node
== "node"
98 def test_convert_EnvironmentError_to_BuildError(self
) -> None:
99 """Test convert_to_BuildError on SConsEnvironmentError."""
100 ee
= SCons
.Errors
.SConsEnvironmentError("test env error")
101 be
= SCons
.Errors
.convert_to_BuildError(ee
)
103 self
.assertEqual(be
.errstr
, "test env error")
105 self
.assertEqual(be
.status
, 2)
107 self
.assertEqual(be
.exitstatus
, 2)
109 self
.assertIsNone(be
.filename
)
111 def test_convert_OSError_to_BuildError(self
) -> None:
112 """Test convert_to_BuildError on OSError."""
113 ose
= OSError(7, 'test oserror')
114 be
= SCons
.Errors
.convert_to_BuildError(ose
)
116 self
.assertEqual(be
.errstr
, 'test oserror')
118 self
.assertEqual(be
.status
, 7)
120 self
.assertEqual(be
.exitstatus
, 2)
122 self
.assertIsNone(be
.filename
)
124 def test_convert_phony_OSError_to_BuildError(self
) -> None:
125 """Test convert_to_BuildError on OSError with defaults."""
126 class PhonyException(OSError):
127 def __init__(self
, name
):
128 OSError.__init
__(self
, name
) # most fields will default to None
131 ose
= PhonyException("test oserror")
132 be
= SCons
.Errors
.convert_to_BuildError(ose
)
134 self
.assertEqual(be
.errstr
, 'test oserror')
136 self
.assertEqual(be
.status
, 2)
138 self
.assertEqual(be
.exitstatus
, 2)
140 self
.assertIsNone(be
.filename
)
143 if __name__
== "__main__":
148 # indent-tabs-mode:nil
150 # vim: set expandtab tabstop=4 shiftwidth=4: