예제 #1
0
 def _prepare_environment(self, spec):
     # returns the relevant bits of the environment
     info = {}
     self._environ_restore = {}
     env_spec = spec.get('environment', {})
     for env in env_spec:
         # store the current value
         self._environ_restore[env] = os.environ.get(env, None)
         if env_spec[env] is None:
             # unset if null
             if env in os.environ:
                 del os.environ[env]
         elif isinstance(env_spec[env], basestring):
             # set if string
             # set the new one
             os.environ[env] = str(env_spec[env])
         elif env_spec[env] is True:
             # this variable is required to be present
             if not cfg.getboolean('testrun', 'fail on missing environment',
                                   default=False) \
                and not env in os.environ:
                 self.skipTest(
                     "required environment variable '%s' not set" % env)
             else:
                 self.assertThat(os.environ, Contains(env))
         # grab envvar values if anyhow listed
         info[env] = os.environ.get(env, None)
     if not len(self._environ_restore):
         self._environ_restore = None
     return info
예제 #2
0
파일: testcase.py 프로젝트: satra/testkraut
 def _prepare_environment(self, spec):
     # returns the relevant bits of the environment
     info = {}
     self._environ_restore = {}
     env_spec = spec.get('environment', {})
     for env in env_spec:
         # store the current value
         self._environ_restore[env] = os.environ.get(env, None)
         if env_spec[env] is None:
             # unset if null
             if env in os.environ:
                 del os.environ[env]
         elif isinstance(env_spec[env], basestring):
             # set if string
             # set the new one
             os.environ[env] = str(env_spec[env])
         elif env_spec[env] is True:
             # this variable is required to be present
             if not cfg.getboolean('testrun', 'fail on missing environment',
                                   default=False) \
                and not env in os.environ:
                 self.skipTest("required environment variable '%s' not set"
                               % env)
             else:
                 self.assertThat(os.environ, Contains(env))
         # grab envvar values if anyhow listed
         info[env] = os.environ.get(env, None)
     if not len(self._environ_restore):
         self._environ_restore = None
     return info
예제 #3
0
파일: testcase.py 프로젝트: satra/testkraut
 def _get_system_info(self):
     if TestFromSPEC._system_info is None:
         if cfg.getboolean('testrun', 'skip platform description',
                           default=False):
             TestFromSPEC._system_info = {}
         else:
             TestFromSPEC._system_info = describe_system()
     return TestFromSPEC._system_info
예제 #4
0
 def _get_system_info(self):
     if TestFromSPEC._system_info is None:
         if cfg.getboolean('testrun', 'skip platform description',
                           default=False):
             TestFromSPEC._system_info = {}
         else:
             TestFromSPEC._system_info = describe_system()
     return TestFromSPEC._system_info
