Guest User

Untitled

a guest
Oct 14th, 2019
942
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def generate_functional_test(output_dir, batch, interaction_id, input_origin, user_interface_idiom, request_locale, request_latitude, request_longitude, restrictions_arr, upcm):
  2. '''
  3. :param model: Model name
  4. :param labeled_utterence: Dictionary representation of single row from .tsv file
  5. :param audio_file_path: Path to .opx audio file.
  6. :param output_dir: Directory in which to save new functest.xml
  7. :return: Full path to new functest.xml
  8. '''
  9.  
  10. language = request_locale.split('_')[0]
  11. country = request_locale.split('_')[1]
  12.  
  13. if not os.path.exists(output_dir):
  14. logging.info(f'{output_dir} does not exist. Creating it.')
  15.  
  16. try:
  17. os.makedirs(output_dir)
  18. except Exception as e:
  19. logging.error(f'Attempting to create directory {output_dir + str(e)} failed.')
  20. return None
  21.  
  22. download_audio(batch, interaction_id)
  23. audio_file_path = f'wabac/audio-debug.funcsuite/{interaction_id}.opx'
  24.  
  25. reference_func_test_xml_path = 'reference_files/func_test_ref.xml'
  26. tree = ET.parse(reference_func_test_xml_path)
  27. root = tree.getroot()
  28.  
  29. root.find('id').text = interaction_id
  30. root.find('name').text = interaction_id
  31. root.find('userInterfaceIdiom').text = user_interface_idiom
  32.  
  33. if user_interface_idiom == 'PHONE':
  34. root.find('iPhone').text = 'true'
  35. if request_latitude:
  36. root.find('latitude').text = request_latitude
  37. if request_longitude:
  38. root.find('longitude').text = request_longitude
  39.  
  40. for utterance in root.iter('com.apple.siri.ace.inspector.client.SpeechUtteranceFromFile'):
  41. utterance.find('speechFile').text = audio_file_path
  42.  
  43. if input_origin:
  44. utterance.find('inputOrigin').text = input_origin
  45.  
  46. for language_element in root.iter('language'):
  47. language_element.set('country', country)
  48. language_element.set('language', language)
  49.  
  50. assistant_id = ET.Element('assistantId')
  51. assistant_id.text = upcm['assistantId']
  52. root.append(assistant_id)
  53.  
  54. speech_id = ET.Element('speechId')
  55. speech_id.text = upcm['speechId']
  56. root.append(speech_id)
  57.  
  58. if upcm['linkedAssistantId'] is not None:
  59. linked_assistant_id = ET.Element('linkedAssistantId')
  60. linked_assistant_id.text = upcm['linkedAssistantId']
  61.  
  62. restrictions_elem = ET.Element('restrictions')
  63.  
  64. for restriction in restrictions_arr:
  65. temp_sub = ET.SubElement(restrictions_elem, "java.lang.String")
  66. temp_sub.text = restriction
  67.  
  68. root.append(restrictions_elem)
  69.  
  70. func_test_filename = f'{interaction_id}.functest.xml'
  71. func_test_file_path = os.path.join(output_dir, func_test_filename)
  72. tree.write(func_test_file_path)
  73.  
  74. if not os.path.isfile(func_test_file_path):
  75. logging.error(f'Failed to write {func_test_file_path}')
  76. return None
  77.  
  78. return func_test_file_path
RAW Paste Data