import copy
import os
-import string
import StringIO
import sys
import TestCmd
keys = d.keys()
keys.sort()
for k in keys:
- if env1.has_key(k):
- if env2.has_key(k):
+ if k in env1:
+ if k in env2:
if env1[k] != env2[k]:
s1 = s1 + " " + repr(k) + " : " + repr(env1[k]) + "\n"
s2 = s2 + " " + repr(k) + " : " + repr(env2[k]) + "\n"
else:
s1 = s1 + " " + repr(k) + " : " + repr(env1[k]) + "\n"
- elif env2.has_key(k):
+ elif k in env2:
s2 = s2 + " " + repr(k) + " : " + repr(env2[k]) + "\n"
s1 = s1 + "}\n"
s2 = s2 + "}\n"
keys = d.keys()
keys.sort()
for k in keys:
- if d1.has_key(k):
- if d2.has_key(k):
+ if k in d1:
+ if k in d2:
if d1[k] != d2[k]:
s1 = s1 + " " + repr(k) + " : " + repr(d1[k]) + "\n"
s2 = s2 + " " + repr(k) + " : " + repr(d2[k]) + "\n"
else:
s1 = s1 + " " + repr(k) + " : " + repr(d1[k]) + "\n"
- elif env2.has_key(k):
+ elif k in env2:
s2 = s2 + " " + repr(k) + " : " + repr(d2[k]) + "\n"
s1 = s1 + "}\n"
s2 = s2 + "}\n"
called_it = {}
built_it = {}
-class Builder:
+class Builder(SCons.Builder.BuilderBase):
"""A dummy Builder class for testing purposes. "Building"
a target is simply setting a value in the dictionary.
"""
class CLVar(UserList.UserList):
def __init__(self, seq):
if type(seq) == type(''):
- seq = string.split(seq)
+ seq = seq.split()
UserList.UserList.__init__(self, seq)
+ def __add__(self, other):
+ return UserList.UserList.__add__(self, CLVar(other))
+ def __radd__(self, other):
+ return UserList.UserList.__radd__(self, CLVar(other))
def __coerce__(self, other):
return (self, CLVar(other))
class TestEnvironmentFixture:
def TestEnvironment(self, *args, **kw):
- if not kw or not kw.has_key('tools'):
+ if not kw or 'tools' not in kw:
kw['tools'] = [test_tool]
default_keys = { 'CC' : 'cc',
'CCFLAGS' : '-DNDEBUG',
'ENV' : { 'TMP' : '/tmp' } }
for key, value in default_keys.items():
- if not kw.has_key(key):
+ if key not in kw:
kw[key] = value
- if not kw.has_key('BUILDERS'):
+ if 'BUILDERS' not in kw:
static_obj = SCons.Builder.Builder(action = {},
emitter = {},
suffix = '.o',
single_source = 1)
kw['BUILDERS'] = {'Object' : static_obj}
+ static_obj.add_action('.cpp', 'fake action')
- env = apply(Environment, args, kw)
+ env = Environment(*args, **kw)
return env
class SubstitutionTestCase(unittest.TestCase):
"""Test initializing a SubstitutionEnvironment
"""
env = SubstitutionEnvironment()
- assert not env.has_key('__env__')
+ assert '__env__' not in env
def test___cmp__(self):
"""Test comparing SubstitutionEnvironments
"""Test the SubstitutionEnvironment has_key() method
"""
env = SubstitutionEnvironment(XXX = 'x')
- assert env.has_key('XXX')
- assert not env.has_key('YYY')
+ assert 'XXX' in env
+ assert 'YYY' not in env
+
+ def test_contains(self):
+ """Test the SubstitutionEnvironment __contains__() method
+ """
+ try:
+ 'x' in {'x':1}
+ except TypeError:
+ # TODO(1.5)
+ # An early version of Python that doesn't support "in"
+ # on dictionaries. Just pass the test.
+ pass
+ else:
+ env = SubstitutionEnvironment(XXX = 'x')
+ assert 'XXX' in env
+ assert not 'YYY' in env
def test_items(self):
"""Test the SubstitutionEnvironment items() method
class X(SCons.Node.Node):
pass
def Factory(name, directory = None, create = 1, dict=dict, X=X):
- if not dict.has_key(name):
+ if name not in dict:
dict[name] = X()
dict[name].name = name
return dict[name]
DummyNode,
target=targets,
source=sources)
- names = map(lambda n: n.name, nodes)
+ names = [n.name for n in nodes]
assert names == ['t1-a', 's1-b', 't2-c', 's2-d'], names
def test_gvars(self):
return self.val
class MyObj:
- pass
+ def get(self):
+ return self
- env = SubstitutionEnvironment(FOO='foo', BAR='bar', PROXY=MyProxy('my1'))
+ env = SubstitutionEnvironment(FOO='foo',
+ BAR='bar',
+ LIST=['one', 'two'],
+ PROXY=MyProxy('my1'))
r = env.subst_path('$FOO')
assert r == ['foo'], r
r = env.subst_path(['$FOO', 'xxx', '$BAR'])
assert r == ['foo', 'xxx', 'bar'], r
+ r = env.subst_path(['$FOO', '$LIST', '$BAR'])
+ assert list(map(str, r)) == ['foo', 'one two', 'bar'], r
+
r = env.subst_path(['$FOO', '$TARGET', '$SOURCE', '$BAR'])
assert r == ['foo', '', '', 'bar'], r
r = env.subst_path(['$FOO', '$TARGET', '$BAR'], target=MyNode('ttt'))
- assert map(str, r) == ['foo', 'ttt', 'bar'], r
+ assert list(map(str, r)) == ['foo', 'ttt', 'bar'], r
r = env.subst_path(['$FOO', '$SOURCE', '$BAR'], source=MyNode('sss'))
- assert map(str, r) == ['foo', 'sss', 'bar'], r
+ assert list(map(str, r)) == ['foo', 'sss', 'bar'], r
n = MyObj()
BAR=StringableObj("bar"))
r = env.subst_path([ "${FOO}/bar", "${BAR}/baz" ])
- assert r == [ "foo/bar", "bar/baz" ]
+ assert r == [ "foo/bar", "bar/baz" ], r
r = env.subst_path([ "bar/${FOO}", "baz/${BAR}" ])
- assert r == [ "bar/foo", "baz/bar" ]
+ assert r == [ "bar/foo", "baz/bar" ], r
r = env.subst_path([ "bar/${FOO}/bar", "baz/${BAR}/baz" ])
- assert r == [ "bar/foo/bar", "baz/bar/baz" ]
+ assert r == [ "bar/foo/bar", "baz/bar/baz" ], r
def test_subst_target_source(self):
"""Test the base environment subst_target_source() method"""
test.write('fail.py', """\
import sys
sys.exit(1)
+""")
+ test.write('echo.py', """\
+import os, sys
+sys.stdout.write(os.environ['ECHO'] + '\\n')
+sys.exit(0)
""")
save_stderr = sys.stderr
python = '"' + sys.executable + '"'
try:
+ sys.stderr = StringIO.StringIO()
cmd = '%s %s' % (python, test.workpath('stdout.py'))
output = env.backtick(cmd)
-
+ errout = sys.stderr.getvalue()
assert output == 'this came from stdout.py\n', output
+ assert errout == '', errout
sys.stderr = StringIO.StringIO()
-
cmd = '%s %s' % (python, test.workpath('stderr.py'))
output = env.backtick(cmd)
errout = sys.stderr.getvalue()
-
assert output == '', output
assert errout == 'this came from stderr.py\n', errout
sys.stderr = StringIO.StringIO()
-
cmd = '%s %s' % (python, test.workpath('fail.py'))
try:
env.backtick(cmd)
else:
self.fail("did not catch expected OSError")
+ sys.stderr = StringIO.StringIO()
+ cmd = '%s %s' % (python, test.workpath('echo.py'))
+ env['ENV'] = os.environ.copy()
+ env['ENV']['ECHO'] = 'this came from ECHO'
+ output = env.backtick(cmd)
+ errout = sys.stderr.getvalue()
+ assert output == 'this came from ECHO\n', output
+ assert errout == '', errout
+
finally:
sys.stderr = save_stderr
r = env.func('-yyy')
assert r == 'func2-foo-yyy', r
+ # Test that clones of clones correctly re-bind added methods.
+ env1 = Environment(FOO = '1')
+ env1.AddMethod(func2)
+ env2 = env1.Clone(FOO = '2')
+ env3 = env2.Clone(FOO = '3')
+ env4 = env3.Clone(FOO = '4')
+ r = env1.func2()
+ assert r == 'func2-1', r
+ r = env2.func2()
+ assert r == 'func2-2', r
+ r = env3.func2()
+ assert r == 'func2-3', r
+ r = env4.func2()
+ assert r == 'func2-4', r
+
+ # Test that clones don't re-bind an attribute that the user
+ env1 = Environment(FOO = '1')
+ env1.AddMethod(func2)
+ def replace_func2():
+ return 'replace_func2'
+ env1.func2 = replace_func2
+ env2 = env1.Clone(FOO = '2')
+ r = env2.func2()
+ assert r == 'replace_func2', r
+
def test_Override(self):
"Test overriding construction variables"
env = SubstitutionEnvironment(ONE=1, TWO=2, THREE=3, FOUR=4)
assert d == empty, d
s = "-I/usr/include/fum -I bar -X\n" + \
+ '-I"C:\\Program Files\\ASCEND\\include" ' + \
"-L/usr/fax -L foo -lxxx -l yyy " + \
+ '-L"C:\\Program Files\\ASCEND" -lascend ' + \
"-Wa,-as -Wl,-link " + \
"-Wl,-rpath=rpath1 " + \
"-Wl,-R,rpath2 " + \
"-pthread " + \
"-mno-cygwin -mwindows " + \
"-arch i386 -isysroot /tmp +DD64 " + \
- "-DFOO -DBAR=value -D BAZ"
+ "-DFOO -DBAR=value -D BAZ "
d = env.ParseFlags(s)
'+DD64'], d['CCFLAGS']
assert d['CPPDEFINES'] == ['FOO', ['BAR', 'value'], 'BAZ'], d['CPPDEFINES']
assert d['CPPFLAGS'] == ['-Wp,-cpp'], d['CPPFLAGS']
- assert d['CPPPATH'] == ['/usr/include/fum', 'bar'], d['CPPPATH']
+ assert d['CPPPATH'] == ['/usr/include/fum',
+ 'bar',
+ 'C:\\Program Files\\ASCEND\\include'], d['CPPPATH']
assert d['FRAMEWORKPATH'] == ['fwd1', 'fwd2', 'fwd3'], d['FRAMEWORKPATH']
assert d['FRAMEWORKS'] == ['Carbon'], d['FRAMEWORKS']
- assert d['LIBPATH'] == ['/usr/fax', 'foo'], d['LIBPATH']
- assert d['LIBS'] == ['xxx', 'yyy'], d['LIBS']
+ assert d['LIBPATH'] == ['/usr/fax',
+ 'foo',
+ 'C:\\Program Files\\ASCEND'], d['LIBPATH']
+ LIBS = list(map(str, d['LIBS']))
+ assert LIBS == ['xxx', 'yyy', 'ascend'], (d['LIBS'], LIBS)
assert d['LINKFLAGS'] == ['-Wl,-link', '-pthread',
'-mno-cygwin', '-mwindows',
('-arch', 'i386'),
"""
env = SubstitutionEnvironment()
env.MergeFlags('')
- assert not env.has_key('CCFLAGS'), env['CCFLAGS']
+ assert 'CCFLAGS' not in env, env['CCFLAGS']
env.MergeFlags('-X')
assert env['CCFLAGS'] == ['-X'], env['CCFLAGS']
env.MergeFlags('-X')
assert env['A'] == ['aaa'], env['A']
assert env['B'] == ['bbb'], env['B']
+# def test_MergeShellPaths(self):
+# """Test the MergeShellPaths() method
+# """
+# env = Environment()
+# env.MergeShellPaths({})
+# assert not env['ENV'].has_key('INCLUDE'), env['INCLUDE']
+# env.MergeShellPaths({'INCLUDE': r'c:\Program Files\Stuff'})
+# assert env['ENV']['INCLUDE'] == r'c:\Program Files\Stuff', env['ENV']['INCLUDE']
+# env.MergeShellPaths({'INCLUDE': r'c:\Program Files\Stuff'})
+# assert env['ENV']['INCLUDE'] == r'c:\Program Files\Stuff', env['ENV']['INCLUDE']
+# env.MergeShellPaths({'INCLUDE': r'xyz'})
+# assert env['ENV']['INCLUDE'] == r'xyz%sc:\Program Files\Stuff'%os.pathsep, env['ENV']['INCLUDE']
+
+# env = Environment()
+# env['ENV']['INCLUDE'] = 'xyz'
+# env.MergeShellPaths({'INCLUDE':['c:/inc1', 'c:/inc2']} )
+# assert env['ENV']['INCLUDE'] == r'c:/inc1%sc:/inc2%sxyz'%(os.pathsep, os.pathsep), env['ENV']['INCLUDE']
+
+# # test prepend=0
+# env = Environment()
+# env.MergeShellPaths({'INCLUDE': r'c:\Program Files\Stuff'}, prepend=0)
+# assert env['ENV']['INCLUDE'] == r'c:\Program Files\Stuff', env['ENV']['INCLUDE']
+# env.MergeShellPaths({'INCLUDE': r'xyz'}, prepend=0)
+# assert env['ENV']['INCLUDE'] == r'c:\Program Files\Stuff%sxyz'%os.pathsep, env['ENV']['INCLUDE']
class BaseTestCase(unittest.TestCase,TestEnvironmentFixture):
+ reserved_variables = [
+ 'CHANGED_SOURCES',
+ 'CHANGED_TARGETS',
+ 'SOURCE',
+ 'SOURCES',
+ 'TARGET',
+ 'TARGETS',
+ 'UNCHANGED_SOURCES',
+ 'UNCHANGED_TARGETS',
+ ]
+
def test___init__(self):
"""Test construction Environment creation
env2 = self.TestEnvironment(XXX = 'x', YYY = 'y')
assert env1 == env2, diff_env(env1, env2)
- assert not env1.has_key('__env__')
- assert not env2.has_key('__env__')
+ assert '__env__' not in env1
+ assert '__env__' not in env2
- def test_options(self):
- """Test that options only get applied once."""
+ def test_variables(self):
+ """Test that variables only get applied once."""
class FakeOptions:
def __init__(self, key, val):
self.calls = 0
self.calls = self.calls + 1
o = FakeOptions('AAA', 'fake_opt')
- env = Environment(options=o, AAA='keyword_arg')
+ env = Environment(variables=o, AAA='keyword_arg')
assert o.calls == 1, o.calls
assert env['AAA'] == 'fake_opt', env['AAA']
'builder2' : b2 })
called_it = {}
env.builder1('in1')
- assert called_it['target'] == None, called_it
+ assert called_it['target'] is None, called_it
assert called_it['source'] == ['in1'], called_it
called_it = {}
env.builder2(source = 'in2', xyzzy = 1)
- assert called_it['target'] == None, called_it
+ assert called_it['target'] is None, called_it
assert called_it['source'] == ['in2'], called_it
assert called_it['xyzzy'] == 1, called_it
called_it = {}
env.builder1(foo = 'bar')
assert called_it['foo'] == 'bar', called_it
- assert called_it['target'] == None, called_it
- assert called_it['source'] == None, called_it
+ assert called_it['target'] is None, called_it
+ assert called_it['source'] is None, called_it
+
+ def test_BuilderWrapper_attributes(self):
+ """Test getting and setting of BuilderWrapper attributes
+ """
+ b1 = Builder()
+ b2 = Builder()
+ e1 = Environment()
+ e2 = Environment()
+
+ e1.Replace(BUILDERS = {'b' : b1})
+ bw = e1.b
+ assert bw.env is e1
+ bw.env = e2
+ assert bw.env is e2
+ assert bw.builder is b1
+ bw.builder = b2
+ assert bw.builder is b2
- def test_Builder_execs(self):
+ self.assertRaises(AttributeError, getattr, bw, 'foobar')
+ bw.foobar = 42
+ assert bw.foobar is 42
+
+ # This unit test is currently disabled because we don't think the
+ # underlying method it tests (Environment.BuilderWrapper.execute())
+ # is necessary, but we're leaving the code here for now in case
+ # that's mistaken.
+ def _DO_NOT_test_Builder_execs(self):
"""Test Builder execution through different environments
One environment is initialized with a single
assert built_it['out3']
env4 = env3.Clone()
- assert env4.builder1.env is env4, "builder1.env (%s) == env3 (%s)?" % (env4.builder1.env, env3)
- assert env4.builder2.env is env4, "builder2.env (%s) == env3 (%s)?" % (env4.builder1.env, env3)
+ assert env4.builder1.env is env4, "builder1.env (%s) == env3 (%s)?" % (
+env4.builder1.env, env3)
+ assert env4.builder2.env is env4, "builder2.env (%s) == env3 (%s)?" % (
+env4.builder1.env, env3)
# Now test BUILDERS as a dictionary.
built_it = {}
assert built_it['out1']
assert built_it['out2']
+
+
def test_Scanners(self):
"""Test setting SCANNERS in various ways
s1 = Scanner(name = 'scanner1', skeys = [".c", ".cc"])
s2 = Scanner(name = 'scanner2', skeys = [".m4"])
s3 = Scanner(name = 'scanner3', skeys = [".m4", ".m5"])
+ s4 = Scanner(name = 'scanner4', skeys = [None])
# XXX Tests for scanner execution through different environments,
# XXX if we ever want to do that some day
env = Environment()
try: del env['SCANNERS']
except KeyError: pass
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [None, None, None, None, None], s
env = self.TestEnvironment(SCANNERS = [])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [None, None, None, None, None], s
env.Replace(SCANNERS = [s1])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [s1, s1, None, None, None], s
env.Append(SCANNERS = [s2])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [s1, s1, None, s2, None], s
env.AppendUnique(SCANNERS = [s3])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [s1, s1, None, s2, s3], s
env = env.Clone(SCANNERS = [s2])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [None, None, None, s2, None], s
env['SCANNERS'] = [s1]
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [s1, s1, None, None, None], s
env.PrependUnique(SCANNERS = [s2, s1])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [s1, s1, None, s2, None], s
env.Prepend(SCANNERS = [s3])
- s = map(env.get_scanner, suffixes)
+ s = list(map(env.get_scanner, suffixes))
assert s == [s1, s1, None, s3, s3], s
+ # Verify behavior of case-insensitive suffix matches on Windows.
+ uc_suffixes = [_.upper() for _ in suffixes]
+
+ env = Environment(SCANNERS = [s1, s2, s3],
+ PLATFORM = 'linux')
+
+ s = list(map(env.get_scanner, suffixes))
+ assert s == [s1, s1, None, s2, s3], s
+
+ s = list(map(env.get_scanner, uc_suffixes))
+ assert s == [None, None, None, None, None], s
+
+ env['PLATFORM'] = 'win32'
+
+ s = list(map(env.get_scanner, uc_suffixes))
+ assert s == [s1, s1, None, s2, s3], s
+
+ # Verify behavior for a scanner returning None (on Windows
+ # where we might try to perform case manipulation on None).
+ env.Replace(SCANNERS = [s4])
+ s = list(map(env.get_scanner, suffixes))
+ assert s == [None, None, None, None, None], s
+
def test_ENV(self):
"""Test setting the external ENV in Environments
"""
env = Environment()
- assert env.Dictionary().has_key('ENV')
+ assert 'ENV' in env.Dictionary()
env = self.TestEnvironment(ENV = { 'PATH' : '/foo:/bar' })
assert env.Dictionary('ENV')['PATH'] == '/foo:/bar'
def test_ReservedVariables(self):
- """Test generation of warnings when reserved variable names
- are set in an environment."""
+ """Test warning generation when reserved variable names are set"""
+
+ reserved_variables = [
+ 'CHANGED_SOURCES',
+ 'CHANGED_TARGETS',
+ 'SOURCE',
+ 'SOURCES',
+ 'TARGET',
+ 'TARGETS',
+ 'UNCHANGED_SOURCES',
+ 'UNCHANGED_TARGETS',
+ ]
- SCons.Warnings.enableWarningClass(SCons.Warnings.ReservedVariableWarning)
+ warning = SCons.Warnings.ReservedVariableWarning
+ SCons.Warnings.enableWarningClass(warning)
old = SCons.Warnings.warningAsException(1)
try:
env4 = Environment()
- for kw in ['TARGET', 'TARGETS', 'SOURCE', 'SOURCES']:
+ for kw in self.reserved_variables:
exc_caught = None
try:
env4[kw] = 'xyzzy'
- except SCons.Warnings.ReservedVariableWarning:
+ except warning:
exc_caught = 1
assert exc_caught, "Did not catch ReservedVariableWarning for `%s'" % kw
- assert not env4.has_key(kw), "`%s' variable was incorrectly set" % kw
+ assert kw not in env4, "`%s' variable was incorrectly set" % kw
+ finally:
+ SCons.Warnings.warningAsException(old)
+
+ def test_FutureReservedVariables(self):
+ """Test warning generation when future reserved variable names are set"""
+
+ future_reserved_variables = []
+
+ warning = SCons.Warnings.FutureReservedVariableWarning
+ SCons.Warnings.enableWarningClass(warning)
+ old = SCons.Warnings.warningAsException(1)
+
+ try:
+ env4 = Environment()
+ for kw in future_reserved_variables:
+ exc_caught = None
+ try:
+ env4[kw] = 'xyzzy'
+ except warning:
+ exc_caught = 1
+ assert exc_caught, "Did not catch FutureReservedVariableWarning for `%s'" % kw
+ assert kw in env4, "`%s' variable was not set" % kw
finally:
SCons.Warnings.warningAsException(old)
path = drive + path
path = os.path.normpath(path)
drive, path = os.path.splitdrive(path)
- return string.lower(drive) + path
+ return drive.lower() + path
env = dict.TestEnvironment(LIBS = [ 'foo', 'bar', 'baz' ],
LIBLINKPREFIX = 'foo',
if arg not in ('$(','$)','-I'):
return np(str(arg))
return arg
- flags = map(normalize_if_path, flags)
+ flags = list(map(normalize_if_path, flags))
assert flags == expect, flags
def test_platform(self):
assert env3['X'] == {'x1': 8, 'x2': 9}, env3['X']
assert env3['Y'] == {'y1': 10}, env3['Y']
- env4 = self.TestEnvironment(BUILDERS = {'z1' : 11})
- env4.Append(BUILDERS = {'z2' : 12})
- assert env4['BUILDERS'] == {'z1' : 11, 'z2' : 12}, env4['BUILDERS']
+ z1 = Builder()
+ z2 = Builder()
+ env4 = self.TestEnvironment(BUILDERS = {'z1' : z1})
+ env4.Append(BUILDERS = {'z2' : z2})
+ assert env4['BUILDERS'] == {'z1' : z1, 'z2' : z2}, env4['BUILDERS']
assert hasattr(env4, 'z1')
assert hasattr(env4, 'z2')
env1.AppendENVPath('PATH',r'C:\dir\num\three', sep = ';')
env1.AppendENVPath('MYPATH',r'C:\mydir\num\three','MYENV', sep = ';')
env1.AppendENVPath('MYPATH',r'C:\mydir\num\one','MYENV', sep = ';')
+ # this should do nothing since delete_existing is 0
+ env1.AppendENVPath('MYPATH',r'C:\mydir\num\three','MYENV', sep = ';', delete_existing=0)
assert(env1['ENV']['PATH'] == r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three')
assert(env1['MYENV']['MYPATH'] == r'C:\mydir\num\two;C:\mydir\num\three;C:\mydir\num\one')
+ test = TestCmd.TestCmd(workdir = '')
+ test.subdir('sub1', 'sub2')
+ p=env1['ENV']['PATH']
+ env1.AppendENVPath('PATH','#sub1', sep = ';')
+ env1.AppendENVPath('PATH',env1.fs.Dir('sub2'), sep = ';')
+ assert env1['ENV']['PATH'] == p + ';sub1;sub2', env1['ENV']['PATH']
+
def test_AppendUnique(self):
"""Test appending to unique values to construction variables
BBB4 = ['b4'],
BBB5 = ['b5'],
CCC1 = '',
- CCC2 = '')
+ CCC2 = '',
+ DDD1 = ['a', 'b', 'c'])
env.AppendUnique(AAA1 = 'a1',
AAA2 = ['a2'],
- AAA3 = ['a3', 'b', 'c', 'a3'],
+ AAA3 = ['a3', 'b', 'c', 'c', 'b', 'a3'], # ignore dups
AAA4 = 'a4.new',
AAA5 = ['a5.new'],
BBB1 = 'b1',
BBB2 = ['b2'],
- BBB3 = ['b3', 'c', 'd', 'b3'],
+ BBB3 = ['b3', 'c', 'd', 'c', 'b3'],
BBB4 = 'b4.new',
BBB5 = ['b5.new'],
CCC1 = 'c1',
- CCC2 = ['c2'])
+ CCC2 = ['c2'],
+ DDD1 = 'b')
assert env['AAA1'] == 'a1a1', env['AAA1']
assert env['AAA2'] == ['a2'], env['AAA2']
assert env['BBB5'] == ['b5', 'b5.new'], env['BBB5']
assert env['CCC1'] == 'c1', env['CCC1']
assert env['CCC2'] == ['c2'], env['CCC2']
-
+ assert env['DDD1'] == ['a', 'b', 'c'], env['DDD1']
+
+ env.AppendUnique(DDD1 = 'b', delete_existing=1)
+ assert env['DDD1'] == ['a', 'c', 'b'], env['DDD1'] # b moves to end
+ env.AppendUnique(DDD1 = ['a','b'], delete_existing=1)
+ assert env['DDD1'] == ['c', 'a', 'b'], env['DDD1'] # a & b move to end
+ env.AppendUnique(DDD1 = ['e','f', 'e'], delete_existing=1)
+ assert env['DDD1'] == ['c', 'a', 'b', 'f', 'e'], env['DDD1'] # add last
+
env['CLVar'] = CLVar([])
env.AppendUnique(CLVar = 'bar')
result = env['CLVar']
assert env1.Dictionary('XXX') is env2.Dictionary('XXX')
assert 4 in env2.Dictionary('YYY')
assert not 4 in env1.Dictionary('YYY')
- assert env2.Dictionary('ZZZ').has_key(5)
- assert not env1.Dictionary('ZZZ').has_key(5)
+ assert 5 in env2.Dictionary('ZZZ')
+ assert 5 not in env1.Dictionary('ZZZ')
#
- env1 = self.TestEnvironment(BUILDERS = {'b1' : 1})
+ env1 = self.TestEnvironment(BUILDERS = {'b1' : Builder()})
assert hasattr(env1, 'b1'), "env1.b1 was not set"
- assert env1.b1.env == env1, "b1.env doesn't point to env1"
- env2 = env1.Clone(BUILDERS = {'b2' : 2})
+ assert env1.b1.object == env1, "b1.object doesn't point to env1"
+ env2 = env1.Clone(BUILDERS = {'b2' : Builder()})
assert env2 is env2
assert env2 == env2
assert hasattr(env1, 'b1'), "b1 was mistakenly cleared from env1"
- assert env1.b1.env == env1, "b1.env was changed"
+ assert env1.b1.object == env1, "b1.object was changed"
assert not hasattr(env2, 'b1'), "b1 was not cleared from env2"
assert hasattr(env2, 'b2'), "env2.b2 was not set"
- assert env2.b2.env == env2, "b2.env doesn't point to env2"
+ assert env2.b2.object == env2, "b2.object doesn't point to env2"
# Ensure that specifying new tools in a copied environment
# works.
env = env.Clone(tools=['yyy'])
assert env['YYY'] == 'two', env['YYY']
+
+ # Test that
+ real_value = [4]
+
+ def my_tool(env, rv=real_value):
+ assert env['KEY_THAT_I_WANT'] == rv[0]
+ env['KEY_THAT_I_WANT'] = rv[0] + 1
+
+ env = self.TestEnvironment()
+
+ real_value[0] = 5
+ env = env.Clone(KEY_THAT_I_WANT=5, tools=[my_tool])
+ assert env['KEY_THAT_I_WANT'] == real_value[0], env['KEY_THAT_I_WANT']
+
+ real_value[0] = 6
+ env = env.Clone(KEY_THAT_I_WANT=6, tools=[my_tool])
+ assert env['KEY_THAT_I_WANT'] == real_value[0], env['KEY_THAT_I_WANT']
+
+
def test_Copy(self):
"""Test copying using the old env.Copy() method"""
env1 = self.TestEnvironment(XXX = 'x', YYY = 'y')
xxx, zzz = env.Dictionary('XXX', 'ZZZ')
assert xxx == 'x'
assert zzz == 'z'
- assert env.Dictionary().has_key('BUILDERS')
- assert env.Dictionary().has_key('CC')
- assert env.Dictionary().has_key('CCFLAGS')
- assert env.Dictionary().has_key('ENV')
+ assert 'BUILDERS' in env.Dictionary()
+ assert 'CC' in env.Dictionary()
+ assert 'CCFLAGS' in env.Dictionary()
+ assert 'ENV' in env.Dictionary()
assert env['XXX'] == 'x'
env['XXX'] = 'foo'
assert env.Dictionary('XXX') == 'foo'
del env['XXX']
- assert not env.Dictionary().has_key('XXX')
+ assert 'XXX' not in env.Dictionary()
def test_FindIxes(self):
"Test FindIxes()"
assert paths[0] == env.FindIxes(paths, 'LIBPREFIX', 'LIBSUFFIX')
assert paths[1] == env.FindIxes(paths, 'SHLIBPREFIX', 'SHLIBSUFFIX')
- assert None == env.FindIxes(paths, 'PREFIX', 'POST')
+ assert None is env.FindIxes(paths, 'PREFIX', 'POST')
paths = ['libfoo.a', 'prefoopost']
assert paths[0] == env.FindIxes(paths, 'LIBPREFIX', 'LIBSUFFIX')
- assert None == env.FindIxes(paths, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ assert None is env.FindIxes(paths, 'SHLIBPREFIX', 'SHLIBSUFFIX')
assert paths[1] == env.FindIxes(paths, 'PREFIX', 'SUFFIX')
def test_ParseConfig(self):
del dlist[:]
env.ParseDepends('$SINGLE', only_one=1)
- t = map(str, tlist)
- d = map(str, dlist)
+ t = list(map(str, tlist))
+ d = list(map(str, dlist))
assert t == ['f0'], t
assert d == ['d1', 'd2', 'd3'], d
del dlist[:]
env.ParseDepends(test.workpath('multiple'))
- t = map(str, tlist)
- d = map(str, dlist)
+ t = list(map(str, tlist))
+ d = list(map(str, dlist))
assert t == ['f1', 'f2', 'f3', 'f4', 'f5'], t
assert d == ['foo', 'bar', 'abc', 'def', 'ghi', 'jkl', 'mno'], d
assert env3['X'] == {'x1': 8, 'x2' : 9}, env3['X']
assert env3['Y'] == {'y1': 10}, env3['Y']
- env4 = self.TestEnvironment(BUILDERS = {'z1' : 11})
- env4.Prepend(BUILDERS = {'z2' : 12})
- assert env4['BUILDERS'] == {'z1' : 11, 'z2' : 12}, env4['BUILDERS']
+ z1 = Builder()
+ z2 = Builder()
+ env4 = self.TestEnvironment(BUILDERS = {'z1' : z1})
+ env4.Prepend(BUILDERS = {'z2' : z2})
+ assert env4['BUILDERS'] == {'z1' : z1, 'z2' : z2}, env4['BUILDERS']
assert hasattr(env4, 'z1')
assert hasattr(env4, 'z2')
env1.PrependENVPath('PATH',r'C:\dir\num\three',sep = ';')
env1.PrependENVPath('MYPATH',r'C:\mydir\num\three','MYENV',sep = ';')
env1.PrependENVPath('MYPATH',r'C:\mydir\num\one','MYENV',sep = ';')
+ # this should do nothing since delete_existing is 0
+ env1.PrependENVPath('MYPATH',r'C:\mydir\num\three','MYENV', sep = ';', delete_existing=0)
assert(env1['ENV']['PATH'] == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one')
assert(env1['MYENV']['MYPATH'] == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two')
- def test_PrependENVPath(self):
- """Test prepending to an ENV path."""
- env1 = self.TestEnvironment(ENV = {'PATH': r'C:\dir\num\one;C:\dir\num\two'},
- MYENV = {'MYPATH': r'C:\mydir\num\one;C:\mydir\num\two'})
- # have to include the pathsep here so that the test will work on UNIX too.
- env1.PrependENVPath('PATH',r'C:\dir\num\two',sep = ';')
- env1.PrependENVPath('PATH',r'C:\dir\num\three',sep = ';')
- env1.PrependENVPath('MYPATH',r'C:\mydir\num\three','MYENV',sep = ';')
- env1.PrependENVPath('MYPATH',r'C:\mydir\num\one','MYENV',sep = ';')
- assert(env1['ENV']['PATH'] == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one')
- assert(env1['MYENV']['MYPATH'] == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two')
+ test = TestCmd.TestCmd(workdir = '')
+ test.subdir('sub1', 'sub2')
+ p=env1['ENV']['PATH']
+ env1.PrependENVPath('PATH','#sub1', sep = ';')
+ env1.PrependENVPath('PATH',env1.fs.Dir('sub2'), sep = ';')
+ assert env1['ENV']['PATH'] == 'sub2;sub1;' + p, env1['ENV']['PATH']
def test_PrependUnique(self):
"""Test prepending unique values to construction variables
BBB4 = ['b4'],
BBB5 = ['b5'],
CCC1 = '',
- CCC2 = '')
+ CCC2 = '',
+ DDD1 = ['a', 'b', 'c'])
env.PrependUnique(AAA1 = 'a1',
AAA2 = ['a2'],
- AAA3 = ['a3', 'b', 'c', 'a3'],
+ AAA3 = ['a3', 'b', 'c', 'b', 'a3'], # ignore dups
AAA4 = 'a4.new',
AAA5 = ['a5.new'],
BBB1 = 'b1',
BBB4 = 'b4.new',
BBB5 = ['b5.new'],
CCC1 = 'c1',
- CCC2 = ['c2'])
+ CCC2 = ['c2'],
+ DDD1 = 'b')
assert env['AAA1'] == 'a1a1', env['AAA1']
assert env['AAA2'] == ['a2'], env['AAA2']
- assert env['AAA3'] == ['b', 'c', 'a3'], env['AAA3']
+ assert env['AAA3'] == ['c', 'b', 'a3'], env['AAA3']
assert env['AAA4'] == 'a4.newa4', env['AAA4']
assert env['AAA5'] == ['a5.new', 'a5'], env['AAA5']
assert env['BBB1'] == ['b1'], env['BBB1']
assert env['BBB5'] == ['b5.new', 'b5'], env['BBB5']
assert env['CCC1'] == 'c1', env['CCC1']
assert env['CCC2'] == ['c2'], env['CCC2']
+ assert env['DDD1'] == ['a', 'b', 'c'], env['DDD1']
+
+ env.PrependUnique(DDD1 = 'b', delete_existing=1)
+ assert env['DDD1'] == ['b', 'a', 'c'], env['DDD1'] # b moves to front
+ env.PrependUnique(DDD1 = ['a','c'], delete_existing=1)
+ assert env['DDD1'] == ['a', 'c', 'b'], env['DDD1'] # a & c move to front
+ env.PrependUnique(DDD1 = ['d','e','d'], delete_existing=1)
+ assert env['DDD1'] == ['d', 'e', 'a', 'c', 'b'], env['DDD1']
+
env['CLVar'] = CLVar([])
env.PrependUnique(CLVar = 'bar')
env2 = self.TestEnvironment(AAA = 'a', BBB = 'bbb', CCC = 'ccc')
assert env1 == env2, diff_env(env1, env2)
- env3 = self.TestEnvironment(BUILDERS = {'b1' : 1})
+ b1 = Builder()
+ b2 = Builder()
+ env3 = self.TestEnvironment(BUILDERS = {'b1' : b1})
assert hasattr(env3, 'b1'), "b1 was not set"
- env3.Replace(BUILDERS = {'b2' : 2})
+ env3.Replace(BUILDERS = {'b2' : b2})
assert not hasattr(env3, 'b1'), "b1 was not cleared"
assert hasattr(env3, 'b2'), "b2 was not set"
test.workpath('sub2'),
test.workpath('sub3'),
test.workpath('sub4'),
- ] + string.split(env_path, os.pathsep)
+ ] + env_path.split(os.pathsep)
pathdirs_1243 = [ test.workpath('sub1'),
test.workpath('sub2'),
test.workpath('sub4'),
test.workpath('sub3'),
- ] + string.split(env_path, os.pathsep)
+ ] + env_path.split(os.pathsep)
- path = string.join(pathdirs_1234, os.pathsep)
+ path = os.pathsep.join(pathdirs_1234)
env = self.TestEnvironment(ENV = {'PATH' : path})
wi = env.WhereIs('xxx.exe')
assert wi == test.workpath(sub3_xxx_exe), wi
wi = env.WhereIs('xxx.exe', pathdirs_1243)
assert wi == test.workpath(sub4_xxx_exe), wi
- wi = env.WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep))
+ wi = env.WhereIs('xxx.exe', os.pathsep.join(pathdirs_1243))
assert wi == test.workpath(sub4_xxx_exe), wi
wi = env.WhereIs('xxx.exe', reject = sub3_xxx_exe)
wi = env.WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe)
assert wi == test.workpath(sub4_xxx_exe), wi
- path = string.join(pathdirs_1243, os.pathsep)
+ path = os.pathsep.join(pathdirs_1243)
env = self.TestEnvironment(ENV = {'PATH' : path})
wi = env.WhereIs('xxx.exe')
assert wi == test.workpath(sub4_xxx_exe), wi
wi = env.WhereIs('xxx.exe', pathdirs_1234)
assert wi == test.workpath(sub3_xxx_exe), wi
- wi = env.WhereIs('xxx.exe', string.join(pathdirs_1234, os.pathsep))
+ wi = env.WhereIs('xxx.exe', os.pathsep.join(pathdirs_1234))
assert wi == test.workpath(sub3_xxx_exe), wi
if sys.platform == 'win32':
assert wi == test.workpath(sub4_xxx_exe), wi
wi = env.WhereIs('xxx', path = pathdirs_1234, pathext = '.BAT;.EXE')
- assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi
+ assert wi.lower() == test.workpath(sub3_xxx_exe).lower(), wi
# Test that we return a normalized path even when
# the path contains forward slashes.
forward_slash = test.workpath('') + '/sub3'
wi = env.WhereIs('xxx', path = forward_slash, pathext = '.EXE')
- assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi
+ assert wi.lower() == test.workpath(sub3_xxx_exe).lower(), wi
tgt = env.Alias('export_alias', [ 'asrc1', '$FOO' ])[0]
assert str(tgt) == 'export_alias', tgt
- assert len(tgt.sources) == 2, map(str, tgt.sources)
- assert str(tgt.sources[0]) == 'asrc1', map(str, tgt.sources)
- assert str(tgt.sources[1]) == 'kkk', map(str, tgt.sources)
+ assert len(tgt.sources) == 2, list(map(str, tgt.sources))
+ assert str(tgt.sources[0]) == 'asrc1', list(map(str, tgt.sources))
+ assert str(tgt.sources[1]) == 'kkk', list(map(str, tgt.sources))
n = env.Alias(tgt, source = ['$BAR', 'asrc4'])[0]
assert n is tgt, n
- assert len(tgt.sources) == 4, map(str, tgt.sources)
- assert str(tgt.sources[2]) == 'lll', map(str, tgt.sources)
- assert str(tgt.sources[3]) == 'asrc4', map(str, tgt.sources)
+ assert len(tgt.sources) == 4, list(map(str, tgt.sources))
+ assert str(tgt.sources[2]) == 'lll', list(map(str, tgt.sources))
+ assert str(tgt.sources[3]) == 'asrc4', list(map(str, tgt.sources))
n = env.Alias('$EA', 'asrc5')[0]
assert n is tgt, n
- assert len(tgt.sources) == 5, map(str, tgt.sources)
- assert str(tgt.sources[4]) == 'asrc5', map(str, tgt.sources)
+ assert len(tgt.sources) == 5, list(map(str, tgt.sources))
+ assert str(tgt.sources[4]) == 'asrc5', list(map(str, tgt.sources))
t1, t2 = env.Alias(['t1', 't2'], ['asrc6', 'asrc7'])
assert str(t1) == 't1', t1
assert str(t2) == 't2', t2
- assert len(t1.sources) == 2, map(str, t1.sources)
- assert str(t1.sources[0]) == 'asrc6', map(str, t1.sources)
- assert str(t1.sources[1]) == 'asrc7', map(str, t1.sources)
- assert len(t2.sources) == 2, map(str, t2.sources)
- assert str(t2.sources[0]) == 'asrc6', map(str, t2.sources)
- assert str(t2.sources[1]) == 'asrc7', map(str, t2.sources)
+ assert len(t1.sources) == 2, list(map(str, t1.sources))
+ assert str(t1.sources[0]) == 'asrc6', list(map(str, t1.sources))
+ assert str(t1.sources[1]) == 'asrc7', list(map(str, t1.sources))
+ assert len(t2.sources) == 2, list(map(str, t2.sources))
+ assert str(t2.sources[0]) == 'asrc6', list(map(str, t2.sources))
+ assert str(t2.sources[1]) == 'asrc7', list(map(str, t2.sources))
tgt = env.Alias('add', 's1')
tgt = env.Alias('add', 's2')[0]
- s = map(str, tgt.sources)
+ s = list(map(str, tgt.sources))
assert s == ['s1', 's2'], s
tgt = env.Alias(tgt, 's3')[0]
- s = map(str, tgt.sources)
+ s = list(map(str, tgt.sources))
assert s == ['s1', 's2', 's3'], s
tgt = env.Alias('act', None, "action1")[0]
assert t[6].path == 'file'
assert t[6].always_build
- def test_BuildDir(self):
- """Test the BuildDir() method"""
+ def test_VariantDir(self):
+ """Test the VariantDir() method"""
class MyFS:
def Dir(self, name):
return name
- def BuildDir(self, build_dir, src_dir, duplicate):
- self.build_dir = build_dir
+ def VariantDir(self, variant_dir, src_dir, duplicate):
+ self.variant_dir = variant_dir
self.src_dir = src_dir
self.duplicate = duplicate
env = self.TestEnvironment(FOO = 'fff', BAR = 'bbb')
env.fs = MyFS()
- env.BuildDir('build', 'src')
- assert env.fs.build_dir == 'build', env.fs.build_dir
+ env.VariantDir('build', 'src')
+ assert env.fs.variant_dir == 'build', env.fs.variant_dir
assert env.fs.src_dir == 'src', env.fs.src_dir
assert env.fs.duplicate == 1, env.fs.duplicate
- env.BuildDir('build${FOO}', '${BAR}src', 0)
- assert env.fs.build_dir == 'buildfff', env.fs.build_dir
+ env.VariantDir('build${FOO}', '${BAR}src', 0)
+ assert env.fs.variant_dir == 'buildfff', env.fs.variant_dir
assert env.fs.src_dir == 'bbbsrc', env.fs.src_dir
assert env.fs.duplicate == 0, env.fs.duplicate
env = self.TestEnvironment(FOO = 'xyzzy')
b = env.Builder(action = 'foo')
- assert not b is None, b
+ assert b is not None, b
b = env.Builder(action = '$FOO')
- assert not b is None, b
+ assert b is not None, b
b = env.Builder(action = ['$FOO', 'foo'])
- assert not b is None, b
+ assert b is not None, b
def func(arg):
pass
b = env.Builder(action = func)
- assert not b is None, b
+ assert b is not None, b
b = env.Builder(generator = func)
- assert not b is None, b
+ assert b is not None, b
def test_CacheDir(self):
"""Test the CacheDir() method"""
env = self.TestEnvironment(CD = 'CacheDir')
env.CacheDir('foo')
- assert env._CacheDir.path == 'foo', env._CacheDir.path
+ assert env._CacheDir_path == 'foo', env._CacheDir_path
env.CacheDir('$CD')
- assert env._CacheDir.path == 'CacheDir', env._CacheDir.path
+ assert env._CacheDir_path == 'CacheDir', env._CacheDir_path
def test_Clean(self):
"""Test the Clean() method"""
fff = env.arg2nodes('fff')[0]
t = env.Clean('foo', 'aaa')
- l = map(str, CT[foo])
+ l = list(map(str, CT[foo]))
assert l == ['aaa'], l
t = env.Clean(foo, ['$BAR', 'ccc'])
- l = map(str, CT[foo])
+ l = list(map(str, CT[foo]))
assert l == ['aaa', 'bbb', 'ccc'], l
eee = env.arg2nodes('eee')[0]
t = env.Clean('$FOO', 'ddd')
- l = map(str, CT[fff])
+ l = list(map(str, CT[fff]))
assert l == ['ddd'], l
t = env.Clean(fff, [eee, 'fff'])
- l = map(str, CT[fff])
+ l = list(map(str, CT[fff]))
assert l == ['ddd', 'eee', 'fff'], l
def test_Command(self):
env = Environment()
t = env.Command(target='foo.out', source=['foo1.in', 'foo2.in'],
action='buildfoo $target $source')[0]
- assert not t.builder is None
+ assert t.builder is not None
assert t.builder.action.__class__.__name__ == 'CommandAction'
assert t.builder.action.cmd_list == 'buildfoo $target $source'
- assert 'foo1.in' in map(lambda x: x.path, t.sources)
- assert 'foo2.in' in map(lambda x: x.path, t.sources)
+ assert 'foo1.in' in [x.path for x in t.sources]
+ assert 'foo2.in' in [x.path for x in t.sources]
sub = env.fs.Dir('sub')
t = env.Command(target='bar.out', source='sub',
action='buildbar $target $source')[0]
- assert 'sub' in map(lambda x: x.path, t.sources)
+ assert 'sub' in [x.path for x in t.sources]
def testFunc(env, target, source):
assert str(target[0]) == 'foo.out'
- assert 'foo1.in' in map(str, source) and 'foo2.in' in map(str, source), map(str, source)
+ assert 'foo1.in' in list(map(str, source)) and 'foo2.in' in list(map(str, source)), list(map(str, source))
return 0
t = env.Command(target='foo.out', source=['foo1.in','foo2.in'],
action=testFunc)[0]
- assert not t.builder is None
+ assert t.builder is not None
assert t.builder.action.__class__.__name__ == 'FunctionAction'
t.build()
- assert 'foo1.in' in map(lambda x: x.path, t.sources)
- assert 'foo2.in' in map(lambda x: x.path, t.sources)
+ assert 'foo1.in' in [x.path for x in t.sources]
+ assert 'foo2.in' in [x.path for x in t.sources]
x = []
def test2(baz, x=x):
t = env.Command(target='baz.out', source='baz.in',
action='${TEST2(XYZ)}',
XYZ='magic word')[0]
- assert not t.builder is None
+ assert t.builder is not None
t.build()
assert x[0] == 'magic word', x
action = 'foo',
X = 'xxx')[0]
assert str(t) == 'xxx.out', str(t)
- assert 'xxx.in' in map(lambda x: x.path, t.sources)
+ assert 'xxx.in' in [x.path for x in t.sources]
env = self.TestEnvironment(source_scanner = 'should_not_find_this')
t = env.Command(target='file.out', source='file.in',
pass
c = env.Configure()
- assert not c is None, c
+ assert c is not None, c
c.Finish()
c = env.Configure(custom_tests = {'foo' : func, '$FOO' : func})
- assert not c is None, c
+ assert c is not None, c
assert hasattr(c, 'foo')
assert hasattr(c, 'xyzzy')
c.Finish()
d = env.Dir('${BAR}_$BAR')
assert d == 'Dir(bardir_bardir)', d
+ d = env.Dir(['dir1'])
+ assert d == ['Dir(dir1)'], d
+
+ d = env.Dir(['dir1', 'dir2'])
+ assert d == ['Dir(dir1)', 'Dir(dir2)'], d
+
def test_NoClean(self):
"""Test the NoClean() method"""
env = self.TestEnvironment(FOO='ggg', BAR='hhh')
e = env.Entry('${BAR}_$BAR')
assert e == 'Entry(barentry_barentry)', e
+ e = env.Entry(['entry1'])
+ assert e == ['Entry(entry1)'], e
+
+ e = env.Entry(['entry1', 'entry2'])
+ assert e == ['Entry(entry1)', 'Entry(entry2)'], e
+
def test_File(self):
"""Test the File() method"""
class MyFS:
f = env.File('${BAR}_$BAR')
assert f == 'File(barfile_barfile)', f
+ f = env.File(['file1'])
+ assert f == ['File(file1)'], f
+
+ f = env.File(['file1', 'file2'])
+ assert f == ['File(file1)', 'File(file2)'], f
+
def test_FindFile(self):
"""Test the FindFile() method"""
env = self.TestEnvironment(FOO = 'fff', BAR = 'bbb')
env = self.TestEnvironment(FOO = scan)
s = env.Scanner('foo')
- assert not s is None, s
+ assert s is not None, s
s = env.Scanner(function = 'foo')
- assert not s is None, s
+ assert s is not None, s
if 0:
s = env.Scanner('$FOO')
- assert not s is None, s
+ assert s is not None, s
s = env.Scanner(function = '$FOO')
- assert not s is None, s
+ assert s is not None, s
def test_SConsignFile(self):
"""Test the SConsignFile() method"""
env = self.TestEnvironment(FOO = 'SConsign',
BAR = os.path.join(os.sep, 'File'))
env.fs = MyFS()
+ env.Execute = lambda action: None
try:
fnames = []
SCons.SConsign.File = capture
env.SConsignFile('foo')
- assert fnames[0] == os.path.join(os.sep, 'dir', 'foo'), fnames
- assert dbms[0] == None, dbms
+ assert fnames[-1] == os.path.join(os.sep, 'dir', 'foo'), fnames
+ assert dbms[-1] is None, dbms
env.SConsignFile('$FOO')
- assert fnames[1] == os.path.join(os.sep, 'dir', 'SConsign'), fnames
- assert dbms[1] == None, dbms
+ assert fnames[-1] == os.path.join(os.sep, 'dir', 'SConsign'), fnames
+ assert dbms[-1] is None, dbms
env.SConsignFile('/$FOO')
- assert fnames[2] == '/SConsign', fnames
- assert dbms[2] == None, dbms
+ assert fnames[-1] == os.sep + 'SConsign', fnames
+ assert dbms[-1] is None, dbms
+
+ env.SConsignFile(os.sep + '$FOO')
+ assert fnames[-1] == os.sep + 'SConsign', fnames
+ assert dbms[-1] is None, dbms
env.SConsignFile('$BAR', 'x')
- assert fnames[3] == os.path.join(os.sep, 'File'), fnames
- assert dbms[3] == 'x', dbms
+ assert fnames[-1] == os.path.join(os.sep, 'File'), fnames
+ assert dbms[-1] == 'x', dbms
env.SConsignFile('__$BAR', 7)
- assert fnames[4] == os.path.join(os.sep, 'dir', '__', 'File'), fnames
- assert dbms[4] == 7, dbms
+ assert fnames[-1] == os.path.join(os.sep, 'dir', '__', 'File'), fnames
+ assert dbms[-1] == 7, dbms
env.SConsignFile()
- assert fnames[5] == os.path.join(os.sep, 'dir', '.sconsign'), fnames
- assert dbms[5] == None, dbms
+ assert fnames[-1] == os.path.join(os.sep, 'dir', '.sconsign'), fnames
+ assert dbms[-1] is None, dbms
env.SConsignFile(None)
- assert fnames[6] == None, fnames
- assert dbms[6] == None, dbms
+ assert fnames[-1] is None, fnames
+ assert dbms[-1] is None, dbms
finally:
SCons.SConsign.File = save_SConsign_File
def test_SourceSignatures(type):
"""Test the SourceSignatures() method"""
+ import SCons.Errors
+
env = type.TestEnvironment(M = 'MD5', T = 'timestamp')
exc_caught = None
except SCons.Errors.UserError:
exc_caught = 1
assert exc_caught, "did not catch expected UserError"
- assert not hasattr(env, '_calc_module')
env.SourceSignatures('MD5')
- m = env._calc_module
+ assert env.src_sig_type == 'MD5', env.src_sig_type
env.SourceSignatures('$M')
- assert env._calc_module is m
+ assert env.src_sig_type == 'MD5', env.src_sig_type
env.SourceSignatures('timestamp')
- t = env._calc_module
+ assert env.src_sig_type == 'timestamp', env.src_sig_type
env.SourceSignatures('$T')
- assert env._calc_module is t
+ assert env.src_sig_type == 'timestamp', env.src_sig_type
+
+ try:
+ import SCons.Util
+ save_md5 = SCons.Util.md5
+ SCons.Util.md5 = None
+ try:
+ env.SourceSignatures('MD5')
+ except SCons.Errors.UserError:
+ pass
+ else:
+ self.fail('Did not catch expected UserError')
+ finally:
+ SCons.Util.md5 = save_md5
def test_Split(self):
"""Test the Split() method"""
def test_TargetSignatures(type):
"""Test the TargetSignatures() method"""
+ import SCons.Errors
+
env = type.TestEnvironment(B = 'build', C = 'content')
exc_caught = None
assert not hasattr(env, '_build_signature')
env.TargetSignatures('build')
- assert env._build_signature == 1, env._build_signature
-
- env.TargetSignatures('content')
- assert env._build_signature == 0, env._build_signature
+ assert env.tgt_sig_type == 'build', env.tgt_sig_type
env.TargetSignatures('$B')
- assert env._build_signature == 1, env._build_signature
+ assert env.tgt_sig_type == 'build', env.tgt_sig_type
+
+ env.TargetSignatures('content')
+ assert env.tgt_sig_type == 'content', env.tgt_sig_type
env.TargetSignatures('$C')
- assert env._build_signature == 0, env._build_signature
+ assert env.tgt_sig_type == 'content', env.tgt_sig_type
+
+ env.TargetSignatures('MD5')
+ assert env.tgt_sig_type == 'MD5', env.tgt_sig_type
+
+ env.TargetSignatures('timestamp')
+ assert env.tgt_sig_type == 'timestamp', env.tgt_sig_type
+
+ try:
+ import SCons.Util
+ save_md5 = SCons.Util.md5
+ SCons.Util.md5 = None
+ try:
+ env.TargetSignatures('MD5')
+ except SCons.Errors.UserError:
+ pass
+ else:
+ self.fail('Did not catch expected UserError')
+ try:
+ env.TargetSignatures('content')
+ except SCons.Errors.UserError:
+ pass
+ else:
+ self.fail('Did not catch expected UserError')
+ finally:
+ SCons.Util.md5 = save_md5
def test_Value(self):
"""Test creating a Value() object
f = env.xxx('$FOO')
assert f == 'foo', f
- def test_bad_keywords(type):
+ def test_bad_keywords(self):
"""Test trying to use reserved keywords in an Environment"""
- reserved = ['TARGETS','SOURCES', 'SOURCE','TARGET']
added = []
- env = type.TestEnvironment(TARGETS = 'targets',
+ env = self.TestEnvironment(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
INIT = 'init')
bad_msg = '%s is not reserved, but got omitted; see Environment.construction_var_name_ok'
added.append('INIT')
- for x in reserved:
- assert not env.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in env, env[x]
for x in added:
- assert env.has_key(x), bad_msg % x
+ assert x in env, bad_msg % x
env.Append(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
APPEND = 'append')
added.append('APPEND')
- for x in reserved:
- assert not env.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in env, env[x]
for x in added:
- assert env.has_key(x), bad_msg % x
+ assert x in env, bad_msg % x
env.AppendUnique(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
APPENDUNIQUE = 'appendunique')
added.append('APPENDUNIQUE')
- for x in reserved:
- assert not env.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in env, env[x]
for x in added:
- assert env.has_key(x), bad_msg % x
+ assert x in env, bad_msg % x
env.Prepend(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
PREPEND = 'prepend')
added.append('PREPEND')
- for x in reserved:
- assert not env.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in env, env[x]
for x in added:
- assert env.has_key(x), bad_msg % x
+ assert x in env, bad_msg % x
env.Prepend(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
PREPENDUNIQUE = 'prependunique')
added.append('PREPENDUNIQUE')
- for x in reserved:
- assert not env.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in env, env[x]
for x in added:
- assert env.has_key(x), bad_msg % x
+ assert x in env, bad_msg % x
env.Replace(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
REPLACE = 'replace')
added.append('REPLACE')
- for x in reserved:
- assert not env.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in env, env[x]
for x in added:
- assert env.has_key(x), bad_msg % x
+ assert x in env, bad_msg % x
copy = env.Clone(TARGETS = 'targets',
SOURCES = 'sources',
SOURCE = 'source',
TARGET = 'target',
+ CHANGED_SOURCES = 'changed_sources',
+ CHANGED_TARGETS = 'changed_targets',
+ UNCHANGED_SOURCES = 'unchanged_sources',
+ UNCHANGED_TARGETS = 'unchanged_targets',
COPY = 'copy')
- for x in reserved:
- assert not copy.has_key(x), env[x]
+ for x in self.reserved_variables:
+ assert x not in copy, env[x]
for x in added + ['COPY']:
- assert copy.has_key(x), bad_msg % x
+ assert x in copy, bad_msg % x
over = env.Override({'TARGETS' : 'targets',
'SOURCES' : 'sources',
'SOURCE' : 'source',
'TARGET' : 'target',
+ 'CHANGED_SOURCES' : 'changed_sources',
+ 'CHANGED_TARGETS' : 'changed_targets',
+ 'UNCHANGED_SOURCES' : 'unchanged_sources',
+ 'UNCHANGED_TARGETS' : 'unchanged_targets',
'OVERRIDE' : 'override'})
- for x in reserved:
- assert not over.has_key(x), over[x]
+ for x in self.reserved_variables:
+ assert x not in over, over[x]
for x in added + ['OVERRIDE']:
- assert over.has_key(x), bad_msg % x
+ assert x in over, bad_msg % x
+
+ def test_parse_flags(self):
+ '''Test the Base class parse_flags argument'''
+ # all we have to show is that it gets to MergeFlags internally
+ env = Environment(tools=[], parse_flags = '-X')
+ assert env['CCFLAGS'] == ['-X'], env['CCFLAGS']
+
+ env = Environment(tools=[], CCFLAGS=None, parse_flags = '-Y')
+ assert env['CCFLAGS'] == ['-Y'], env['CCFLAGS']
+
+ env = Environment(tools=[], CPPDEFINES = 'FOO', parse_flags = '-std=c99 -X -DBAR')
+ assert env['CFLAGS'] == ['-std=c99'], env['CFLAGS']
+ assert env['CCFLAGS'] == ['-X'], env['CCFLAGS']
+ assert env['CPPDEFINES'] == ['FOO', 'BAR'], env['CPPDEFINES']
+
+ def test_clone_parse_flags(self):
+ '''Test the env.Clone() parse_flags argument'''
+ # all we have to show is that it gets to MergeFlags internally
+ env = Environment(tools = [])
+ env2 = env.Clone(parse_flags = '-X')
+ assert 'CCFLAGS' not in env
+ assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS']
+
+ env = Environment(tools = [], CCFLAGS=None)
+ env2 = env.Clone(parse_flags = '-Y')
+ assert env['CCFLAGS'] is None, env['CCFLAGS']
+ assert env2['CCFLAGS'] == ['-Y'], env2['CCFLAGS']
+
+ env = Environment(tools = [], CPPDEFINES = 'FOO')
+ env2 = env.Clone(parse_flags = '-std=c99 -X -DBAR')
+ assert 'CFLAGS' not in env
+ assert env2['CFLAGS'] == ['-std=c99'], env2['CFLAGS']
+ assert 'CCFLAGS' not in env
+ assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS']
+ assert env['CPPDEFINES'] == 'FOO', env['CPPDEFINES']
+ assert env2['CPPDEFINES'] == ['FOO','BAR'], env2['CPPDEFINES']
env, env2, env3 = self.envs
del env3['XXX']
- assert not env.has_key('XXX'), "env has XXX?"
- assert not env2.has_key('XXX'), "env2 has XXX?"
- assert not env3.has_key('XXX'), "env3 has XXX?"
+ assert 'XXX' not in env, "env has XXX?"
+ assert 'XXX' not in env2, "env2 has XXX?"
+ assert 'XXX' not in env3, "env3 has XXX?"
del env3['YYY']
- assert not env.has_key('YYY'), "env has YYY?"
- assert not env2.has_key('YYY'), "env2 has YYY?"
- assert not env3.has_key('YYY'), "env3 has YYY?"
+ assert 'YYY' not in env, "env has YYY?"
+ assert 'YYY' not in env2, "env2 has YYY?"
+ assert 'YYY' not in env3, "env3 has YYY?"
del env3['ZZZ']
- assert not env.has_key('ZZZ'), "env has ZZZ?"
- assert not env2.has_key('ZZZ'), "env2 has ZZZ?"
- assert not env3.has_key('ZZZ'), "env3 has ZZZ?"
+ assert 'ZZZ' not in env, "env has ZZZ?"
+ assert 'ZZZ' not in env2, "env2 has ZZZ?"
+ assert 'ZZZ' not in env3, "env3 has ZZZ?"
def test_get(self):
"""Test the OverrideEnvironment get() method"""
assert env.get('YYY') == 'y', env.get('YYY')
assert env2.get('YYY') == 'y', env2.get('YYY')
assert env3.get('YYY') == 'y3', env3.get('YYY')
- assert env.get('ZZZ') == None, env.get('ZZZ')
- assert env2.get('ZZZ') == None, env2.get('ZZZ')
+ assert env.get('ZZZ') is None, env.get('ZZZ')
+ assert env2.get('ZZZ') is None, env2.get('ZZZ')
assert env3.get('ZZZ') == 'z3', env3.get('ZZZ')
def test_has_key(self):
"""Test the OverrideEnvironment has_key() method"""
env, env2, env3 = self.envs
- assert env.has_key('XXX'), env.has_key('XXX')
- assert env2.has_key('XXX'), env2.has_key('XXX')
- assert env3.has_key('XXX'), env3.has_key('XXX')
- assert env.has_key('YYY'), env.has_key('YYY')
- assert env2.has_key('YYY'), env2.has_key('YYY')
- assert env3.has_key('YYY'), env3.has_key('YYY')
- assert not env.has_key('ZZZ'), env.has_key('ZZZ')
- assert not env2.has_key('ZZZ'), env2.has_key('ZZZ')
- assert env3.has_key('ZZZ'), env3.has_key('ZZZ')
+ assert 'XXX' in env, 'XXX' in env
+ assert 'XXX' in env2, 'XXX' in env2
+ assert 'XXX' in env3, 'XXX' in env3
+ assert 'YYY' in env, 'YYY' in env
+ assert 'YYY' in env2, 'YYY' in env2
+ assert 'YYY' in env3, 'YYY' in env3
+ assert 'ZZZ' not in env, 'ZZZ' in env
+ assert 'ZZZ' not in env2, 'ZZZ' in env2
+ assert 'ZZZ' in env3, 'ZZZ' in env3
+
+ def test_contains(self):
+ """Test the OverrideEnvironment __contains__() method"""
+ try:
+ 'x' in {'x':1}
+ except TypeError:
+ # TODO(1.5)
+ # An early version of Python that doesn't support "in"
+ # on dictionaries. Just pass the test.
+ pass
+ else:
+ env, env2, env3 = self.envs
+ assert 'XXX' in env
+ assert 'XXX' in env2
+ assert 'XXX' in env3
+ assert 'YYY' in env
+ assert 'YYY' in env2
+ assert 'YYY' in env3
+ assert not 'ZZZ' in env
+ assert not 'ZZZ' in env2
+ assert 'ZZZ' in env3
def test_items(self):
"""Test the OverrideEnvironment Dictionary() method"""
x = env3.Split('$AAA')
assert x == ['x3', 'y3', 'z3'], x
+ def test_parse_flags(self):
+ '''Test the OverrideEnvironment parse_flags argument'''
+ # all we have to show is that it gets to MergeFlags internally
+ env = SubstitutionEnvironment()
+ env2 = env.Override({'parse_flags' : '-X'})
+ assert 'CCFLAGS' not in env
+ assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS']
+
+ env = SubstitutionEnvironment(CCFLAGS=None)
+ env2 = env.Override({'parse_flags' : '-Y'})
+ assert env['CCFLAGS'] is None, env['CCFLAGS']
+ assert env2['CCFLAGS'] == ['-Y'], env2['CCFLAGS']
+
+ env = SubstitutionEnvironment(CPPDEFINES = 'FOO')
+ env2 = env.Override({'parse_flags' : '-std=c99 -X -DBAR'})
+ assert 'CFLAGS' not in env
+ assert env2['CFLAGS'] == ['-std=c99'], env2['CFLAGS']
+ assert 'CCFLAGS' not in env
+ assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS']
+ assert env['CPPDEFINES'] == 'FOO', env['CPPDEFINES']
+ assert env2['CPPDEFINES'] == ['FOO','BAR'], env2['CPPDEFINES']
+
class NoSubstitutionProxyTestCase(unittest.TestCase,TestEnvironmentFixture):
args = ('$XXX $TARGET $SOURCE $YYY',)
kw = {'target' : DummyNode('ttt'), 'source' : DummyNode('sss')}
- x = apply(env.subst_target_source, args, kw)
+ x = env.subst_target_source(*args, **kw)
assert x == 'x ttt sss y', x
- x = apply(proxy.subst_target_source, args, kw)
+ x = proxy.subst_target_source(*args, **kw)
assert x == ' ttt sss ', x
+class EnvironmentVariableTestCase(unittest.TestCase):
+
+ def test_is_valid_construction_var(self):
+ """Testing is_valid_construction_var()"""
+ r = is_valid_construction_var("_a")
+ assert r is not None, r
+ r = is_valid_construction_var("z_")
+ assert r is not None, r
+ r = is_valid_construction_var("X_")
+ assert r is not None, r
+ r = is_valid_construction_var("2a")
+ assert r is None, r
+ r = is_valid_construction_var("a2_")
+ assert r is not None, r
+ r = is_valid_construction_var("/")
+ assert r is None, r
+ r = is_valid_construction_var("_/")
+ assert r is None, r
+ r = is_valid_construction_var("a/")
+ assert r is None, r
+ r = is_valid_construction_var(".b")
+ assert r is None, r
+ r = is_valid_construction_var("_.b")
+ assert r is None, r
+ r = is_valid_construction_var("b1._")
+ assert r is None, r
+ r = is_valid_construction_var("-b")
+ assert r is None, r
+ r = is_valid_construction_var("_-b")
+ assert r is None, r
+ r = is_valid_construction_var("b1-_")
+ assert r is None, r
+
if __name__ == "__main__":
tclasses = [ SubstitutionTestCase,
BaseTestCase,
OverrideEnvironmentTestCase,
- NoSubstitutionProxyTestCase ]
+ NoSubstitutionProxyTestCase,
+ EnvironmentVariableTestCase ]
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)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: