diff options
author | dirkbaechle <devnull@localhost> | 2012-08-03 21:01:53 (GMT) |
---|---|---|
committer | dirkbaechle <devnull@localhost> | 2012-08-03 21:01:53 (GMT) |
commit | 4d8c8379e1d4c7860a1c1d29b7302b394c920844 (patch) | |
tree | 30339b821646f25aa0b03076722b8effc821b7eb /QMTest | |
parent | e5ed166538a2e12893346f9778cba8037f2dd847 (diff) | |
download | SCons-4d8c8379e1d4c7860a1c1d29b7302b394c920844.zip SCons-4d8c8379e1d4c7860a1c1d29b7302b394c920844.tar.gz SCons-4d8c8379e1d4c7860a1c1d29b7302b394c920844.tar.bz2 |
- basic merge with source from the external scons-test-framework
Diffstat (limited to 'QMTest')
-rw-r--r-- | QMTest/TestCmd.py | 124 | ||||
-rw-r--r-- | QMTest/TestSCons.py | 170 |
2 files changed, 225 insertions, 69 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index a27df27..8d382ce 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -897,6 +897,11 @@ class TestCmd(object): combine = 0, universal_newlines = 1, timeout = None): + self.external = 0 + try: + self.external = os.environ.get('SCONS_EXTERNAL_TEST', 0) + except KeyError: + pass self._cwd = os.getcwd() self.description_set(description) self.program_set(program) @@ -1009,13 +1014,19 @@ class TestCmd(object): def command_args(self, program = None, interpreter = None, arguments = None): - if program: - if isinstance(program, str) and not os.path.isabs(program): - program = os.path.join(self._cwd, program) + if not self.external: + if program: + if isinstance(program, str) and not os.path.isabs(program): + program = os.path.join(self._cwd, program) + else: + program = self.program + if not interpreter: + interpreter = self.interpreter else: - program = self.program - if not interpreter: - interpreter = self.interpreter + if not program: + program = self.program + if not interpreter: + interpreter = self.interpreter if not isinstance(program, (list, tuple)): program = [program] cmd = list(program) @@ -1189,8 +1200,9 @@ class TestCmd(object): def program_set(self, program): """Set the executable program or script to be tested. """ - if program and not os.path.isabs(program): - program = os.path.join(self._cwd, program) + if not self.external: + if program and not os.path.isabs(program): + program = os.path.join(self._cwd, program) self.program = program def read(self, file, mode = 'rb'): @@ -1227,6 +1239,96 @@ class TestCmd(object): self.timeout = timeout self.timer = None + def parse_path(self, path, suppress_current=False): + """Return a list with the single path components of path. + """ + head, tail = os.path.split(path) + result = [] + if not tail: + if head == path: + return [head] + else: + result.append(tail) + head, tail = os.path.split(head) + while head and tail: + result.append(tail) + head, tail = os.path.split(head) + result.append(head or tail) + result.reverse() + + return result + + def dir_fixture(self, srcdir, dstdir=None): + """Copies the contents of the specified folder srcdir from + the directory of the called script, to the current + working directory. + The srcdir name may be a list, in which case the elements are + concatenated with the os.path.join() method. The dstdir is + assumed to be under the temporary working directory, it gets + created automatically, if it does not already exist. + """ + if srcdir and self.script_srcdir and not os.path.isabs(srcdir): + spath = os.path.join(self.script_srcdir, srcdir) + else: + spath = srcdir + if dstdir: + dstdir = self.canonicalize(dstdir) + else: + dstdir = '.' + + if dstdir != '.' and not os.path.exists(dstdir): + dstlist = self.parse_path(dstdir) + if len(dstlist) > 0 and dstlist[0] == ".": + dstlist = dstlist[1:] + for idx in range(len(dstlist)): + self.subdir(dstlist[:idx+1]) + + if dstdir and self.workdir: + dstdir = os.path.join(self.workdir, dstdir) + + for entry in os.listdir(spath): + epath = os.path.join(spath, entry) + dpath = os.path.join(dstdir, entry) + if os.path.isdir(epath): + # Copy the subfolder + shutil.copytree(epath, dpath) + else: + shutil.copy(epath, dpath) + + def file_fixture(self, srcfile, dstfile=None): + """Copies the file srcfile from the directory of + the called script, to the current working directory. + The dstfile is assumed to be under the temporary working + directory unless it is an absolute path name. + If dstfile is specified its target directory gets created + automatically, if it does not already exist. + """ + srcpath, srctail = os.path.split(srcfile) + if srcpath: + if self.script_srcdir and not os.path.isabs(srcpath): + spath = os.path.join(self.script_srcdir, srcfile) + else: + spath = srcfile + else: + spath = os.path.join(self.script_srcdir, srcfile) + if not dstfile: + if srctail: + dpath = os.path.join(self.workdir, srctail) + else: + return + else: + dstpath, dsttail = os.path.split(dstfile) + if dstpath: + if not os.path.exists(os.path.join(self.workdir, dstpath)): + dstlist = self.parse_path(dstpath) + if len(dstlist) > 0 and dstlist[0] == ".": + dstlist = dstlist[1:] + for idx in range(len(dstlist)): + self.subdir(dstlist[:idx+1]) + + dpath = os.path.join(self.workdir, dstfile) + shutil.copy(spath, dpath) + def start(self, program = None, interpreter = None, arguments = None, @@ -1304,6 +1406,12 @@ class TestCmd(object): The specified program will have the original directory prepended unless it is enclosed in a [list]. """ + if self.external: + if not program: + program = self.program + if not interpreter: + interpreter = self.interpreter + if chdir: oldcwd = os.getcwd() if not os.path.isabs(chdir): diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index 4f04a48..cd3836d 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -231,20 +231,36 @@ class TestSCons(TestCommon): is not necessary. """ self.orig_cwd = os.getcwd() + self.external = 0 try: - script_dir = os.environ['SCONS_SCRIPT_DIR'] + self.external = os.environ.get('SCONS_EXTERNAL_TEST', 0) except KeyError: pass + + if not self.external: + try: + script_dir = os.environ['SCONS_SCRIPT_DIR'] + except KeyError: + pass + else: + os.chdir(script_dir) else: - os.chdir(script_dir) + try: + self.script_srcdir = os.environ['PYTHON_SCRIPT_DIR'] + except KeyError: + pass if 'program' not in kw: kw['program'] = os.environ.get('SCONS') if not kw['program']: - if os.path.exists('scons'): - kw['program'] = 'scons' + if not self.external: + if os.path.exists('scons'): + kw['program'] = 'scons' + else: + kw['program'] = 'scons.py' else: - kw['program'] = 'scons.py' - elif not os.path.isabs(kw['program']): + kw['program'] = 'scons' + kw['interpreter'] = '' + elif not self.external and not os.path.isabs(kw['program']): kw['program'] = os.path.join(self.orig_cwd, kw['program']) if 'interpreter' not in kw and not os.environ.get('SCONS_EXEC'): kw['interpreter'] = [python, '-tt'] @@ -264,23 +280,27 @@ class TestSCons(TestCommon): TestCommon.__init__(self, **kw) - import SCons.Node.FS - if SCons.Node.FS.default_fs is None: - SCons.Node.FS.default_fs = SCons.Node.FS.FS() + if not self.external: + import SCons.Node.FS + if SCons.Node.FS.default_fs is None: + SCons.Node.FS.default_fs = SCons.Node.FS.FS() def Environment(self, ENV=None, *args, **kw): """ Return a construction Environment that optionally overrides the default external environment with the specified ENV. """ - import SCons.Environment - import SCons.Errors - if not ENV is None: - kw['ENV'] = ENV - try: - return SCons.Environment.Environment(*args, **kw) - except (SCons.Errors.UserError, SCons.Errors.InternalError): - return None + if not self.external: + import SCons.Environment + import SCons.Errors + if not ENV is None: + kw['ENV'] = ENV + try: + return SCons.Environment.Environment(*args, **kw) + except (SCons.Errors.UserError, SCons.Errors.InternalError): + return None + + return None def detect(self, var, prog=None, ENV=None, norm=None): """ @@ -292,17 +312,20 @@ class TestSCons(TestCommon): used as prog. """ env = self.Environment(ENV) - v = env.subst('$'+var) - if not v: - return None - if prog is None: - prog = v - if v != prog: - return None - result = env.WhereIs(prog) - if norm and os.sep != '/': - result = result.replace(os.sep, '/') - return result + if env: + v = env.subst('$'+var) + if not v: + return None + if prog is None: + prog = v + if v != prog: + return None + result = env.WhereIs(prog) + if norm and os.sep != '/': + result = result.replace(os.sep, '/') + return result + + return self.where_is(prog) def detect_tool(self, tool, prog=None, ENV=None): """ @@ -324,13 +347,35 @@ class TestSCons(TestCommon): def where_is(self, prog, path=None): """ Given a program, search for it in the specified external PATH, - or in the actual external PATH is none is specified. + or in the actual external PATH if none is specified. """ - import SCons.Environment - env = SCons.Environment.Environment() if path is None: path = os.environ['PATH'] - return env.WhereIs(prog, path) + if isinstance(prog, str): + prog = [prog] + if self.external: + import stat + paths = path.split(os.pathsep) + for p in prog: + for d in paths: + f = os.path.join(d, p) + if os.path.isfile(f): + try: + st = os.stat(f) + except OSError: + # os.stat() raises OSError, not IOError if the file + # doesn't exist, so in this case we let IOError get + # raised so as to not mask possibly serious disk or + # network issues. + continue + if stat.S_IMODE(st[stat.ST_MODE]) & 0111: + return os.path.normpath(f) + else: + import SCons.Environment + env = SCons.Environment.Environment() + return env.WhereIs(prog, path) + + return None def wrap_stdout(self, build_str = "", read_str = "", error = 0, cleaning = 0): """Wraps standard output string(s) in the normal @@ -616,36 +661,39 @@ class TestSCons(TestCommon): Initialize with a default external environment that uses a local Java SDK in preference to whatever's found in the default PATH. """ - try: - return self._java_env[version]['ENV'] - except AttributeError: - self._java_env = {} - except KeyError: - pass - - import SCons.Environment - env = SCons.Environment.Environment() - self._java_env[version] = env - - - if version: - patterns = [ - '/usr/java/jdk%s*/bin' % version, - '/usr/lib/jvm/*-%s*/bin' % version, - '/usr/local/j2sdk%s*/bin' % version, - ] - java_path = self.paths(patterns) + [env['ENV']['PATH']] - else: - patterns = [ - '/usr/java/latest/bin', - '/usr/lib/jvm/*/bin', - '/usr/local/j2sdk*/bin', - ] - java_path = self.paths(patterns) + [env['ENV']['PATH']] - - env['ENV']['PATH'] = os.pathsep.join(java_path) - return env['ENV'] + if not self.external: + try: + return self._java_env[version]['ENV'] + except AttributeError: + self._java_env = {} + except KeyError: + pass + + import SCons.Environment + env = SCons.Environment.Environment() + self._java_env[version] = env + + + if version: + patterns = [ + '/usr/java/jdk%s*/bin' % version, + '/usr/lib/jvm/*-%s*/bin' % version, + '/usr/local/j2sdk%s*/bin' % version, + ] + java_path = self.paths(patterns) + [env['ENV']['PATH']] + else: + patterns = [ + '/usr/java/latest/bin', + '/usr/lib/jvm/*/bin', + '/usr/local/j2sdk*/bin', + ] + java_path = self.paths(patterns) + [env['ENV']['PATH']] + + env['ENV']['PATH'] = os.pathsep.join(java_path) + return env['ENV'] + return None + def java_where_includes(self,version=None): """ Return java include paths compiling java jni code |