def test_exists_fb(self): fb_res = fb_resources.FBResources('TEST_FB') result = fb_res.exists_fb() self.assertEqual(True, result) fb_res = fb_resources.FBResources('E_EXAMPLE_1') result = fb_res.exists_fb() self.assertEqual(False, result)
def create_fb(self, fb_name, fb_type, monitor=False): logging.info('creating a new fb...') fb_res = fb_resources.FBResources(fb_type) exists_fb = fb_res.exists_fb() if not exists_fb: # Downloads the fb definition and python code logging.info('fb doesnt exists, needs to be downloaded ...') fb_res.download_fb() fb_definition, fb_obj = fb_res.import_fb() # check if if happened any importing error if fb_definition is not None: ## if it is a real FB, not a hidden one if monitor: fb_element = fb.FB(fb_name, fb_type, fb_obj, fb_definition, monitor=self.monitor) else: fb_element = fb.FB(fb_name, fb_type, fb_obj, fb_definition) self.set_fb(fb_name, fb_element) logging.info('created fb type: {0}, instance: {1}'.format( fb_type, fb_name)) # returns the both elements return fb_element, fb_definition else: logging.error( 'can not create the fb type: {0}, instance: {1}'.format( fb_type, fb_name))
def test_import_fb(self): fb_res = fb_resources.FBResources('TEST_FB') element, fb_obj = fb_res.import_fb() result = fb_obj.schedule('EI', 23, None) tag = element.tag self.assertEqual('FBType', tag) self.assertEqual(24, result[0])
def create_fb(self, fb_name, fb_type, monitor=False): logging.info('creating a new fb...') fb_res = fb_resources.FBResources(fb_type) exists_fb = fb_res.exists_fb() if not exists_fb: # Downloads the fb definition and python code logging.info('fb doesnt exists, needs to be downloaded ...') fb_res.download_fb() fb_definition, fb_obj = fb_res.import_fb() # check if if happened any importing error if fb_definition is not None: # Checking order and number or arguments of schedule function # Logs warning if order and number are not the same scheduleArgs = inspect.getargspec(fb_obj.schedule).args if len(scheduleArgs) > 3: scheduleArgs = scheduleArgs[3:] scheduleArgs = [i.lower() for i in scheduleArgs] xmlArgs = [] for child in fb_definition: inputvars = child.find('InputVars') varslist = inputvars.findall('VarDeclaration') for xmlVar in varslist: if xmlVar.get('Name') is not None: xmlArgs.append(xmlVar.get('Name').lower()) else: logging.error( 'Could not find mandatory "Name" attribute for variable. Please check {0}.fbt' .format(fb_name)) if scheduleArgs != xmlArgs: logging.warning( 'Argument names for schedule function of {0} do not match definition in {0}.fbt' .format(fb_name)) logging.warning( 'Ensure your variable arguments are the same as the input variables and in the same order' ) ## if it is a real FB, not a hidden one if monitor: fb_element = fb.FB(fb_name, fb_type, fb_obj, fb_definition, monitor=self.monitor) else: fb_element = fb.FB(fb_name, fb_type, fb_obj, fb_definition) self.set_fb(fb_name, fb_element) logging.info('created fb type: {0}, instance: {1}'.format( fb_type, fb_name)) # returns the both elements return fb_element, fb_definition else: logging.error( 'can not create the fb type: {0}, instance: {1}'.format( fb_type, fb_name)) return None, None