Source

SCons / src / scons / Scanner / ScannerTests.py

__revision__ = "Scanner/ScannerTests.py __REVISION__ __DATE__ __DEVELOPER__"

import unittest
import scons.Scanner
import sys

class ScannerTestBase:
    
    def func(self, filename, env):
        self.filename = filename
        self.env = env
        return self.deps

    def error_func(self, filename, env):
        self.fail("the wrong function was called")

    def test(self, scanner, env, filename, deps):
        self.deps = deps
        deps = scanner.scan(filename, env)

        self.failUnless(self.filename == filename, "the filename was passed incorrectly")
        self.failUnless(self.env == env, "the environment was passed incorrectly")
        self.failUnless(self.deps == deps, "the dependencies were returned incorrectly")

class DummyEnvironment:
    pass


class ScannerPositionalTestCase(ScannerTestBase, unittest.TestCase):
    "Test the Scanner class using the position argument"
    def runTest(self):
        s = scons.Scanner.Scanner(self.func)
        env = DummyEnvironment()
        env.ARGUMENT = "arg1"
        self.test(s, env, 'f1.cpp', ['f1.h', 'f2.h'])

class ScannerKeywordTestCase(ScannerTestBase, unittest.TestCase):
    "Test the Scanner class using the keyword argument"
    def runTest(self):
        s = scons.Scanner.Scanner(function = self.func)
        env = DummyEnvironment()
        env.ARGUMENT = "arg1"
        self.test(s, env, 'f1.cpp', ['f1.h', 'f2.h'])

def suite():
    suite = unittest.TestSuite()
    suite.addTest(ScannerPositionalTestCase())
    suite.addTest(ScannerKeywordTestCase())
    return suite

if __name__ == "__main__":
    runner = unittest.TextTestRunner()
    result = runner.run(suite())
    if not result.wasSuccessful():
        sys.exit(1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.