Best Python code snippet using autotest_python
__init__.py
Source:__init__.py
...322 return w_sub323 def parseTextLine(module):324 fm = parseFormMessage(module)325 fm.form.widget = _populateTextWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module, fm)326 fm.form.widget.set_extensiontype_('TextLineWidget')327 return fm328 def parseTextBlock(module):329 fm = parseFormMessage(module)330 fm.form.widget = _populateTextWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module, fm)331 fm.form.widget.set_extensiontype_('TextBlockWidget')332 return fm333 def parseAutoComplete(module):334 fm = parseFormMessage(module)335 fm.form.widget = _populateTextWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module, fm)336 try:337 suggestions_list = module['config']['formMessageDef']['suggestions_group']['suggestions_list']338 except:339 suggestions_list = module['value']['suggestions_group']['suggestions_list']340 fm.form.widget.suggestion = [ ValueSub(value=s['value']) for s in suggestions_list ]341 fm.form.widget.set_extensiontype_('TextAutocompleteWidget')342 return fm343 def parseSingleSelect(module):344 fm = parseFormMessage(module)345 fm.form.widget = _populateSelectWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module)346 try:347 form_settings = module['config']['formMessageDef']['form_settings_group']348 except:349 form_settings = module['value']['form_settings_group']350 fm.form.widget.value = form_settings['value'] or None351 fm.form.widget.set_extensiontype_('SelectSingleWidget')352 return fm353 def parseMultiSelect(module):354 fm = parseFormMessage(module)355 fm.form.widget = _populateSelectWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module)356 try:357 initial_choices_list = module['config']['formMessageDef']['initial_choices_group']['initial_choices_list']358 except:359 initial_choices_list = module['value']['initial_choices_group']['initial_choices_list']360 fm.form.widget.value = [ ValueSub(value=c['value']) for c in initial_choices_list ]361 fm.form.widget.set_extensiontype_('SelectMultiWidget')362 return fm363 def parseDateSelect(module):364 try:365 form_settings = module['config']['formMessageDef']['form_settings_group']366 except:367 form_settings = module['value']['form_settings_group']368 fm = parseFormMessage(module)369 fm.form.widget = MFD_WIDGET_MODULE_MAPPING[module['name']]()370 fm.form.widget.date = None371 fm.form.widget.maxDate = None372 fm.form.widget.minDate = None373 fm.form.widget.minuteInterval = _parseNumber(form_settings['minute_interval'], long, "Minute interval", \374 fm, defaultValue=DateSelectTO.DEFAULT_MINUTE_INTERVAL)375 fm.form.widget.mode = form_settings['mode']376 fm.form.widget.unit = form_settings['unit'] or None377 fm.form.widget.set_extensiontype_('SelectDateWidget')378 return fm379 def parseSingleSlider(module):380 fm = parseFormMessage(module)381 fm.form.widget = _populateSliderWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module, fm)382 try:383 form_settings = module['config']['formMessageDef']['form_settings_group']384 except:385 form_settings = module['value']['form_settings_group']386 fm.form.widget.value = _parseNumber(form_settings['value'], float, "Value", fm, \387 defaultValue=fm.form.widget.min)388 fm.form.widget.set_extensiontype_('SliderWidget')389 return fm390 def parseRangeSlider(module):391 fm = parseFormMessage(module)392 fm.form.widget = _populateSliderWidget(MFD_WIDGET_MODULE_MAPPING[module['name']](), module, fm)393 try:394 form_settings = module['config']['formMessageDef']['form_settings_group']395 except:396 form_settings = module['value']['form_settings_group']397 fm.form.widget.lowValue = _parseNumber(form_settings['low_value'], float, \398 "Low value", fm, defaultValue=fm.form.widget.min)399 fm.form.widget.highValue = _parseNumber(form_settings['high_value'], float, \400 "High value", fm, defaultValue=fm.form.widget.max)401 fm.form.widget.set_extensiontype_('RangeSliderWidget')402 return fm403 def parsePhotoUpload(module):404 form_settings = module['value']['form_settings_group']405 fm = parseFormMessage(module)406 fm.form.widget = MFD_WIDGET_MODULE_MAPPING[module['name']]()407 if form_settings['crop']:408 fm.form.widget.ratio = form_settings['ratio'] or u'0x0'409 else:410 fm.form.widget.ratio = None411 fm.form.widget.quality = form_settings['quality']412 if str(form_settings['source']) == 'gallery':413 fm.form.widget.gallery = True414 fm.form.widget.camera = False415 elif str(form_settings['source']) == 'camera':416 fm.form.widget.camera = True417 fm.form.widget.gallery = False418 elif str(form_settings['source']) == 'gallery_camera':419 fm.form.widget.gallery = True420 fm.form.widget.camera = True421 fm.form.widget.set_extensiontype_('PhotoUploadWidget')422 return fm423 def parseGPSLocation(module):424 form_settings = module['value']['form_settings_group']425 fm = parseFormMessage(module)426 fm.form.widget = MFD_WIDGET_MODULE_MAPPING[module['name']]()427 fm.form.widget.gps = form_settings['gps']428 fm.form.widget.set_extensiontype_('GPSLocationWidget')429 return fm430 def parseMyDigiPass(module):431 fm = parseFormMessage(module)432 fm.form.widget = MFD_WIDGET_MODULE_MAPPING[module['name']]()433 fm.form.widget.scope = " ".join(sorted((scope for scope in MdpScope.all()434 if module['value']['mdp_scopes_group'][scope])))435 fm.form.widget.set_extensiontype_('MyDigiPassWidget')436 return fm437 def parseAdvancedOrder(module):438 try:439 form_settings = module['config']['formMessageDef']['form_settings_group']440 except:441 form_settings = module['value']['form_settings_group']442 try:443 w = module['config']['formMessageDef']['advanced_order_group']444 except:445 w = module['value']['advanced_order_group']446 bizz_check(form_settings['currency'], "%s has an empty currency field!" % (module['name']))447 fm = parseFormMessage(module)448 fm.form.widget = MFD_WIDGET_MODULE_MAPPING[module['name']]()449 fm.form.widget.currency = form_settings['currency']450 fm.form.widget.leapTime = 0451 fm.form.widget.category = []452 for c in w['category_list']:453 category = AdvancedOrderCategorySub(c['id'], c['name'])454 for i in c['category_item_list']:455 unit_price = i['unitPrice'] or 0456 item = AdvancedOrderItemSub(id=i['id'],457 name=i['name'],458 description=i['description'],459 value=i['value'] or 0,460 unit=i['unit'],461 unitPrice=unit_price,462 hasPrice=False if unit_price == 0 else True,463 step=i['step'] or 0,464 stepUnit=i['stepUnit'],465 stepUnitConversion=i['stepUnitConversion'] or 0,466 imageUrl=i["imageUrl"])467 category.add_item(item)468 fm.form.widget.add_category(category)469 fm.form.widget.set_extensiontype_('AdvancedOrderWidget')470 return fm471 moduleParsers = {472 MFD_MODULE_START: parseStart,473 MFD_MODULE_END: parseEnd,474 MFD_MODULE_MESSAGE_FLOW: parseSubMessageFlow,475 MFD_MODULE_MESSAGE: parseMessage,476 MFD_MODULE_TEXT_LINE: parseTextLine,477 MFD_MODULE_TEXT_BLOCK: parseTextBlock,478 MFD_MODULE_AUTO_COMPLETE: parseAutoComplete,479 MFD_MODULE_SINGLE_SELECT: parseSingleSelect,480 MFD_MODULE_MULTI_SELECT: parseMultiSelect,481 MFD_MODULE_DATE_SELECT: parseDateSelect,482 MFD_MODULE_SINGLE_SLIDER: parseSingleSlider,483 MFD_MODULE_RANGE_SLIDER: parseRangeSlider,...
maec_helper.py
Source:maec_helper.py
...582 fileobj.set_Sym_Links(sym_links)583 elif key == 'controlcode':584 if len(value) > 0:585 send_control_effect = maec.cybox.SendControlCodeEffectType(effect_type='ControlCode_Sent', Control_Code=value)586 send_control_effect.set_extensiontype_('cybox:SendControlCodeEffectType')587 cybox_object.set_Defined_Effect(send_control_effect)588 elif key == 'association':589 cybox_object.set_association_type(value)590 591 if fs_hashes.hasContent_():592 fileobj.set_Hashes(fs_hashes)593 594 if fileobj.hasContent_():595 cybox_object.set_Defined_Object(fileobj)596 return cybox_object597 598 def create_pipe_object(self, pipe_attributes):599 cybox_object = maec.cybox.AssociatedObjectType(id=self.generator.generate_obj_id())600 pipeobj = win_pipe_object.WindowsPipeObjectType(named='True')601 pipeobj.set_anyAttributes_({'xsi:type' : 'WinPipeObj:WindowsPipeObjectType'})602 cybox_object.set_type('Pipe')603 604 for key, value in pipe_attributes.items():605 if key == 'name' or key == 'filename':606 if len(value) > 0:607 pipeobj.set_Name(maec.common.StringObjectAttributeType(datatype='String', valueOf_=maec.quote_xml(value)))608 elif key == 'controlcode':609 if len(value) > 0:610 send_control_effect = maec.cybox.SendControlCodeEffectType(effect_type='ControlCode_Sent', Control_Code=value)611 send_control_effect.set_extensiontype_('cybox:SendControlCodeEffectType')612 cybox_object.set_Defined_Effect(send_control_effect)613 elif key == 'association':614 cybox_object.set_association_type(value)615 if pipeobj.hasContent_():616 cybox_object.set_Defined_Object(pipeobj)617 return cybox_object618 619 def create_process_object(self, process_attributes):620 cybox_object = maec.cybox.AssociatedObjectType(id=self.generator.generate_obj_id(), type_='Process')621 proc_object = process_object.ProcessObjectType()622 proc_object.set_anyAttributes_({'xsi:type' : 'ProcessObj:ProcessObjectType'})623 624 image_info = process_object.ImageInfoType()625 for key, value in process_attributes.items():626 if key == 'name':627 continue628 elif key == 'filename':629 if value != '':630 image_info.set_Path(maec.common.StringObjectAttributeType(datatype='String',valueOf_=maec.quote_xml(value)))631 elif key == 'cmd_line':632 if value != '':633 image_info.set_Command_Line(maec.common.StringObjectAttributeType(datatype='String',valueOf_=maec.quote_xml(value)))634 elif key == 'association':635 cybox_object.set_association_type(value)636 637 if image_info.hasContent_():638 proc_object.set_Image_Info(image_info)639 640 if proc_object.hasContent_(): 641 cybox_object.set_Defined_Object(proc_object)642 643 return cybox_object644 645 def create_memory_object(self, memory_attributes):646 cybox_object = maec.cybox.AssociatedObjectType(id=self.generator.generate_obj_id(), type_='Memory Page')647 mem_object = memory_object.MemoryObjectType()648 mem_object.set_anyAttributes_({'xsi:type' : 'MemoryObj:MemoryObjectType'})649 #set object attributes650 for key,value in memory_attributes.items():651 if key == 'address':652 if len(value) > 0:653 mem_object.set_Region_Start_Address(maec.common.HexBinaryObjectAttributeType(datatype='hexBinary', valueOf_=maec.quote_xml(value.replace('$',''))))654 elif key == 'association':655 cybox_object.set_association_type(value)656 657 if mem_object.hasContent_():658 cybox_object.set_Defined_Object(mem_object)659 660 return cybox_object661 662 def create_internet_object(self, internet_attributes):663 cybox_object = maec.cybox.AssociatedObjectType(id=self.generator.generate_obj_id(), type_='URI')664 uriobj = uri_object.URIObjectType()665 uriobj.set_anyAttributes_({'xsi:type' : 'URIObj:URIObjectType'})666 #set object attributes667 for key, value in internet_attributes.items():668 if key == 'uri':669 if len(value) > 0:670 uriobj.set_Value(maec.common.AnyURIObjectAttributeType(datatype='AnyURI', valueOf_=maec.quote_xml(value)))671 elif key == 'association':672 cybox_object.set_AssociationType(value)673 674 if uriobj.hasContent_():675 cybox_object.set_Defined_Object(uriobj)676 677 return cybox_object678 679 def create_service_object(self, service_attributes):680 cybox_object = maec.cybox.AssociatedObjectType(id=self.generator.generate_obj_id(), type_='Service/Daemon')681 serv_object = win_service_object.WindowsServiceObjectType()682 serv_object.set_anyAttributes_({'xsi:type' : 'WinServiceObj:WindowsServiceObjectType'})683 684 for key, value in service_attributes.items():685 if key == 'name':686 if len(value) > 0:687 serv_object.set_Service_Name(maec.common.StringObjectAttributeType(datatype='String',valueOf_=maec.quote_xml(value)))688 elif key == 'displayname':689 if len(value) > 0:690 serv_object.set_Display_Name(maec.common.StringObjectAttributeType(datatype='String',valueOf_=maec.quote_xml(value)))691 elif key == 'filename':692 continue #revisit693 elif key == 'controlcode':694 if len(value) > 0:695 send_control_effect = maec.cybox.SendControlCodeEffectType(effect_type='ControlCode_Sent', Control_Code=value)696 send_control_effect.set_extensiontype_('cybox:SendControlCodeEffectType')697 cybox_object.set_Defined_Effect(send_control_effect)698 elif key == 'association':699 cybox_object.set_association_type(value)700 701 if serv_object.hasContent_(): 702 cybox_object.set_Defined_Object(serv_object)703 704 return cybox_object 705 def create_mutex_object(self, mutex_attributes):706 cybox_object = maec.cybox.AssociatedObjectType(id=self.generator.generate_obj_id(), type_='Mutex')707 mutex_obj = win_mutex_object.WindowsMutexObjectType()708 mutex_obj.set_anyAttributes_({'xsi:type' : 'WinMutexObj:WindowsMutexObjectType'})709 710 for key, value in mutex_attributes.items():...
CreateSIPs.py
Source:CreateSIPs.py
...257 # We create the pipelineRun that will be added in all created SIPs258 # and fill all its fields259 if isCalibrated:260 self.pipelineRun = sipapi.CalibrationPipeline()261 self.pipelineRun.set_extensiontype_('sip:CalibrationPipeline')262 pipName = 'Calibration'263 else:264 self.pipelineRun = sipapi.AveragingPipeline()265 self.pipelineRun.set_extensiontype_('sip:AveragingPipeline')266 pipName = 'Averaging'267 268 pipelineRunName = 'LOFAR EoR ' + pipName + ' pipeline for ' + str(ldsbpid)269 if mainUser != None: 270 pipelineRunName += ' by ' + mainUser271 272 self.processIdentifier = sipapi.IdentifierType()273 self.processIdentifier.set_source('EoR')274 self.processIdentifier.set_name(pipelineRunName)275 self.processIdentifier.set_identifier(str(ldsbpid))276 self.pipelineRun.set_processIdentifier(self.processIdentifier)277 278 obsIdentifier = sipapi.IdentifierType()279 obsIdentifier.set_source('EoR')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!