예제 #5
0
    def _get_dep_info(self):
        info = {}
        self._details['dep_info'] = info
        if cfg.getboolean('testrun',
                          'skip dependency description',
                          default=False):
            return
        spec = self._cur_spec
        for dep_id, depspec in spec.get('dependencies', {}).iteritems():
            if not 'type' in depspec or not 'location' in depspec:
                raise ValueError(
                    "dependency SPEC '%s' contains no 'type' or no 'location' field"
                    % dep_id)
            deptype = depspec['type']
            deploc = depspec['location']
            # TODO implement support for more dependency types
            if deptype == 'executable':
                dephash = describe_binary(deptype, deploc, info)
            elif deptype == 'python_module':
                from imp import find_module
                try:
                    mfile, mpath, mdescr = find_module(deploc.replace(
                        '.', '/'))
                except ImportError:
                    # swallow the error -- if it can't be imported the test was
                    # skipped anyway
                    continue
                if mfile is None:
                    # a package
                    mpath = opj(mpath, '__init__.py')
                dephash = describe_python_module(deptype, mpath, info)
            else:
                raise ValueError("unsupported dependency type '%s' in '%s'" %
                                 (deptype, dep_id))

            # check version information
            have_version = False
            if 'version_file' in depspec:
                verfilename = depspec['version_file']
                extract_regex = r'.*'
                if isinstance(verfilename, list):
                    verfilename, extract_regex = verfilename
                # expand the filename
                verfilename = os.path.realpath(os.path.expandvars(verfilename))
                try:
                    file_content = open(verfilename).read().strip()
                    version = re.findall(extract_regex, file_content)[0]
                    if len(version):
                        info[dephash]['version'] = version
                        have_version = True
                except:
                    lgr.debug("failed to read version from '%s'" % verfilename)
            if not have_version and 'version_cmd' in depspec:
                vercmd = depspec['version_cmd']
                extract_regex = r'.*'
                if isinstance(vercmd, list):
                    vercmd, extract_regex = vercmd
                ret = run_command(vercmd)
                try:
                    # this will throw an exception if nothing is found
                    version = re.findall(extract_regex,
                                         '\n'.join(ret['stderr']))[0]
                    if len(version):
                        info[dephash]['version'] = version
                        have_version = True
                except:
                    try:
                        version = re.findall(extract_regex,
                                             '\n'.join(ret['stdout']))[0]
                        if len(version):
                            info[dephash]['version'] = version
                            have_version = True
                    except:
                        lgr.debug("failed to read version from '%s'" % vercmd)
예제 #6
0
파일: testcase.py 프로젝트: satra/testkraut
    def _get_dep_info(self):
        info = {}
        self._details['dep_info'] = info
        if cfg.getboolean('testrun', 'skip dependency description',
                          default=False):
            return
        spec = self._cur_spec
        for dep_id, depspec in spec.get('dependencies', {}).iteritems():
            if not 'type' in depspec or not 'location' in depspec:
                raise ValueError("dependency SPEC '%s' contains no 'type' or no 'location' field"
                                 % dep_id)
            deptype = depspec['type']
            deploc = depspec['location']
            # TODO implement support for more dependency types
            if deptype == 'executable':
                dephash = describe_binary(deptype, deploc, info)
            elif deptype == 'python_module':
                from imp import find_module
                try:
                    mfile, mpath, mdescr = find_module(deploc.replace('.', '/'))
                except ImportError:
                    # swallow the error -- if it can't be imported the test was
                    # skipped anyway
                    continue
                if mfile is None:
                    # a package
                    mpath = opj(mpath, '__init__.py')
                dephash = describe_python_module(deptype, mpath, info)
            else:
                raise ValueError("unsupported dependency type '%s' in '%s'"
                                 % (deptype, dep_id))

            # check version information
            have_version = False
            if 'version_file' in depspec:
                verfilename = depspec['version_file']
                extract_regex = r'.*'
                if isinstance(verfilename, list):
                    verfilename, extract_regex = verfilename
                # expand the filename
                verfilename = os.path.realpath(os.path.expandvars(verfilename))
                try:
                    file_content = open(verfilename).read().strip()
                    version = re.findall(extract_regex, file_content)[0]
                    if len(version):
                        info[dephash]['version'] = version
                        have_version = True
                except:
                    lgr.debug("failed to read version from '%s'"
                              % verfilename)
            if not have_version and 'version_cmd' in depspec:
                vercmd = depspec['version_cmd']
                extract_regex = r'.*'
                if isinstance(vercmd, list):
                    vercmd, extract_regex = vercmd
                ret = run_command(vercmd)
                try:
                    # this will throw an exception if nothing is found
                    version = re.findall(extract_regex, '\n'.join(ret['stderr']))[0]
                    if len(version):
                        info[dephash]['version'] = version
                        have_version = True
                except:
                    try:
                        version = re.findall(extract_regex, '\n'.join(ret['stdout']))[0]
                        if len(version):
                            info[dephash]['version'] = version
                            have_version = True
                    except:
                        lgr.debug("failed to read version from '%s'" % vercmd)