Beispiel #1
0
 def __enter__(self):
     print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" )
     print( "| RScript {0} is starting".format(self.scriptName) )
     self.pathToRScript = self.configuration.get_parameter('PATH:rscript')
     if not os.path.exists(self.pathToRScript):
        raise ExecutionError(self.stepName, 'Rscript  not found at %s' % self.pathToRScript )
     print( "..........................................................." )
     self.pathToCode = self.configuration.get_parameter('PATH:rcode')
     if not os.path.exists(self.pathToCode):
        raise ExecutionError(self.stepName, 'Base directory to R scripts (rcode) not found at %s' % self.pathToCode )
     return self
Beispiel #2
0
 def assert_input_file(self, filePath):
     # TODO factorisation validator
     if '*' in filePath:
         # lookup a matching file
         foundMatch = False
         for filepath_object in glob.glob(filePath):
             if os.path.isfile(filepath_object):
                 foundMatch = True
         if not foundMatch:
             msg = 'not file is matching required pattern %s' % filePath
             raise ExecutionError('Input assertion', msg)
     else:
         # lookup the exact name
         if not os.path.exists(filePath):
             msg = 'required file %s not found' % filePath
             raise ExecutionError('Input assertion', msg)
Beispiel #3
0
 def test_get_parameter_not_found(self):
     cfgFile = 'easydatalab/tests/resources/config/config_for_unittests.cfg'
     appConfiguration = AppConfiguration(cfgFile)
     appConfiguration.__enter__()
     with self.assertRaises(ExecutionError) as ctx:
         value = appConfiguration.get_parameter('x1')
         raise ExecutionError('AppConfiguration', 'key x1 was not found')
def main():
    """Main entry point for the script."""

    cfgFile = 'easydatalab/tests/resources/config/config_for_unittests.cfg'
    logCfgFile = 'easydatalab/resources/log_config.yml'

    with AppContext(log_config_file=logCfgFile) as appContext:
        appContext.logger.info("default logger for %s" % str(appContext))
        appContext.skip_steps(['skipped step'])

        with appContext.new_configuration(cfgFile) as appConfiguration:
            appConfiguration.show()

            with appContext.new_step('something') as step:
                if step.enabled():
                    print("does something")

            with appContext.new_step('skipped step') as step:
                if step.enabled():
                    print("does skipped")

            with appContext.new_step('failed step') as step:
                if step.enabled():
                    raise ExecutionError('step 3', 'failed to complete task')

            with appContext.new_step('something else') as step:
                if step.enabled():
                    print("does something else")
Beispiel #5
0
 def __exit__(self, exc_type, exc_value, exc_traceback):
     print( "..........................................................." )
     if exc_type == None:
         print( '| RScript %s completed' %   self.scriptName )
         print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" )
     else:
         print( '| RScript %s Aborted' %  (self.scriptName) )
         print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" )
         raise ExecutionError('RScript', 'error during %s execution - %s' % (self.scriptName, traceback.format_exc() ) )
Beispiel #6
0
 def get_parameters_as_map(self, keyList):
     params = []
     params.append( '{0}={1}'.format('pathToCode', self.pathToCode) )
     for key in keyList:
         if key != 'pathToCode':
             try:
                 params.append( "%s=%s" % (key,  self.configuration.get_parameter(key) ) )
             except:
                 raise ExecutionError("Missing parameter", key)
     return params
 def get_parameter(self, key):
     try:
         if ':' in key:
             pair = key.split(':')
             value = self.settings.get(pair[0], pair[1])
         else:
             value = self.parameters[key]
     except:
         raise ExecutionError('AppConfiguration',
                              'key %s was not found' % key)
     return value
 def test_exception(self):
     with self.assertRaises(ExecutionError) as ctx:
         raise ExecutionError('pathToCode', 'does not exist')
         self.assertTrue('ExecutionError' in ctx.exception)
         self.assertEqual('ExecutionError: error in step step2 - wrong parameter', str(ctx.exception))
Beispiel #9
0
 def get_full_path(self, scriptPath):
     path = '{0}/{1}'.format(self.pathToCode , scriptPath)
     if not os.path.exists(path):
        raise ExecutionError(self.stepName, 'R program not found at %s' % path )
     return path