summaryrefslogtreecommitdiff
path: root/src/engine/SCons/BuilderTests.py
diff options
context:
space:
mode:
authorLuca Falavigna <dktrkranz@debian.org>2010-06-15 14:28:22 +0000
committerLuca Falavigna <dktrkranz@debian.org>2010-06-15 14:28:22 +0000
commit738149c9bfb9965d013d01ef99f9bb1c2819e7e8 (patch)
tree0397d9bf3b12c903dc73419585df231397ff343c /src/engine/SCons/BuilderTests.py
parente7885e3af440eaef38a9301fd92a105afc8ddebb (diff)
Imported Upstream version 2.0.0upstream/2.0.0
Diffstat (limited to 'src/engine/SCons/BuilderTests.py')
-rw-r--r--src/engine/SCons/BuilderTests.py203
1 files changed, 96 insertions, 107 deletions
diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py
index 4ccded6..a2f8caa 100644
--- a/src/engine/SCons/BuilderTests.py
+++ b/src/engine/SCons/BuilderTests.py
@@ -21,7 +21,9 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/BuilderTests.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/BuilderTests.py 5023 2010/06/14 22:05:46 scons"
+
+import SCons.compat
# Define a null function for use as a builder action.
# Where this is defined in the file seems to affect its
@@ -30,13 +32,12 @@ __revision__ = "src/engine/SCons/BuilderTests.py 4720 2010/03/24 03:14:11 jars"
def Func():
pass
+import collections
+import io
import os.path
import re
import sys
-import types
-import StringIO
import unittest
-import UserList
import TestCmd
@@ -47,7 +48,7 @@ import SCons.Errors
import SCons.Subst
import SCons.Util
-sys.stdout = StringIO.StringIO()
+sys.stdout = io.StringIO()
# Initial setup of the common environment for all tests,
# a temporary working directory containing a
@@ -70,7 +71,7 @@ scons_env = SCons.Environment.Environment()
env_arg2nodes_called = None
-class Environment:
+class Environment(object):
def __init__(self, **kw):
self.d = {}
self.d['SHELL'] = scons_env['SHELL']
@@ -118,21 +119,23 @@ class Environment:
self.d[item] = var
def __getitem__(self, item):
return self.d[item]
+ def __contains__(self, item):
+ return self.d.__contains__(item)
def has_key(self, item):
- return self.d.has_key(item)
+ return item in self.d
def keys(self):
- return self.d.keys()
+ return list(self.d.keys())
def get(self, key, value=None):
return self.d.get(key, value)
def Override(self, overrides):
- env = apply(Environment, (), self.d)
+ env = Environment(**self.d)
env.d.update(overrides)
env.scanner = self.scanner
return env
def _update(self, dict):
self.d.update(dict)
def items(self):
- return self.d.items()
+ return list(self.d.items())
def sig_dict(self):
d = {}
for k,v in self.items(): d[k] = v
@@ -144,7 +147,7 @@ class Environment:
def __cmp__(self, other):
return cmp(self.scanner, other.scanner) or cmp(self.d, other.d)
-class MyAction:
+class MyAction(object):
def __init__(self, action):
self.action = action
def __call__(self, *args, **kw):
@@ -152,7 +155,7 @@ class MyAction:
def get_executor(self, env, overrides, tlist, slist, executor_kw):
return ['executor'] + [self.action]
-class MyNode_without_target_from_source:
+class MyNode_without_target_from_source(object):
def __init__(self, name):
self.name = name
self.sources = []
@@ -215,7 +218,7 @@ class BuilderTestCase(unittest.TestCase):
exc_caught = 1
assert exc_caught, "did not catch expected InternalError exception"
- class Node:
+ class Node(object):
pass
n = Node()
@@ -250,12 +253,12 @@ class BuilderTestCase(unittest.TestCase):
assert not hasattr(n2, 'env')
l = [1]
- ul = UserList.UserList([2])
+ ul = collections.UserList([2])
try:
l.extend(ul)
except TypeError:
def mystr(l):
- return str(map(str, l))
+ return str(list(map(str, l)))
else:
mystr = str
@@ -264,14 +267,14 @@ class BuilderTestCase(unittest.TestCase):
tlist = builder(env, target = [nnn1, nnn2], source = [])
s = mystr(tlist)
assert s == "['nnn1', 'nnn2']", s
- l = map(str, tlist)
+ l = list(map(str, tlist))
assert l == ['nnn1', 'nnn2'], l
tlist = builder(env, target = 'n3', source = 'n4')
s = mystr(tlist)
assert s == "['n3']", s
target = tlist[0]
- l = map(str, tlist)
+ l = list(map(str, tlist))
assert l == ['n3'], l
assert target.name == 'n3'
assert target.sources[0].name == 'n4'
@@ -279,7 +282,7 @@ class BuilderTestCase(unittest.TestCase):
tlist = builder(env, target = 'n4 n5', source = ['n6 n7'])
s = mystr(tlist)
assert s == "['n4 n5']", s
- l = map(str, tlist)
+ l = list(map(str, tlist))
assert l == ['n4 n5'], l
target = tlist[0]
assert target.name == 'n4 n5'
@@ -288,7 +291,7 @@ class BuilderTestCase(unittest.TestCase):
tlist = builder(env, target = ['n8 n9'], source = 'n10 n11')
s = mystr(tlist)
assert s == "['n8 n9']", s
- l = map(str, tlist)
+ l = list(map(str, tlist))
assert l == ['n8 n9'], l
target = tlist[0]
assert target.name == 'n8 n9'
@@ -302,7 +305,8 @@ class BuilderTestCase(unittest.TestCase):
#be = target.get_build_env()
#assert be['VAR'] == 'foo', be['VAR']
- if not hasattr(types, 'UnicodeType'):
+ try: unicode
+ except NameError:
uni = str
else:
uni = unicode
@@ -340,7 +344,7 @@ class BuilderTestCase(unittest.TestCase):
except SCons.Errors.UserError, e:
pass
else:
- raise "Did not catch expected UserError."
+ raise Exception("Did not catch expected UserError.")
builder = SCons.Builder.Builder(action="foo")
target = builder(env, None, source='n22', srcdir='src_dir')[0]
@@ -419,7 +423,7 @@ class BuilderTestCase(unittest.TestCase):
def test_target_factory(self):
"""Test a Builder that creates target nodes of a specified class
"""
- class Foo:
+ class Foo(object):
pass
def FooFactory(target):
global Foo
@@ -431,7 +435,7 @@ class BuilderTestCase(unittest.TestCase):
def test_source_factory(self):
"""Test a Builder that creates source nodes of a specified class
"""
- class Foo:
+ class Foo(object):
pass
def FooFactory(source):
global Foo
@@ -564,13 +568,11 @@ class BuilderTestCase(unittest.TestCase):
"Unexpected tgt.sources[0] name: %s" % tgt.sources[0].path
b2 = SCons.Builder.Builder(src_suffix = '.2', src_builder = b1)
- r = b2.src_suffixes(env)
- r.sort()
+ r = sorted(b2.src_suffixes(env))
assert r == ['.2', '.c'], r
b3 = SCons.Builder.Builder(action = {'.3a' : '', '.3b' : ''})
- s = b3.src_suffixes(env)
- s.sort()
+ s = sorted(b3.src_suffixes(env))
assert s == ['.3a', '.3b'], s
b4 = SCons.Builder.Builder(src_suffix = '$XSUFFIX')
@@ -618,7 +620,7 @@ class BuilderTestCase(unittest.TestCase):
src_suffix='.obj',
suffix='.exe')
tgt = b2(env, target=None, source=['foo$OBJSUFFIX'])
- s = map(str, tgt[0].sources)
+ s = list(map(str, tgt[0].sources))
assert s == ['foo.obj'], s
def test_suffix(self):
@@ -704,21 +706,10 @@ class BuilderTestCase(unittest.TestCase):
tgt.build()
assert env['CNT'][0] == 2
tgts = builder(env, None, infiles[2:4])
- try:
- [].extend(UserList.UserList())
- except TypeError:
- # Old Python version (1.5.2) that can't handle extending
- # a list with list-like objects. That means the return
- # value from the builder call is a real list with Nodes,
- # and doesn't have a __str__() method that stringifies
- # the individual elements. Since we're gong to drop 1.5.2
- # support anyway, don't bother trying to test for it.
- pass
- else:
- s = map(str, tgts)
- expect = [test.workpath('2.out'), test.workpath('3.out')]
- expect = map(os.path.normcase, expect)
- assert map(os.path.normcase, s) == expect, s
+ s = list(map(str, tgts))
+ expect = [test.workpath('2.out'), test.workpath('3.out')]
+ expect = list(map(os.path.normcase, expect))
+ assert list(map(os.path.normcase, s)) == expect, s
for t in tgts: t.prepare()
tgts[0].build()
tgts[1].build()
@@ -744,7 +735,7 @@ class BuilderTestCase(unittest.TestCase):
for t in target:
open(str(t), 'w').write("function2\n")
for t in tlist:
- if not t in map(str, target):
+ if not t in list(map(str, target)):
open(t, 'w').write("function2\n")
return 1
@@ -773,7 +764,7 @@ class BuilderTestCase(unittest.TestCase):
for t in target:
open(str(t), 'w').write("function3\n")
for t in tlist:
- if not t in map(str, target):
+ if not t in list(map(str, target)):
open(t, 'w').write("function3\n")
return 1
@@ -811,17 +802,17 @@ class BuilderTestCase(unittest.TestCase):
tgt = builder2(env, target='baz', source=sources)[0]
s = str(tgt)
assert s == 'baz', s
- s = map(str, tgt.sources)
+ s = list(map(str, tgt.sources))
assert s == ['test.foo', 'test2.foo', 'test3.txt', 'test4.foo'], s
- s = map(str, tgt.sources[0].sources)
+ s = list(map(str, tgt.sources[0].sources))
assert s == ['test.bar'], s
tgt = builder2(env, None, 'aaa.bar')[0]
s = str(tgt)
assert s == 'aaa', s
- s = map(str, tgt.sources)
+ s = list(map(str, tgt.sources))
assert s == ['aaa.foo'], s
- s = map(str, tgt.sources[0].sources)
+ s = list(map(str, tgt.sources[0].sources))
assert s == ['aaa.bar'], s
builder3 = SCons.Builder.Builder(action='bld3')
@@ -841,17 +832,17 @@ class BuilderTestCase(unittest.TestCase):
tgt = builder6(env, 'test', 'test.i')[0]
s = str(tgt)
assert s == 'test.exe', s
- s = map(str, tgt.sources)
+ s = list(map(str, tgt.sources))
assert s == ['test_wrap.obj'], s
- s = map(str, tgt.sources[0].sources)
+ s = list(map(str, tgt.sources[0].sources))
assert s == ['test_wrap.c'], s
- s = map(str, tgt.sources[0].sources[0].sources)
+ s = list(map(str, tgt.sources[0].sources[0].sources))
assert s == ['test.i'], s
def test_target_scanner(self):
"""Testing ability to set target and source scanners through a builder."""
global instanced
- class TestScanner:
+ class TestScanner(object):
pass
tscan = TestScanner()
sscan = TestScanner()
@@ -893,7 +884,7 @@ class BuilderTestCase(unittest.TestCase):
def test_src_scanner(slf):
"""Testing ability to set a source file scanner through a builder."""
- class TestScanner:
+ class TestScanner(object):
def key(self, env):
return 'TestScannerkey'
def instance(self, env):
@@ -922,7 +913,7 @@ class BuilderTestCase(unittest.TestCase):
# An Environment that has suffix-specified SCANNERS should
# provide a source scanner to the target.
- class EnvTestScanner:
+ class EnvTestScanner(object):
def key(self, env):
return '.y'
def instance(self, env):
@@ -1030,8 +1021,7 @@ class BuilderTestCase(unittest.TestCase):
bld.set_src_suffix(['.bar', '.foo'])
r = bld.get_src_suffix(env)
assert r == '.bar', r
- r = bld.src_suffixes(env)
- r.sort()
+ r = sorted(bld.src_suffixes(env))
assert r == ['.bar', '.foo'], r
# adjust_suffix normalizes the suffix, adding a `.' if needed
@@ -1151,8 +1141,7 @@ class BuilderTestCase(unittest.TestCase):
assert r is None, r
r = builder.get_src_suffix(env)
assert r == '.src_sfx1', r
- r = builder.src_suffixes(env)
- r.sort()
+ r = sorted(builder.src_suffixes(env))
assert r == ['.src_sfx1', '.src_sfx2'], r
@@ -1198,14 +1187,14 @@ class BuilderTestCase(unittest.TestCase):
tgt = builder(env, target='foo3', source='bar', foo=1)
assert len(tgt) == 2, len(tgt)
- assert 'foo3' in map(str, tgt), map(str, tgt)
- assert 'bar1' in map(str, tgt), map(str, tgt)
+ assert 'foo3' in list(map(str, tgt)), list(map(str, tgt))
+ assert 'bar1' in list(map(str, tgt)), list(map(str, tgt))
tgt = builder(env, target='foo4', source='bar', bar=1)[0]
assert str(tgt) == 'foo4', str(tgt)
assert len(tgt.sources) == 2, len(tgt.sources)
- assert 'baz' in map(str, tgt.sources), map(str, tgt.sources)
- assert 'bar' in map(str, tgt.sources), map(str, tgt.sources)
+ assert 'baz' in list(map(str, tgt.sources)), list(map(str, tgt.sources))
+ assert 'bar' in list(map(str, tgt.sources)), list(map(str, tgt.sources))
env2=Environment(FOO=emit)
builder2=SCons.Builder.Builder(action='foo',
@@ -1226,14 +1215,14 @@ class BuilderTestCase(unittest.TestCase):
tgt = builder2(env2, target='foo6', source='bar', foo=2)
assert len(tgt) == 2, len(tgt)
- assert 'foo6' in map(str, tgt), map(str, tgt)
- assert 'bar2' in map(str, tgt), map(str, tgt)
+ assert 'foo6' in list(map(str, tgt)), list(map(str, tgt))
+ assert 'bar2' in list(map(str, tgt)), list(map(str, tgt))
tgt = builder2(env2, target='foo7', source='bar', bar=1)[0]
assert str(tgt) == 'foo7', str(tgt)
assert len(tgt.sources) == 2, len(tgt.sources)
- assert 'baz' in map(str, tgt.sources), map(str, tgt.sources)
- assert 'bar' in map(str, tgt.sources), map(str, tgt.sources)
+ assert 'baz' in list(map(str, tgt.sources)), list(map(str, tgt.sources))
+ assert 'bar' in list(map(str, tgt.sources)), list(map(str, tgt.sources))
def test_emitter_preserve_builder(self):
"""Test an emitter not overwriting a newly-set builder"""
@@ -1262,12 +1251,12 @@ class BuilderTestCase(unittest.TestCase):
env = Environment()
def emit4a(target, source, env):
- source = map(str, source)
- target = map(lambda x: 'emit4a-' + x[:-3], source)
+ source = list(map(str, source))
+ target = ['emit4a-' + x[:-3] for x in source]
return (target, source)
def emit4b(target, source, env):
- source = map(str, source)
- target = map(lambda x: 'emit4b-' + x[:-3], source)
+ source = list(map(str, source))
+ target = ['emit4b-' + x[:-3] for x in source]
return (target, source)
builder = SCons.Builder.Builder(action='foo',
@@ -1283,8 +1272,8 @@ class BuilderTestCase(unittest.TestCase):
assert str(tgt) == 'ccc', str(tgt)
def emit4c(target, source, env):
- source = map(str, source)
- target = map(lambda x: 'emit4c-' + x[:-3], source)
+ source = list(map(str, source))
+ target = ['emit4c-' + x[:-3] for x in source]
return (target, source)
builder.add_emitter('.4c', emit4c)
@@ -1296,29 +1285,29 @@ class BuilderTestCase(unittest.TestCase):
env = Environment()
def emit1a(target, source, env):
- source = map(str, source)
- target = target + map(lambda x: 'emit1a-' + x[:-2], source)
+ source = list(map(str, source))
+ target = target + ['emit1a-' + x[:-2] for x in source]
return (target, source)
def emit1b(target, source, env):
- source = map(str, source)
- target = target + map(lambda x: 'emit1b-' + x[:-2], source)
+ source = list(map(str, source))
+ target = target + ['emit1b-' + x[:-2] for x in source]
return (target, source)
builder1 = SCons.Builder.Builder(action='foo',
emitter=[emit1a, emit1b],
node_factory=MyNode)
tgts = builder1(env, target='target-1', source='aaa.1')
- tgts = map(str, tgts)
+ tgts = list(map(str, tgts))
assert tgts == ['target-1', 'emit1a-aaa', 'emit1b-aaa'], tgts
# Test a list of emitter functions through the environment.
def emit2a(target, source, env):
- source = map(str, source)
- target = target + map(lambda x: 'emit2a-' + x[:-2], source)
+ source = list(map(str, source))
+ target = target + ['emit2a-' + x[:-2] for x in source]
return (target, source)
def emit2b(target, source, env):
- source = map(str, source)
- target = target + map(lambda x: 'emit2b-' + x[:-2], source)
+ source = list(map(str, source))
+ target = target + ['emit2b-' + x[:-2] for x in source]
return (target, source)
builder2 = SCons.Builder.Builder(action='foo',
emitter='$EMITTERLIST',
@@ -1327,7 +1316,7 @@ class BuilderTestCase(unittest.TestCase):
env = Environment(EMITTERLIST = [emit2a, emit2b])
tgts = builder2(env, target='target-2', source='aaa.2')
- tgts = map(str, tgts)
+ tgts = list(map(str, tgts))
assert tgts == ['target-2', 'emit2a-aaa', 'emit2b-aaa'], tgts
def test_emitter_TARGET_SOURCE(self):
@@ -1345,8 +1334,8 @@ class BuilderTestCase(unittest.TestCase):
targets = builder(env, target = 'TTT', source ='SSS')
sources = targets[0].sources
- targets = map(str, targets)
- sources = map(str, sources)
+ targets = list(map(str, targets))
+ sources = list(map(str, sources))
assert targets == ['TTT', 'SSS.s1', 'TTT.t1'], targets
assert sources == ['SSS', 'TTT.t2', 'SSS.s2'], targets
@@ -1358,53 +1347,53 @@ class BuilderTestCase(unittest.TestCase):
tgt = b(env, None, 'aaa')[0]
assert str(tgt) == 'aaa.o', str(tgt)
- assert len(tgt.sources) == 1, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'aaa', map(str, tgt.sources)
+ assert len(tgt.sources) == 1, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'aaa', list(map(str, tgt.sources))
tgt = b(env, None, 'bbb.c')[0]
assert str(tgt) == 'bbb.o', str(tgt)
- assert len(tgt.sources) == 1, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'bbb.c', map(str, tgt.sources)
+ assert len(tgt.sources) == 1, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'bbb.c', list(map(str, tgt.sources))
tgt = b(env, None, 'ccc.x.c')[0]
assert str(tgt) == 'ccc.x.o', str(tgt)
- assert len(tgt.sources) == 1, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'ccc.x.c', map(str, tgt.sources)
+ assert len(tgt.sources) == 1, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'ccc.x.c', list(map(str, tgt.sources))
tgt = b(env, None, ['d0.c', 'd1.c'])[0]
assert str(tgt) == 'd0.o', str(tgt)
- assert len(tgt.sources) == 2, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'd0.c', map(str, tgt.sources)
- assert str(tgt.sources[1]) == 'd1.c', map(str, tgt.sources)
+ assert len(tgt.sources) == 2, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'd0.c', list(map(str, tgt.sources))
+ assert str(tgt.sources[1]) == 'd1.c', list(map(str, tgt.sources))
tgt = b(env, target = None, source='eee')[0]
assert str(tgt) == 'eee.o', str(tgt)
- assert len(tgt.sources) == 1, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'eee', map(str, tgt.sources)
+ assert len(tgt.sources) == 1, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'eee', list(map(str, tgt.sources))
tgt = b(env, target = None, source='fff.c')[0]
assert str(tgt) == 'fff.o', str(tgt)
- assert len(tgt.sources) == 1, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'fff.c', map(str, tgt.sources)
+ assert len(tgt.sources) == 1, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'fff.c', list(map(str, tgt.sources))
tgt = b(env, target = None, source='ggg.x.c')[0]
assert str(tgt) == 'ggg.x.o', str(tgt)
- assert len(tgt.sources) == 1, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'ggg.x.c', map(str, tgt.sources)
+ assert len(tgt.sources) == 1, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'ggg.x.c', list(map(str, tgt.sources))
tgt = b(env, target = None, source=['h0.c', 'h1.c'])[0]
assert str(tgt) == 'h0.o', str(tgt)
- assert len(tgt.sources) == 2, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'h0.c', map(str, tgt.sources)
- assert str(tgt.sources[1]) == 'h1.c', map(str, tgt.sources)
+ assert len(tgt.sources) == 2, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'h0.c', list(map(str, tgt.sources))
+ assert str(tgt.sources[1]) == 'h1.c', list(map(str, tgt.sources))
w = b(env, target='i0.w', source=['i0.x'])[0]
y = b(env, target='i1.y', source=['i1.z'])[0]
tgt = b(env, None, source=[w, y])[0]
assert str(tgt) == 'i0.o', str(tgt)
- assert len(tgt.sources) == 2, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'i0.w', map(str, tgt.sources)
- assert str(tgt.sources[1]) == 'i1.y', map(str, tgt.sources)
+ assert len(tgt.sources) == 2, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'i0.w', list(map(str, tgt.sources))
+ assert str(tgt.sources[1]) == 'i1.y', list(map(str, tgt.sources))
def test_get_name(self):
"""Test getting name of builder.
@@ -1642,7 +1631,7 @@ if __name__ == "__main__":
]
for tclass in tclasses:
names = unittest.getTestCaseNames(tclass, 'test_')
- suite.addTests(map(tclass, names))
+ suite.addTests(list(map(tclass, names)))
if not unittest.TextTestRunner().run(suite).wasSuccessful():
sys.exit(1)