"""TestRuntest.py: a testing framework for the runtest.py command used toinvoke SCons tests.A TestRuntest environment object is created via the usual invocation: test = TestRuntest()TestRuntest is a subclass of TestCommon, which is in turn is a subclassof TestCmd), and hence has available all of the methods and attributesfrom those classes, as well as any overridden or additional methods orattributes defined in this subclass."""# __COPYRIGHT____revision__="__FILE__ __REVISION__ __DATE__ __DEVELOPER__"importosimportos.pathimportreimportshutilimportsysfromTestCommonimport*fromTestCommonimport__all____all__.extend(['TestRuntest','pythonstring',])ifre.search('\s',python):pythonstring=_python_else:pythonstring=pythonpythonstring=pythonstring.replace('\\','\\\\')failing_test_template="""\import syssys.stdout.write('FAILING TEST STDOUT\\n')sys.stderr.write('FAILING TEST STDERR\\n')sys.exit(1)"""no_result_test_template="""\import syssys.stdout.write('NO RESULT TEST STDOUT\\n')sys.stderr.write('NO RESULT TEST STDERR\\n')sys.exit(2)"""passing_test_template="""\import syssys.stdout.write('PASSING TEST STDOUT\\n')sys.stderr.write('PASSING TEST STDERR\\n')sys.exit(0)"""fake_scons_py="""__version__ = '1.2.3'__build__ = 'D123'__buildsys__ = 'fake_system'__date__ = 'Jan 1 1970'__developer__ = 'Anonymous'"""fake___init___py="""__version__ = '4.5.6'__build__ = 'D456'__buildsys__ = 'another_fake_system'__date__ = 'Dec 31 1999'__developer__ = 'John Doe'"""classTestRuntest(TestCommon):"""Class for testing the runtest.py script. This provides a common place for initializing Runtest tests, eliminating the need to begin every test with the same repeated initializations. """def__init__(self,**kw):"""Initialize a Runtest testing object. If they're not overridden by keyword arguments, this initializes the object with the following default values: program = 'runtest.py' interpreter = ['python', '-tt'] match = match_exact workdir = '' The workdir value means that, by default, a temporary workspace directory is created for a TestRuntest environment. The superclass TestCommon.__init__() will change directory (chdir) to the workspace directory, so an explicit "chdir = '.'" on all of the run() method calls is not necessary. This initialization also copies the runtest.py and QMTest/ subdirectory tree to the temporary directory, duplicating how this test infrastructure appears in a normal workspace. """if'program'notinkw:kw['program']='runtest.py'if'interpreter'notinkw:kw['interpreter']=[python,'-tt']if'match'notinkw:kw['match']=match_exactif'workdir'notinkw:kw['workdir']=''try:things_to_copy=kw['things_to_copy']exceptKeyError:things_to_copy=['runtest.py','QMTest',]else:delkw['things_to_copy']orig_cwd=os.getcwd()TestCommon.__init__(self,**kw)dirs=[os.environ.get('SCONS_RUNTEST_DIR',orig_cwd)]spe=os.environ.get('SCONS_SOURCE_PATH_EXECUTABLE',orig_cwd)fordinspe.split(os.pathsep):dirs.append(os.path.join(d,'build'))dirs.append(d)forthinginthings_to_copy:fordirindirs:t=os.path.join(dir,thing)ifos.path.exists(t):ifos.path.isdir(t):copy_func=shutil.copytreeelse:copy_func=shutil.copyfilecopy_func(t,self.workpath(thing))breakself.program_set(self.workpath(kw['program']))forkeyinos.environ.keys():ifkey[:5]=='AEGIS':os.environ[key]=''os.environ['PYTHONPATH']=''os.environ['SCONS_SOURCE_PATH_EXECUTABLE']=''defwrite_fake_scons_source_tree(self):os.mkdir('src')os.mkdir('src/script')self.write('src/script/scons.py',fake_scons_py)os.mkdir('src/engine')os.mkdir('src/engine/SCons')self.write('src/engine/SCons/__init__.py',fake___init___py)os.mkdir('src/engine/SCons/Script')self.write('src/engine/SCons/Script/__init__.py',fake___init___py)defwrite_failing_test(self,name):self.write(name,failing_test_template)defwrite_no_result_test(self,name):self.write(name,no_result_test_template)defwrite_passing_test(self,name):self.write(name,passing_test_template)# Local Variables:# tab-width:4# indent-tabs-mode:nil# End:# vim: set expandtab tabstop=4 shiftwidth=4: