Пример #1
0
def checkVersions():
    """
    Method to check if versions of modules are new enough. Will call sys.exit
    if they are not in the range specified.
    @ In, None
    @ Out, None
  """
    # import library handler (although it is bad practice to import inside a function)
    frameworkDir = findFramework()
    scriptDir = os.path.join(frameworkDir, '..', 'scripts')
    if scriptDir not in sys.path:
        remove = True
        sys.path.append(scriptDir)
    else:
        remove = False
    try:
        import library_handler as LH
    except ModuleNotFoundError:
        print(
            "ERROR: Unable to check library versions because library_handler not found"
        )
        return
    if remove:
        sys.path.pop(sys.path.index(scriptDir))
    # if libraries are not to be checked, we're done here
    if not LH.checkVersions():
        return
    # otherwise, we check for incorrect libraries
    missing, notQA = LH.checkLibraries()
    if missing:
        print(
            'ERROR: Some required Python libraries are missing but required to run RAVEN as configured:'
        )
        for lib, version in missing:
            # report the missing library
            msg = f'  -> MISSING: {lib}'
            # add the required version if applicable
            if version is not None:
                msg += f' version {version}'
            print(msg)
    if notQA:
        print(
            'ERROR: Some required Python libraries have incorrect versions for running RAVEN as configured:'
        )
        for lib, found, need in notQA:
            print(
                f'  -> WRONG VERSION: lib "{lib}" need "{need}" but found "{found}"'
            )
    if missing or notQA:
        print(
            'Try installing libraries using instructions on RAVEN repository wiki at '
            +
            'https://github.com/idaholab/raven/wiki/Installing_RAVEN_Libraries.'
        )
        sys.exit(-4)
    else:
        print('RAVEN Python dependencies located and checked.')
Пример #2
0
 def check_runnable(self):
     """
   This method checks if the the test is runnable within the current settings
   @ In, None
   @ Out, check_runnable, boolean, If True this test can run.
 """
     missing, notQa = library_handler.checkLibraries()
     if len(missing) > 0:
         self.set_skip('skipped (Missing python modules: ' + str(missing) +
                       " PYTHONPATH=" + os.environ.get("PYTHONPATH", "") +
                       ')')
         return False
     if len(notQa) > 0:
         self.set_skip('skipped (incorrect version python modules: ' +
                       " ".join(['{}-{}'.format(*m)
                                 for m in notQa]) + " PYTHONPATH=" +
                       os.environ.get("PYTHONPATH", "") + ')')
         return False
     for lib in self.required_libraries:
         if platform.system() == 'Windows':
             lib += '.pyd'
         else:
             lib += '.so'
         if not os.path.exists(lib):
             self.set_skip('skipped (Missing library: "' + lib + '")')
             return False
     if self.specs['python3_only'] and not library_handler.inPython3():
         self.set_skip('Python 3 only')
         return False
     if len(self.required_executable) > 0 and \
        not os.path.exists(self.required_executable):
         self.set_skip('skipped (Missing executable: "' +
                       self.required_executable + '")')
         return False
     try:
         if len(self.required_executable) > 0 and \
            subprocess.call([self.required_executable], stdout=subprocess.PIPE) != 0:
             self.set_skip('skipped (Failing executable: "' +
                           self.required_executable + '")')
             return False
     except Exception:
         self.set_skip('skipped (Error when trying executable: "' +
                       self.required_executable + '")')
         return False
     if len(self.specs['skip_if_env']) > 0:
         envVar = self.specs['skip_if_env']
         if envVar in os.environ:
             self.set_skip('skipped (found environmental variable "' +
                           envVar + '")')
             return False
     return True
