def test_checkAllXMLInputFilesExist(self): sampleXMLs = glob.glob(os.path.join("sampleData", "stgXML", "*.xml")) try: stgpath.checkAllXMLInputFilesExist(sampleXMLs) except IOError: self.fail("Shouldn't produce IO error") self.assertRaises(IOError, stgpath.checkAllXMLInputFilesExist, ["boo"])
def __init__(self, testType, inputFiles, outputPathBase, basePath=None, nproc=1, timeout=None, paramOverrides=None, solverOpts=None, nameSuffix=None): if isinstance(inputFiles, str): inputFiles = [inputFiles] testName = getStdTestName(testType + "Test", inputFiles, nproc, paramOverrides, solverOpts, nameSuffix) if basePath is None: # Since this is a virtual class, get calling path 2 levels up basePath = credo.utils.getCallingPath(2) SysTest.__init__(self, testType, testName, basePath, outputPathBase, nproc, timeout) self.inputFiles = inputFiles self.paramOverrides = paramOverrides if self.paramOverrides == None: self.paramOverrides = {} absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths( self.inputFiles, self.basePath) stgpath.checkAllXMLInputFilesExist(absInputFiles) self.solverOpts = solverOpts
def test_checkAllXMLInputFilesExist(self): sampleXMLs = glob.glob(os.path.join("sampleData", "stgXML", "*.xml")) try: stgpath.checkAllXMLInputFilesExist(sampleXMLs) except IOError: self.fail("Shouldn't produce IO error") self.assertRaises(IOError, stgpath.checkAllXMLInputFilesExist, ["boo"])
def checkValidRunConfig(self): """Check the given modelRun is valid and ready to be run.""" stgpath.checkAllXMLInputFilesExist(self.modelInputFiles) # Pre-run checks for validity - e.g. at least one input file, # nproc is sensible value if self.simParams: self.simParams.checkValidParams() self.simParams.checkNoDuplicates(self.paramOverrides.keys()) if self.solverOpts: self.checkSolverOptsFile()
def checkValidRunConfig(self): """Check the given modelRun is valid and ready to be run.""" stgpath.checkAllXMLInputFilesExist(self.modelInputFiles) # Pre-run checks for validity - e.g. at least one input file, # nproc is sensible value if self.simParams: self.simParams.checkValidParams() self.simParams.checkNoDuplicates(self.paramOverrides.keys()) if self.solverOpts: self.checkSolverOptsFile()
def addStdTest(self, testClass, inputFiles, **testOpts): """Instantiate and add a "standard" system test type to the list of System tests to be run. (The "standard" refers to the user needing to have access to the module containing the system test type to be added, usually from a `from credo.systest import *` statement. :param testClass: Python class of the System test to be added. This needs to be a sub-class of :class:`~credo.systest.api.SysTest`. :param inputFiles: model input files to be passed through to the System test when instantiated. :param `**testOpts`: any other keyword arguments the user wishes to passed through to the System test when it's instantiated. Can be used to customise a test. :returns: a reference to the newly created and added SysTest.""" if not inspect.isclass(testClass): raise TypeError("The testClass argument must be a type that's"\ " a subclass of the CREDO SysTest type. Arg passed in, '%s',"\ " of type '%s', is not a Python Class." \ % (testClass, type(testClass))) if not issubclass(testClass, testapi.SingleModelSysTest): raise TypeError("The testClass argument must be a type that's"\ " a subclass of the CREDO SysTest type. Type passed in, '%s',"\ " not a subclass of SysTest." \ % (testClass)) callingPath = credo.utils.getCallingPath(1) # If just given a single input file as a string, convert # to a list (containing that single file). if isinstance(inputFiles, str): inputFiles = [inputFiles] absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths( inputFiles, callingPath) stgpath.checkAllXMLInputFilesExist(absInputFiles) if 'nproc' not in testOpts: testOpts['nproc'] = self.nproc outputPath = testapi.getStdOutputPath(testClass, inputFiles, testOpts) newSysTest = testClass(inputFiles, outputPath, basePath=callingPath, **testOpts) self.sysTests.append(newSysTest) return newSysTest
def addStdTest(self, testClass, inputFiles, **testOpts): """Instantiate and add a "standard" system test type to the list of System tests to be run. (The "standard" refers to the user needing to have access to the module containing the system test type to be added, usually from a `from credo.systest import *` statement. :param testClass: Python class of the System test to be added. This needs to be a sub-class of :class:`~credo.systest.api.SysTest`. :param inputFiles: model input files to be passed through to the System test when instantiated. :param `**testOpts`: any other keyword arguments the user wishes to passed through to the System test when it's instantiated. Can be used to customise a test. :returns: a reference to the newly created and added SysTest.""" if not inspect.isclass(testClass): raise TypeError("The testClass argument must be a type that's"\ " a subclass of the CREDO SysTest type. Arg passed in, '%s',"\ " of type '%s', is not a Python Class." \ % (testClass, type(testClass))) if not issubclass(testClass, testapi.SingleModelSysTest): raise TypeError("The testClass argument must be a type that's"\ " a subclass of the CREDO SysTest type. Type passed in, '%s',"\ " not a subclass of SysTest." \ % (testClass)) callingPath = credo.utils.getCallingPath(1) # If just given a single input file as a string, convert # to a list (containing that single file). if isinstance(inputFiles, str): inputFiles = [inputFiles] absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(inputFiles, callingPath) stgpath.checkAllXMLInputFilesExist(absInputFiles) if 'nproc' not in testOpts: testOpts['nproc']=self.nproc outputPath = testapi.getStdOutputPath(testClass, inputFiles, testOpts) newSysTest = testClass(inputFiles, outputPath, basePath=callingPath, **testOpts) self.sysTests.append(newSysTest) return newSysTest