diff options
author | Steven Knight <knight@baldmt.com> | 2004-09-25 21:57:33 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2004-09-25 21:57:33 (GMT) |
commit | 898eef1827833249cec50c781e71cb4e3b469a33 (patch) | |
tree | 5883e57764e409e69d9b2c93c4b0d0f73c4267a6 | |
parent | ad257d2483736b6e9461a26a62048ac05dafe3b6 (diff) | |
download | SCons-898eef1827833249cec50c781e71cb4e3b469a33.zip SCons-898eef1827833249cec50c781e71cb4e3b469a33.tar.gz SCons-898eef1827833249cec50c781e71cb4e3b469a33.tar.bz2 |
Update Scanner pydoc, enhance tests. (Kevin Quick)
-rw-r--r-- | src/CHANGES.txt | 2 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 58 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 15 |
3 files changed, 52 insertions, 23 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index aa9a71e..52bb9e8 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -165,6 +165,8 @@ RELEASE 0.97 - XXX - Use the source_scanner from the target Node, not the source node itself. + - Enforce internally that Scanners are only passed Nodes. + From Christoph Wiedemann: - Add an Environment.SetDefault() method that only sets values if diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index e0c1f58..3c460c2 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -49,6 +49,14 @@ class DummyEnvironment(UserDict.UserDict): def get_calculator(self): return SCons.Sig.default_calc +class DummyNode: + def __init__(self, name): + self.name = name + def rexists(self): + return None + def __str__(self): + return self.name + class FindPathDirsTestCase(unittest.TestCase): def test_FindPathDirs(self): """Test the FindPathDirs callable class""" @@ -108,22 +116,23 @@ class BaseTestCase(unittest.TestCase): s = SCons.Scanner.Base(self.func, "Pos") env = DummyEnvironment() env.VARIABLE = "var1" - self.test(s, env, 'f1.cpp', ['f1.h', 'f1.hpp']) + self.test(s, env, DummyNode('f1.cpp'), ['f1.h', 'f1.hpp']) env = DummyEnvironment() env.VARIABLE = "i1" - self.test(s, env, 'i1.cpp', ['i1.h', 'i1.hpp']) + self.test(s, env, DummyNode('i1.cpp'), ['i1.h', 'i1.hpp']) def test_keywords(self): """Test the Scanner.Base class using keyword arguments""" s = SCons.Scanner.Base(function = self.func, name = "Key") env = DummyEnvironment() env.VARIABLE = "var2" - self.test(s, env, 'f2.cpp', ['f2.h', 'f2.hpp']) + self.test(s, env, DummyNode('f2.cpp'), ['f2.h', 'f2.hpp']) env = DummyEnvironment() env.VARIABLE = "i2" - self.test(s, env, 'i2.cpp', ['i2.h', 'i2.hpp']) + + self.test(s, env, DummyNode('i2.cpp'), ['i2.h', 'i2.hpp']) def test_pos_opt(self): """Test the Scanner.Base class using both position and optional arguments""" @@ -131,11 +140,11 @@ class BaseTestCase(unittest.TestCase): s = SCons.Scanner.Base(self.func, "PosArg", arg) env = DummyEnvironment() env.VARIABLE = "var3" - self.test(s, env, 'f3.cpp', ['f3.h', 'f3.hpp'], arg) + self.test(s, env, DummyNode('f3.cpp'), ['f3.h', 'f3.hpp'], arg) env = DummyEnvironment() env.VARIABLE = "i3" - self.test(s, env, 'i3.cpp', ['i3.h', 'i3.hpp'], arg) + self.test(s, env, DummyNode('i3.cpp'), ['i3.h', 'i3.hpp'], arg) def test_key_opt(self): """Test the Scanner.Base class using both keyword and optional arguments""" @@ -144,11 +153,11 @@ class BaseTestCase(unittest.TestCase): argument = arg) env = DummyEnvironment() env.VARIABLE = "var4" - self.test(s, env, 'f4.cpp', ['f4.h', 'f4.hpp'], arg) + self.test(s, env, DummyNode('f4.cpp'), ['f4.h', 'f4.hpp'], arg) env = DummyEnvironment() env.VARIABLE = "i4" - self.test(s, env, 'i4.cpp', ['i4.h', 'i4.hpp'], arg) + self.test(s, env, DummyNode('i4.cpp'), ['i4.h', 'i4.hpp'], arg) def test_hash(self): """Test the Scanner.Base class __hash__() method""" @@ -163,13 +172,13 @@ class BaseTestCase(unittest.TestCase): def my_scan(filename, env, target, *args): return [] def check(node, env, s=self): - s.checked[node] = 1 + s.checked[str(node)] = 1 return 1 env = DummyEnvironment() s = SCons.Scanner.Base(my_scan, "Check", scan_check = check) self.checked = {} path = s.path(env) - scanned = s('x', env, path) + scanned = s(DummyNode('x'), env, path) self.failUnless(self.checked['x'] == 1, "did not call check function") @@ -209,12 +218,23 @@ class BaseTestCase(unittest.TestCase): s = scanner.select('.x') assert s is scanner, s + def test___str__(self): + """Test the Scanner.Base __str__() method""" + scanner = SCons.Scanner.Base(function = self.func) + s = str(scanner) + assert s == 'NONE', s + scanner = SCons.Scanner.Base(function = self.func, name = 'xyzzy') + s = str(scanner) + assert s == 'xyzzy', s + class SelectorTestCase(unittest.TestCase): - class skey: + class skey_node: def __init__(self, key): self.key = key def scanner_key(self): return self.key + def rexists(self): + return None def test___init__(self): """Test creation of Scanner.Selector object""" @@ -236,31 +256,31 @@ class SelectorTestCase(unittest.TestCase): s1 = SCons.Scanner.Base(s1func) s2 = SCons.Scanner.Base(s2func) selector = SCons.Scanner.Selector({'.x' : s1, '.y' : s2}) - nx = self.skey('.x') + nx = self.skey_node('.x') selector(nx, None, []) assert called == ['s1func', nx], called del called[:] - ny = self.skey('.y') + ny = self.skey_node('.y') selector(ny, None, []) assert called == ['s2func', ny], called def test_select(self): """Test the Scanner.Selector select() method""" selector = SCons.Scanner.Selector({'.x' : 1, '.y' : 2}) - s = selector.select(self.skey('.x')) + s = selector.select(self.skey_node('.x')) assert s == 1, s - s = selector.select(self.skey('.y')) + s = selector.select(self.skey_node('.y')) assert s == 2, s - s = selector.select(self.skey('.z')) + s = selector.select(self.skey_node('.z')) assert s is None, s def test_add_scanner(self): """Test the Scanner.Selector add_scanner() method""" selector = SCons.Scanner.Selector({'.x' : 1, '.y' : 2}) - s = selector.select(self.skey('.z')) + s = selector.select(self.skey_node('.z')) assert s is None, s selector.add_scanner('.z', 3) - s = selector.select(self.skey('.z')) + s = selector.select(self.skey_node('.z')) assert s == 3, s class CurrentTestCase(unittest.TestCase): @@ -271,6 +291,8 @@ class CurrentTestCase(unittest.TestCase): self.called_has_builder = None self.called_current = None self.func_called = None + def rexists(self): + return None class HasNoBuilder(MyNode): def has_builder(self): self.called_has_builder = 1 diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index f865efc..f134b2d 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -151,11 +151,13 @@ class Base: recursively on the implicit dependencies it returns (the canonical example being #include lines in C source files). - The scanner function's first argument will be the name of a file - that should be scanned for dependencies, the second argument will - be an Environment object, the third argument will be the value - passed into 'argument', and the returned list should contain the - Nodes for all the direct dependencies of the file. + The scanner function's first argument will be the a Node that + should be scanned for dependencies, the second argument will + be an Environment object, the third argument will be the tuple + of paths returned by the path_function, and the fourth + argument will be the value passed into 'argument', and the + returned list should contain the Nodes for all the direct + dependencies of the file. Examples: @@ -220,6 +222,9 @@ class Base: def __hash__(self): return id(self) + def __str__(self): + return self.name + def add_skey(self, skey): """Add a skey to the list of skeys""" self.skeys.append(skey) |