__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import string
import UserDict
import SCons.Errors
def get_contents(self):
"""The contents of an alias is the concatenation
of all the contents of its sources"""
- contents = ""
- for kid in self.children(None):
- contents = contents + kid.get_contents()
- return contents
+ contents = map(lambda n: n.get_contents(), self.children(None))
+ return string.join(contents, '')
def sconsign(self):
"""An Alias is not recorded in .sconsign files"""
a2 = ans.Alias('a1')
assert a1 is a2, (a1, a2)
+ def test_get_contents(self):
+ """Test the get_contents() method
+ """
+ class DummyNode:
+ def __init__(self, contents):
+ self.contents = contents
+ def get_contents(self):
+ return self.contents
+
+ ans = SCons.Node.Alias.AliasNameSpace()
+
+ ans.Alias('a1')
+ a = ans.lookup('a1')
+
+ a.sources = [ DummyNode('one'), DummyNode('two'), DummyNode('three') ]
+
+ c = a.get_contents()
+ assert c == 'onetwothree', c
+
def test_lookup(self):
"""Test the lookup() method
"""
directory."""
return self.disambiguate().exists()
+ def missing(self):
+ """Return if the Entry is missing. Check the file system to
+ see what we should turn into first. Assume a file if there's
+ no directory."""
+ return self.disambiguate().missing()
+
+ def get_csig(self):
+ """Return the entry's content signature. Check the file system
+ to see what we should turn into first. Assume a file if there's
+ no directory."""
+ return self.disambiguate().get_csig()
+
def calc_signature(self, calc=None):
"""Return the Entry's calculated signature. Check the file
system to see what we should turn into first. Assume a file if
def get_contents(self):
"""Return aggregate contents of all our children."""
- contents = cStringIO.StringIO()
- for kid in self.children():
- contents.write(kid.get_contents())
- return contents.getvalue()
+ contents = map(lambda n: n.get_contents(), self.children())
+ return string.join(contents, '')
def prepare(self):
pass
pass
else:
setattr(self, attr, map(Entry_func, val))
+ def format(self):
+ result = [ self.ninfo.format() ]
+ bkids = self.bsources + self.bdepends + self.bimplicit
+ bkidsigs = self.bsourcesigs + self.bdependsigs + self.bimplicitsigs
+ for i in xrange(len(bkids)):
+ result.append(str(bkids[i]) + ': ' + bkidsigs[i].format())
+ return string.join(result, '\n')
+
class File(Base):
"""A class for files in a file system.
def test_convert_from_sconsign(self):
"""Test converting from .sconsign file format"""
+ def test_format(self):
+ """Test the format() method"""
+ f1 = self.fs.File('f1')
+ bi1 = SCons.Node.FS.BuildInfo(f1)
+
+ s1sig = SCons.Node.FS.NodeInfo()
+ s1sig.a = 1
+ d1sig = SCons.Node.FS.NodeInfo()
+ d1sig.a = 2
+ i1sig = SCons.Node.FS.NodeInfo()
+ i1sig.a = 3
+
+ bi1.bsources = [self.fs.File('s1')]
+ bi1.bdepends = [self.fs.File('d1')]
+ bi1.bimplicit = [self.fs.File('i1')]
+ bi1.bsourcesigs = [s1sig]
+ bi1.bdependsigs = [d1sig]
+ bi1.bimplicitsigs = [i1sig]
+
+ format = bi1.format()
+ assert format == 'None 0\ns1: 1\nd1: 2\ni1: 3', repr(format)
+
class FSTestCase(_tempdirTestCase):
def test_runTest(self):
"""Test FS (file system) Node operations
self.fs.Entry('#topdir')
self.fs.Entry('#topdir/a/b/c')
+ def test_missing(self):
+ """Test that the Entry.missing() method disambiguates node types"""
+ test = TestCmd(workdir='')
+ # FS doesn't like the cwd to be something other than its root.
+ os.chdir(test.workpath(""))
+
+ fs = SCons.Node.FS.FS()
+
+ test.subdir('emd')
+ test.write('emf', "emf\n")
+
+ emd = fs.Entry('emd')
+ missing = emd.missing()
+ assert emd.__class__ is SCons.Node.FS.Dir, emd.__class__
+ assert not missing
+
+ emf = fs.Entry('emf')
+ missing = emf.missing()
+ assert emf.__class__ is SCons.Node.FS.File, emf.__class__
+ assert not missing
+
+ emn = fs.Entry('emn')
+ missing = emn.missing()
+ assert emn.__class__ is SCons.Node.FS.File, emn.__class__
+ assert missing
+
+ def test_get_csig(self):
+ """Test that the Entry.get_csig() method disambiguates node types"""
+ test = TestCmd(workdir='')
+ # FS doesn't like the cwd to be something other than its root.
+ os.chdir(test.workpath(""))
+
+ fs = SCons.Node.FS.FS()
+
+ test.subdir('egcd')
+ test.write('egcf', "egcf\n")
+
+ egcd = fs.Entry('egcd')
+ egcd.get_csig()
+ assert egcd.__class__ is SCons.Node.FS.Dir, egcd.__class__
+
+ egcf = fs.Entry('egcf')
+ egcf.get_csig()
+ assert egcf.__class__ is SCons.Node.FS.File, egcf.__class__
+
+ egcn = fs.Entry('egcn')
+ egcn.get_csig()
+ assert egcn.__class__ is SCons.Node.FS.File, egcn.__class__
+
class FileTestCase(_tempdirTestCase):
ni = SCons.Node.NodeInfo()
ni.update(SCons.Node.Node())
+ def test_format(self):
+ """Test the NodeInfo.format() method"""
+ ni1 = SCons.Node.NodeInfo()
+ ni1.xxx = 'x'
+ ni1.yyy = 'y'
+ ni1.zzz = 'z'
+
+ f = ni1.format()
+ assert f == 'x y z', f
+
+ ni1.field_list = ['xxx', 'zzz', 'aaa']
+
+ f = ni1.format()
+ assert f == 'x z None', f
+
class BuildInfoTestCase(unittest.TestCase):
-
class NodeTestCase(unittest.TestCase):
def test_build(self):
def merge(self, other):
for key, val in other.__dict__.items():
self.__dict__[key] = val
+ def format(self):
+ try:
+ field_list = self.field_list
+ except AttributeError:
+ field_list = self.__dict__.keys()
+ field_list.sort()
+ fields = []
+ for field in field_list:
+ try:
+ f = getattr(self, field)
+ except AttributeError:
+ f = None
+ fields.append(str(f))
+ return string.join(fields, " ")
class BuildInfo:
"""