def subst(x, env = env):
if SCons.Util.is_String(x):
- return SCons.Util.scons_subst(x, env)
+ return env.subst(x)
else:
return x
def test_subst(self):
"""Test substituting construction variables within strings
-
+
Check various combinations, including recursive expansion
of variables into other variables.
"""
clazz=SCons.Node.FS.Dir,
must_exist=0,
cwd=SCons.Node.FS.default_fs.Dir('xx'))
-
+
env = Environment(LIBS = [ 'foo', 'bar', 'baz' ],
LIBLINKPREFIX = 'foo',
LIBLINKSUFFIX = 'bar',
env = Environment(tools = [t1, t2, t3], XYZ = 'aaa')
assert env['TOOL1'] == 111, env['TOOL1']
assert env['TOOL2'] == 222, env
- assert env['AAA'] == 'aaa', env
+ assert env['AAA'] == 'aaa', env
t4(env)
assert env['TOOL4'] == 444, env
-
+
def test_Default_TOOLS(self):
"""Test overriding the default TOOLS variable"""
def t5(env):
env = Environment(XYZ = 'bbb')
assert env['TOOL5'] == 555, env['TOOL5']
assert env['TOOL6'] == 666, env
- assert env['BBB'] == 'bbb', env
+ assert env['BBB'] == 'bbb', env
t8(env)
assert env['TOOL8'] == 888, env
finally:
env1 = Environment(tools=[foo])
env2 = env1.Copy()
env3 = env1.Copy(tools=[bar, baz])
-
+
assert env1.get('FOO') is 1
assert env1.get('BAR') is None
assert env1.get('BAZ') is None
def test_FindIxes(self):
"Test FindIxes()"
- env = Environment(LIBPREFIX='lib',
+ env = Environment(LIBPREFIX='lib',
LIBSUFFIX='.a',
- SHLIBPREFIX='lib',
+ SHLIBPREFIX='lib',
SHLIBSUFFIX='.so',
PREFIX='pre',
SUFFIX='post')
env1 = Environment(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\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 = ';')
env1 = Environment(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\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 = ';')
def test_ReplaceIxes(self):
"Test ReplaceIxes()"
- env = Environment(LIBPREFIX='lib',
+ env = Environment(LIBPREFIX='lib',
LIBSUFFIX='.a',
- SHLIBPREFIX='lib',
+ SHLIBPREFIX='lib',
SHLIBSUFFIX='.so',
PREFIX='pre',
SUFFIX='post')
-
- assert 'libfoo.a' == env.ReplaceIxes('libfoo.so',
+
+ assert 'libfoo.a' == env.ReplaceIxes('libfoo.so',
'SHLIBPREFIX', 'SHLIBSUFFIX',
'LIBPREFIX', 'LIBSUFFIX')
-
+
assert os.path.join('dir', 'libfoo.a') == env.ReplaceIxes(os.path.join('dir', 'libfoo.so'),
'SHLIBPREFIX', 'SHLIBSUFFIX',
'LIBPREFIX', 'LIBSUFFIX')
- assert 'libfoo.a' == env.ReplaceIxes('prefoopost',
+ assert 'libfoo.a' == env.ReplaceIxes('prefoopost',
'PREFIX', 'SUFFIX',
'LIBPREFIX', 'LIBSUFFIX')
f=fs.Entry('foo/bar/baz.blat').get_subst_proxy()
assert str(f.dir) == os.path.normpath('foo/bar'), str(f.dir)
- assert f.dir.is_literal()
+ assert f.dir.is_literal(), f.dir
assert f.dir.for_signature() == 'bar', f.dir.for_signature()
assert str(f.file) == 'baz.blat', str(f.file)
- assert f.file.is_literal()
+ assert f.file.is_literal(), f.file
assert f.file.for_signature() == 'baz.blat_file', \
f.file.for_signature()
assert str(f.base) == os.path.normpath('foo/bar/baz'), str(f.base)
- assert f.base.is_literal()
+ assert f.base.is_literal(), f.base
assert f.base.for_signature() == 'baz.blat_base', \
f.base.for_signature()
assert str(f.filebase) == 'baz', str(f.filebase)
- assert f.filebase.is_literal()
+ assert f.filebase.is_literal(), f.filebase
assert f.filebase.for_signature() == 'baz.blat_filebase', \
f.filebase.for_signature()
assert str(f.suffix) == '.blat', str(f.suffix)
- assert f.suffix.is_literal()
+ assert f.suffix.is_literal(), f.suffix
assert f.suffix.for_signature() == 'baz.blat_suffix', \
f.suffix.for_signature()
assert str(f.abspath) == test.workpath('foo', 'bar', 'baz.blat'), str(f.abspath)
- assert f.abspath.is_literal()
+ assert f.abspath.is_literal(), f.abspath
assert f.abspath.for_signature() == 'baz.blat_abspath', \
f.abspath.for_signature()
assert str(f.posix) == 'foo/bar/baz.blat', str(f.posix)
- assert f.posix.is_literal()
+ assert f.posix.is_literal(), f.posix
if f.posix != f:
assert f.posix.for_signature() == 'baz.blat_posix', \
f.posix.for_signature()
fs.BuildDir('foo', 'baz')
assert str(f.srcpath) == os.path.normpath('baz/bar/baz.blat'), str(f.srcpath)
- assert f.srcpath.is_literal()
+ assert f.srcpath.is_literal(), f.srcpath
assert isinstance(f.srcpath.get(), SCons.Node.FS.Entry)
assert str(f.srcdir) == os.path.normpath('baz/bar'), str(f.srcdir)
- assert f.srcdir.is_literal()
+ assert f.srcdir.is_literal(), f.srcdir
assert isinstance(f.srcdir.get(), SCons.Node.FS.Dir)
# And now, combinations!!!
class MyAction:
def __init__(self):
self.order = 0
-
+
def __call__(self, target, source, env):
global built_it, built_target, built_source, built_args, built_order
built_it = 1
"""
n = SCons.Node.Node()
n.visited()
-
+
def test_depends_on(self):
"""Test the depends_on() method
"""
child = SCons.Node.Node()
parent.add_dependency([child])
assert parent.depends_on([child])
-
+
def test_builder_set(self):
"""Test setting a Node's Builder
"""
n4 = MyNode()
node.implicit = []
node.implicit_dict = {}
- node._add_child(node.implicit, node.implicit_dict, [n4])
+ node._add_child(node.implicit, node.implicit_dict, [n4])
exc_caught = 0
try:
node.prepare()
def for_signature(self):
return self.sig
-
+
n = TestNode("foo", "bar")
assert n.get_string(0) == "foo", n.get_string(0)
assert n.get_string(1) == "bar", n.get_string(1)
- def test_arg2nodes(self):
- """Test the arg2nodes function."""
- dict = {}
- class X(SCons.Node.Node):
- pass
- def Factory(name, directory = None, create = 1, dict=dict, X=X):
- if not dict.has_key(name):
- dict[name] = X()
- dict[name].name = name
- return dict[name]
-
- nodes = SCons.Node.arg2nodes("Util.py UtilTests.py", Factory)
- assert len(nodes) == 1, nodes
- assert isinstance(nodes[0], X)
- assert nodes[0].name == "Util.py UtilTests.py"
-
- if hasattr(types, 'UnicodeType'):
- code = """if 1:
- nodes = SCons.Node.arg2nodes(u"Util.py UtilTests.py", Factory)
- assert len(nodes) == 1, nodes
- assert isinstance(nodes[0], X)
- assert nodes[0].name == u"Util.py UtilTests.py"
- \n"""
- exec code in globals(), locals()
-
- nodes = SCons.Node.arg2nodes(["Util.py", "UtilTests.py"], Factory)
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], X)
- assert isinstance(nodes[1], X)
- assert nodes[0].name == "Util.py"
- assert nodes[1].name == "UtilTests.py"
-
- n1 = Factory("Util.py")
- nodes = SCons.Node.arg2nodes([n1, "UtilTests.py"], Factory)
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], X)
- assert isinstance(nodes[1], X)
- assert nodes[0].name == "Util.py"
- assert nodes[1].name == "UtilTests.py"
-
- class SConsNode(SCons.Node.Node):
- pass
- nodes = SCons.Node.arg2nodes(SConsNode())
- assert len(nodes) == 1, nodes
- assert isinstance(nodes[0], SConsNode), node
-
- class OtherNode:
- pass
- nodes = SCons.Node.arg2nodes(OtherNode())
- assert len(nodes) == 1, nodes
- assert isinstance(nodes[0], OtherNode), node
-
- def lookup_a(str, F=Factory):
- if str[0] == 'a':
- n = F(str)
- n.a = 1
- return n
- else:
- return None
-
- def lookup_b(str, F=Factory):
- if str[0] == 'b':
- n = F(str)
- n.b = 1
- return n
- else:
- return None
-
- SCons.Node.arg2nodes_lookups.append(lookup_a)
- SCons.Node.arg2nodes_lookups.append(lookup_b)
-
- nodes = SCons.Node.arg2nodes(['aaa', 'bbb', 'ccc'], Factory)
- assert len(nodes) == 3, nodes
-
- assert nodes[0].name == 'aaa', nodes[0]
- assert nodes[0].a == 1, nodes[0]
- assert not hasattr(nodes[0], 'b'), nodes[0]
-
- assert nodes[1].name == 'bbb'
- assert not hasattr(nodes[1], 'a'), nodes[1]
- assert nodes[1].b == 1, nodes[1]
-
- assert nodes[2].name == 'ccc'
- assert not hasattr(nodes[2], 'a'), nodes[1]
- assert not hasattr(nodes[2], 'b'), nodes[1]
-
- def lookup_bbbb(str, F=Factory):
- if str == 'bbbb':
- n = F(str)
- n.bbbb = 1
- return n
- else:
- return None
-
- def lookup_c(str, F=Factory):
- if str[0] == 'c':
- n = F(str)
- n.c = 1
- return n
- else:
- return None
-
- nodes = SCons.Node.arg2nodes(['bbbb', 'ccc'], Factory,
- [lookup_c, lookup_bbbb, lookup_b])
- assert len(nodes) == 2, nodes
-
- assert nodes[0].name == 'bbbb'
- assert not hasattr(nodes[0], 'a'), nodes[1]
- assert not hasattr(nodes[0], 'b'), nodes[1]
- assert nodes[0].bbbb == 1, nodes[1]
- assert not hasattr(nodes[0], 'c'), nodes[0]
-
- assert nodes[1].name == 'ccc'
- assert not hasattr(nodes[1], 'a'), nodes[1]
- assert not hasattr(nodes[1], 'b'), nodes[1]
- assert not hasattr(nodes[1], 'bbbb'), nodes[0]
- assert nodes[1].c == 1, nodes[1]
-
def test_literal(self):
"""Test the is_literal() function."""
n=SCons.Node.Node()
assert n.is_literal()
-
+
def test_Annotate(self):
"""Test using an interface-specific Annotate function."""
def my_annotate(node, self=self):
arg2nodes_lookups = []
-
-def arg2nodes(args, node_factory=None, lookup_list=arg2nodes_lookups):
- """This function converts a string or list into a list of Node
- instances. It accepts the following inputs:
- - A single string,
- - A single Node instance,
- - A list containing either strings or Node instances.
- In all cases, strings are converted to Node instances, and the
- function returns a list of Node instances."""
-
- if not args:
- return []
- if not SCons.Util.is_List(args):
- args = [args]
-
- nodes = []
- for v in args:
- if SCons.Util.is_String(v):
- n = None
- for l in lookup_list:
- n = l(v)
- if not n is None:
- break
- if not n is None:
- if SCons.Util.is_String(n) and node_factory:
- n = node_factory(n)
- nodes.append(n)
- elif node_factory:
- nodes.append(node_factory(v))
- # Do we enforce the following restriction? Maybe, but it
- # would also restrict what we can do to allow people to
- # use the engine with alternate Node implementations...
- #elif not issubclass(v.__class__, Node):
- # raise TypeError
- else:
- nodes.append(v)
-
- return nodes