Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def generate_functional_test(output_dir, batch, interaction_id, input_origin, user_interface_idiom, request_locale, request_latitude, request_longitude, restrictions_arr, upcm):
- '''
- :param model: Model name
- :param labeled_utterence: Dictionary representation of single row from .tsv file
- :param audio_file_path: Path to .opx audio file.
- :param output_dir: Directory in which to save new functest.xml
- :return: Full path to new functest.xml
- '''
- language = request_locale.split('_')[0]
- country = request_locale.split('_')[1]
- if not os.path.exists(output_dir):
- logging.info(f'{output_dir} does not exist. Creating it.')
- try:
- os.makedirs(output_dir)
- except Exception as e:
- logging.error(f'Attempting to create directory {output_dir + str(e)} failed.')
- return None
- download_audio(batch, interaction_id)
- audio_file_path = f'wabac/audio-debug.funcsuite/{interaction_id}.opx'
- reference_func_test_xml_path = 'reference_files/func_test_ref.xml'
- tree = ET.parse(reference_func_test_xml_path)
- root = tree.getroot()
- root.find('id').text = interaction_id
- root.find('name').text = interaction_id
- root.find('userInterfaceIdiom').text = user_interface_idiom
- if user_interface_idiom == 'PHONE':
- root.find('iPhone').text = 'true'
- if request_latitude:
- root.find('latitude').text = request_latitude
- if request_longitude:
- root.find('longitude').text = request_longitude
- for utterance in root.iter('com.apple.siri.ace.inspector.client.SpeechUtteranceFromFile'):
- utterance.find('speechFile').text = audio_file_path
- if input_origin:
- utterance.find('inputOrigin').text = input_origin
- for language_element in root.iter('language'):
- language_element.set('country', country)
- language_element.set('language', language)
- assistant_id = ET.Element('assistantId')
- assistant_id.text = upcm['assistantId']
- root.append(assistant_id)
- speech_id = ET.Element('speechId')
- speech_id.text = upcm['speechId']
- root.append(speech_id)
- if upcm['linkedAssistantId'] is not None:
- linked_assistant_id = ET.Element('linkedAssistantId')
- linked_assistant_id.text = upcm['linkedAssistantId']
- restrictions_elem = ET.Element('restrictions')
- for restriction in restrictions_arr:
- temp_sub = ET.SubElement(restrictions_elem, "java.lang.String")
- temp_sub.text = restriction
- root.append(restrictions_elem)
- func_test_filename = f'{interaction_id}.functest.xml'
- func_test_file_path = os.path.join(output_dir, func_test_filename)
- tree.write(func_test_file_path)
- if not os.path.isfile(func_test_file_path):
- logging.error(f'Failed to write {func_test_file_path}')
- return None
- return func_test_file_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement