Towards issue 2336: Rename the compat/builtins.py module to
[scons.git] / QMTest / TestSConsign.py
1 # __COPYRIGHT__
2
3 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
4
5 __doc__ = """
6 TestSConsign.py:  a testing framework for the "sconsign" script 
7 tool.
8
9 A TestSConsign environment object is created via the usual invocation:
10
11     test = TestSConsign()
12
13 TestSconsign is a subclass of TestSCons, which is a subclass of
14 TestCommon, which is in turn is a subclass of TestCmd), and hence
15 has available all of the methods and attributes from those classes,
16 as well as any overridden or additional methods or attributes defined
17 in this subclass.
18 """
19
20 import os
21 import os.path
22 import sys
23
24 from TestSCons import *
25 from TestSCons import __all__
26
27 __all__.extend([ 'TestSConsign', ])
28
29 class TestSConsign(TestSCons):
30     """Class for testing the sconsign.py script.
31
32     This provides a common place for initializing sconsign tests,
33     eliminating the need to begin every test with the same repeated
34     initializations.
35
36     This adds additional methods for running the sconsign script
37     without changing the basic ability of the run() method to run
38     "scons" itself, since we need to run scons to generate the
39     .sconsign files that we want the sconsign script to read.
40     """
41     def __init__(self, *args, **kw):
42         try:
43             script_dir = os.environ['SCONS_SCRIPT_DIR']
44         except KeyError:
45             pass
46         else:
47             os.chdir(script_dir)
48         self.script_dir = os.getcwd()
49
50         TestSCons.__init__(self, *args, **kw)
51
52         self.my_kw = {
53             'interpreter' : python,     # imported from TestSCons
54         }
55
56         if 'program' not in kw:
57             kw['program'] = os.environ.get('SCONS')
58             if not kw['program']:
59                 if os.path.exists('scons'):
60                     kw['program'] = 'scons'
61                 else:
62                     kw['program'] = 'scons.py'
63
64         sconsign = os.environ.get('SCONSIGN')
65         if not sconsign:
66             if os.path.exists(self.script_path('sconsign.py')):
67                 sconsign = 'sconsign.py'
68             elif os.path.exists(self.script_path('sconsign')):
69                 sconsign = 'sconsign'
70             else:
71                 print "Can find neither 'sconsign.py' nor 'sconsign' scripts."
72                 self.no_result()
73         self.set_sconsign(sconsign)
74
75     def script_path(self, script):
76         return os.path.join(self.script_dir, script)
77
78     def set_sconsign(self, sconsign):
79         self.my_kw['program'] = sconsign
80
81     def run_sconsign(self, *args, **kw):
82         kw.update(self.my_kw)
83         return self.run(*args, **kw)
84
85 # Local Variables:
86 # tab-width:4
87 # indent-tabs-mode:nil
88 # End:
89 # vim: set expandtab tabstop=4 shiftwidth=4: