1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import string
import sys
import unittest
import SCons.Executor
class MyEnvironment:
def __init__(self, **kw):
self._dict = {}
self._dict.update(kw)
def __getitem__(self, key):
return self._dict[key]
def Override(self, overrides):
d = self._dict.copy()
d.update(overrides)
return apply(MyEnvironment, (), d)
def _update(self, dict):
self._dict.update(dict)
class MyAction:
actions = ['action1', 'action2']
def get_actions(self):
return self.actions
def genstring(self, target, source, env):
return string.join(['GENSTRING'] + self.actions + target + source)
def get_raw_contents(self, target, source, env):
return string.join(['RAW'] + self.actions + target + source)
def get_contents(self, target, source, env):
return string.join(self.actions + target + source)
class MyBuilder:
def __init__(self, env, overrides):
self.env = env
self.overrides = overrides
self.action = MyAction()
class MyNode:
def __init__(self, pre, post):
self.pre_actions = pre
self.post_actions = post
class ExecutorTestCase(unittest.TestCase):
def test__init__(self):
"""Test creating an Executor"""
source_list = ['s1', 's2']
x = SCons.Executor.Executor('b', 'e', 'o', 't', source_list)
assert x.builder == 'b', x.builder
assert x.env == 'e', x.env
assert x.overrides == 'o', x.overrides
assert x.targets == 't', x.targets
source_list.append('s3')
assert x.sources == ['s1', 's2'], x.sources
def test_get_build_env(self):
"""Test fetching and generating a build environment"""
x = SCons.Executor.Executor(MyBuilder('e', {}),
'e',
{},
't',
['s1', 's2'])
x.build_env = 'eee'
be = x.get_build_env()
assert be == 'eee', be
x = SCons.Executor.Executor(MyBuilder('e', {}),
MyEnvironment(X='xxx'),
{'O':'o2'},
't',
['s1', 's2'])
be = x.get_build_env()
assert be['O'] == 'o2', be['O']
assert be['X'] == 'xxx', be['X']
env = MyEnvironment(Y='yyy')
x = SCons.Executor.Executor(MyBuilder(env, {'O':'ob3'}),
None,
{'O':'oo3'},
't',
's')
be = x.get_build_env()
assert be['O'] == 'oo3', be['O']
assert be['Y'] == 'yyy', be['Y']
x = SCons.Executor.Executor(MyBuilder(env, {'O':'ob3'}),
None,
{},
't',
's')
be = x.get_build_env()
assert be['O'] == 'ob3', be['O']
assert be['Y'] == 'yyy', be['Y']
def test_get_action_list(self):
"""Test fetching and generating an action list"""
x = SCons.Executor.Executor('b', 'e', 'o', 't', 's')
x.action_list = ['aaa']
al = x.get_action_list(MyNode([], []))
assert al == ['aaa'], al
al = x.get_action_list(MyNode(['PRE'], ['POST']))
assert al == ['PRE', 'aaa', 'POST'], al
x = SCons.Executor.Executor(MyBuilder('e', 'o'), None, {}, 't', 's')
al = x.get_action_list(MyNode(['pre'], ['post']))
assert al == ['pre', 'action1', 'action2', 'post'], al
def test__call__(self):
"""Test calling an Executor"""
actions = []
env = MyEnvironment(CALL='call')
b = MyBuilder(env, {})
x = SCons.Executor.Executor(b, None, {}, ['t1', 't2'], ['s1', 's2'])
def func(action, target, source, env, a=actions):
a.append(action)
assert target == ['t1', 't2'], target
assert source == ['s1', 's2'], source
assert env['CALL'] == 'call', env['CALL']
x(MyNode(['pre'], ['post']), func)
assert actions == ['pre', 'action1', 'action2', 'post'], actions
def test_cleanup(self):
"""Test cleaning up an Executor"""
x = SCons.Executor.Executor('b', 'e', 'o', 't', ['s1', 's2'])
x.cleanup()
x.build_env = 'eee'
be = x.get_build_env()
assert be == 'eee', be
x.cleanup()
assert not hasattr(x, 'build_env')
def test_add_sources(self):
"""Test adding sources to an Executor"""
x = SCons.Executor.Executor('b', 'e', 'o', 't', ['s1', 's2'])
assert x.sources == ['s1', 's2'], x.sources
x.add_sources(['s1', 's2'])
assert x.sources == ['s1', 's2'], x.sources
x.add_sources(['s3', 's1', 's4'])
assert x.sources == ['s1', 's2', 's3', 's4'], x.sources
def test___str__(self):
"""Test the __str__() method"""
env = MyEnvironment(S='string')
x = SCons.Executor.Executor(MyBuilder(env, {}), None, {}, ['t'], ['s'])
c = str(x)
assert c == 'GENSTRING action1 action2 t s', c
def test_get_raw_contents(self):
"""Test fetching the raw signatures contents"""
env = MyEnvironment(RC='raw contents')
x = SCons.Executor.Executor(MyBuilder(env, {}), None, {}, ['t'], ['s'])
x.raw_contents = 'raw raw raw'
rc = x.get_raw_contents()
assert rc == 'raw raw raw', rc
x = SCons.Executor.Executor(MyBuilder(env, {}), None, {}, ['t'], ['s'])
rc = x.get_raw_contents()
assert rc == 'RAW action1 action2 t s', rc
def test_get_contents(self):
"""Test fetching the signatures contents"""
env = MyEnvironment(C='contents')
x = SCons.Executor.Executor(MyBuilder(env, {}), None, {}, ['t'], ['s'])
x.contents = 'contents'
c = x.get_contents()
assert c == 'contents', c
x = SCons.Executor.Executor(MyBuilder(env, {}), None, {}, ['t'], ['s'])
c = x.get_contents()
assert c == 'action1 action2 t s', c
def test_get_timetstamp(self):
"""Test fetching the "timestamp" """
x = SCons.Executor.Executor('b', 'e', 'o', 't', ['s1', 's2'])
ts = x.get_timestamp()
assert ts == 0, ts
if __name__ == "__main__":
suite = unittest.TestSuite()
tclasses = [ ExecutorTestCase ]
for tclass in tclasses:
names = unittest.getTestCaseNames(tclass, 'test_')
suite.addTests(map(tclass, names))
if not unittest.TextTestRunner().run(suite).wasSuccessful():
sys.exit(1)
|