Пример #3
0
def checkVersions():
    """
    Method to check if versions of modules are new enough. Will call sys.exit
    if they are not in the range specified.
    @ In, None
    @ Out, None
  """
    # if libraries are not to be checked, we're done here
    if not LH.checkVersions():
        return
    # otherwise, we check for incorrect libraries
    missing, notQA = LH.checkLibraries()
    if missing:
        print(
            'ERROR: Some required Python libraries are missing but required to run RAVEN as configured:'
        )
        for lib, version in missing:
            # report the missing library
            msg = '  -> MISSING: {}'.format(lib)
            # add the required version if applicable
            if version is not None:
                msg += ' version {}'.format(version)
            print(msg)
    if notQA:
        print(
            'ERROR: Some required Python libraries have incorrect versions for running RAVEN as configured:'
        )
        for lib, found, need in notQA:
            print(
                '  -> WRONG VERSION: lib "{}" need "{}" but found "{}"'.format(
                    lib, found, need))
    if missing or notQA:
        print(
            'Try installing libraries using instructions on RAVEN repository wiki at '
            +
            'https://github.com/idaholab/raven/wiki/Installing_RAVEN_Libraries.'
        )
        sys.exit(-4)
    else:
        print('RAVEN Python dependencies located and checked.')
Пример #4
0
#  path is somewhere under tests/framework.
# Be aware that if this file changes its location, this variable should also be
#  changed.
myDir = os.path.dirname(os.path.realpath(__file__))
RAVENDIR = os.path.abspath(os.path.join(myDir, '..', '..', '..', 'framework'))

#Need to add the directory for AMSC for doing module checks.
os.environ["PYTHONPATH"] = os.path.join(RAVENDIR, 'contrib') +\
  os.pathsep + os.environ.get("PYTHONPATH", "")

scriptDir = os.path.abspath(os.path.join(RAVENDIR, '..', 'scripts'))
sys.path.append(scriptDir)
import library_handler
sys.path.pop()

_missingModules, _notQAModules = library_handler.checkLibraries()
_checkVersions = library_handler.checkVersions()

class RavenFramework(Tester):
  """
  RavenFramework is the class to use for testing standard raven inputs.
  """

  @staticmethod
  def get_valid_params():
    """
      Returns the parameters that can be used for this class.
      @ In, None
      @ Out, params, _ValidParameters, return the parameters.
    """
    params = Tester.get_valid_params()
Пример #5
0
    def check_runnable(self):
        """
      Checks if this test can be run.
      @ In, None
      @ Out, check_runnable, boolean, If True can run this test.
    """
        i = 0
        if len(self.minimum_libraries) % 2:
            self.set_skip(
                'skipped (libraries are not matched to versions numbers: ' +
                str(self.minimum_libraries) + ')')
            return False
        while i < len(self.minimum_libraries):
            libraryName = self.minimum_libraries[i]
            libraryVersion = self.minimum_libraries[i + 1]
            found, _, actualVersion = library_handler.checkSingleLibrary(
                libraryName, 'check')
            if not found:
                self.set_skip('skipped (Unable to import library: "' +
                              libraryName + '")')
                return False
            if distutils.version.LooseVersion(actualVersion) < \
               distutils.version.LooseVersion(libraryVersion):
                self.set_skip('skipped (Outdated library: "' + libraryName +
                              '")')
                return False
            i += 2

        if len(self.required_executable) > 0:
            try:
                argsList = [self.required_executable]
                argsList.extend(self.required_executable_check_flags)
                retValue = subprocess.call(argsList, stdout=subprocess.PIPE)
                if retValue != 0:
                    self.set_skip('skipped (Failing executable: "' +
                                  self.required_executable + '")')
                    return False
            except Exception:
                self.set_skip('skipped (Error when trying executable: "' +
                              self.required_executable + '")')
                return False

        if self.specs['requires_swig2'] and not RavenPython.hasSwig2:
            self.set_skip('skipped (No swig 2.0 found)')
            return False
        missing, notQa = library_handler.checkLibraries()
        if len(missing) > 0:
            self.set_fail('skipped (Missing python modules: ' +
                          " ".join(missing) + " PYTHONPATH=" +
                          os.environ.get("PYTHONPATH", "") + ')')
            return False
        if len(notQa) > 0 and library_handler.checkVersions():
            self.set_fail('skipped (Incorrectly versioned python modules: ' +
                          " ".join(['{}-{}'.format(*m)
                                    for m in notQa]) + " PYTHONPATH=" +
                          os.environ.get("PYTHONPATH", "") + ')')
            return False
        for lib in self.required_libraries:
            found, _, _ = library_handler.checkSingleLibrary(lib)
            if not found:
                self.set_skip('skipped (Unable to import library: "' + lib +
                              '")')
                return False
        if self.specs['python3_only'] and not library_handler.inPython3():
            self.set_skip('Python 3 only')
            return False

        return True