2 TestRuntest.py: a testing framework for the runtest.py command used to
5 A TestRuntest environment object is created via the usual invocation:
9 TestRuntest is a subclass of TestCommon, which is in turn is a subclass
10 of TestCmd), and hence has available all of the methods and attributes
11 from those classes, as well as any overridden or additional methods or
12 attributes defined in this subclass.
17 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25 from TestCommon import *
26 from TestCommon import __all__
28 __all__.extend([ 'TestRuntest',
33 python = python_executable
34 _python_ = '"' + python_executable + '"'
37 failing_test_template = """\
39 sys.stdout.write('FAILING TEST STDOUT\\n')
40 sys.stderr.write('FAILING TEST STDERR\\n')
44 no_result_test_template = """\
46 sys.stdout.write('NO RESULT TEST STDOUT\\n')
47 sys.stderr.write('NO RESULT TEST STDERR\\n')
51 passing_test_template = """\
53 sys.stdout.write('PASSING TEST STDOUT\\n')
54 sys.stderr.write('PASSING TEST STDERR\\n')
61 __buildsys__ = 'fake_system'
62 __date__ = 'Jan 1 1970'
63 __developer__ = 'Anonymous'
66 fake___init___py = """
69 __buildsys__ = 'another_fake_system'
70 __date__ = 'Dec 31 1999'
71 __developer__ = 'John Doe'
74 class TestRuntest(TestCommon):
75 """Class for testing the runtest.py script.
77 This provides a common place for initializing Runtest tests,
78 eliminating the need to begin every test with the same repeated
82 def __init__(self, **kw):
83 """Initialize a Runtest testing object.
85 If they're not overridden by keyword arguments, this
86 initializes the object with the following default values:
88 program = 'runtest.py'
89 interpreter = ['python', '-tt']
93 The workdir value means that, by default, a temporary
94 workspace directory is created for a TestRuntest environment.
95 The superclass TestCommon.__init__() will change directory (chdir)
96 to the workspace directory, so an explicit "chdir = '.'" on all
97 of the run() method calls is not necessary. This initialization
98 also copies the runtest.py and QMTest/ subdirectory tree to the
99 temporary directory, duplicating how this test infrastructure
100 appears in a normal workspace.
102 set_workpath_runtest = None
103 if not kw.has_key('program'):
104 kw['program'] = 'runtest.py'
105 set_workpath_runtest = 1
106 if not kw.has_key('interpreter'):
107 kw['interpreter'] = [python, '-tt']
108 if not kw.has_key('match'):
109 kw['match'] = match_exact
110 if not kw.has_key('workdir'):
114 noqmtest = kw['noqmtest']
120 orig_cwd = os.getcwd()
121 apply(TestCommon.__init__, [self], kw)
124 qmtest = self.where_is('qmtest')
126 self.skip_test("Could not find 'qmtest'; skipping test(s).\n")
133 dirs = [os.environ.get('SCONS_RUNTEST_DIR', orig_cwd)]
135 spe = os.environ.get('SCONS_SOURCE_PATH_EXECUTABLE', orig_cwd)
136 for d in string.split(spe, os.pathsep):
137 dirs.append(os.path.join(d, 'build'))
140 for thing in things_to_copy:
142 t = os.path.join(dir, thing)
143 if os.path.exists(t):
145 copy_func = shutil.copytree
147 copy_func = shutil.copyfile
148 copy_func(t, self.workpath(thing))
151 if set_workpath_runtest:
152 self.program_set(self.workpath('runtest.py'))
154 for key in os.environ.keys():
155 if key[:5] == 'AEGIS':
158 os.environ['PYTHONPATH'] = ''
159 os.environ['SCONS_SOURCE_PATH_EXECUTABLE'] = ''
161 def write_fake_scons_source_tree(self):
163 os.mkdir('src/script')
164 self.write('src/script/scons.py', fake_scons_py)
166 os.mkdir('src/engine')
167 os.mkdir('src/engine/SCons')
168 self.write('src/engine/SCons/__init__.py', fake___init___py)
169 os.mkdir('src/engine/SCons/Script')
170 self.write('src/engine/SCons/Script/__init__.py', fake___init___py)
172 def write_failing_test(self, name):
173 self.write(name, failing_test_template)
175 def write_no_result_test(self, name):
176 self.write(name, no_result_test_template)
178 def write_passing_test(self, name):
179 self.write(name, passing_test_template)
183 # indent-tabs-mode:nil
185 # vim: set expandtab tabstop=4 shiftwidth=4: