alessandro trinca tornidor commited on
Commit
82a2b00
·
1 Parent(s): 1bd485a

test: update test cases

Browse files
tests/lambdas/test_lambdaSpeechToScore.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  import os
 
3
  import platform
4
  import unittest
5
 
@@ -95,6 +96,10 @@ def check_output(self, output, expected_output, check_audio_files=False):
95
  output["real_transcripts_ipa"] = expected_output["real_transcripts_ipa"]
96
  if check_audio_files:
97
  audio_files = output["audio_files"]
 
 
 
 
98
  for audio_file in audio_files:
99
  path_audio_file = Path(audio_file)
100
  app_logger.info(f"path_audio_file:{path_audio_file}.")
@@ -103,6 +108,10 @@ def check_output(self, output, expected_output, check_audio_files=False):
103
 
104
  output["audio_files"] = [*audio_files]
105
  expected_output["audio_files"] = [*audio_files]
 
 
 
 
106
  app_logger.info(f"output audio_files:{output['audio_files']}.")
107
  app_logger.info(f"expected_output audio_files:{expected_output['audio_files']}.")
108
  self.assertDictEqual(output, expected_output)
@@ -210,6 +219,7 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
210
  ipa_transcript,
211
  real_transcripts_ipa,
212
  num_words,
 
213
  dumped,
214
  ) = lambdaSpeechToScore.get_speech_to_score_tuple(
215
  real_text=text_dict[language],
@@ -224,7 +234,10 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
224
  assert len(ipa_transcript.strip()) > 0
225
  assert len(real_transcripts_ipa.strip()) > 0
226
  assert num_words == 6
227
- check_output(self, json.loads(dumped), expected_output[language], check_audio_files=True)
 
 
 
228
 
229
  def test_get_speech_to_score_tuple_en_ok(self):
230
  from aip_trainer.lambdas import lambdaSpeechToScore
@@ -238,6 +251,7 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
238
  ipa_transcript,
239
  real_transcripts_ipa,
240
  num_words,
 
241
  dumped,
242
  ) = lambdaSpeechToScore.get_speech_to_score_tuple(
243
  real_text=text_dict[language],
@@ -252,6 +266,8 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
252
  assert len(ipa_transcript.strip()) > 0
253
  assert len(real_transcripts_ipa.strip()) > 0
254
  assert num_words == 5
 
 
255
  check_output(self, json.loads(dumped), expected_output[language], check_audio_files=True)
256
 
257
  def test_get_speech_to_score_dict__de_empty_input_text(self):
 
1
  import json
2
  import os
3
+ from pathlib import Path
4
  import platform
5
  import unittest
6
 
 
96
  output["real_transcripts_ipa"] = expected_output["real_transcripts_ipa"]
97
  if check_audio_files:
98
  audio_files = output["audio_files"]
99
+ audio_durations = output["audio_durations"]
100
+ for audio_duration in audio_durations:
101
+ assert isinstance(audio_duration, float)
102
+ assert audio_duration > 0
103
  for audio_file in audio_files:
104
  path_audio_file = Path(audio_file)
105
  app_logger.info(f"path_audio_file:{path_audio_file}.")
 
108
 
109
  output["audio_files"] = [*audio_files]
110
  expected_output["audio_files"] = [*audio_files]
111
+ n_durations = len(output["audio_durations"])
112
+ audio_durations = [x/4 + 0.5 for x in range(n_durations)]
113
+ output["audio_durations"] = [*audio_durations]
114
+ expected_output["audio_durations"] = [*audio_durations]
115
  app_logger.info(f"output audio_files:{output['audio_files']}.")
116
  app_logger.info(f"expected_output audio_files:{expected_output['audio_files']}.")
117
  self.assertDictEqual(output, expected_output)
 
219
  ipa_transcript,
220
  real_transcripts_ipa,
221
  num_words,
222
+ first_audio_file,
223
  dumped,
224
  ) = lambdaSpeechToScore.get_speech_to_score_tuple(
225
  real_text=text_dict[language],
 
234
  assert len(ipa_transcript.strip()) > 0
235
  assert len(real_transcripts_ipa.strip()) > 0
236
  assert num_words == 6
237
+ first_audio_file_path = Path(first_audio_file)
238
+ assert first_audio_file_path.exists() and first_audio_file_path.is_file()
239
+ json_loaded = json.loads(dumped)
240
+ check_output(self, json_loaded, expected_output[language], check_audio_files=True)
241
 
242
  def test_get_speech_to_score_tuple_en_ok(self):
243
  from aip_trainer.lambdas import lambdaSpeechToScore
 
251
  ipa_transcript,
252
  real_transcripts_ipa,
253
  num_words,
254
+ first_audio_file,
255
  dumped,
256
  ) = lambdaSpeechToScore.get_speech_to_score_tuple(
257
  real_text=text_dict[language],
 
266
  assert len(ipa_transcript.strip()) > 0
267
  assert len(real_transcripts_ipa.strip()) > 0
268
  assert num_words == 5
269
+ first_audio_file_path = Path(first_audio_file)
270
+ assert first_audio_file_path.exists() and first_audio_file_path.is_file()
271
  check_output(self, json.loads(dumped), expected_output[language], check_audio_files=True)
272
 
273
  def test_get_speech_to_score_dict__de_empty_input_text(self):