alessandro trinca tornidor commited on
Commit
ac226c8
Β·
1 Parent(s): 9cf833f

test: start refactor tests based on mutation tests from cosmic-ray

Browse files
tests/events/test_empty.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b8fbafe8679076454429756fa72f11d5f442c87381cc6a4285451d826a9e629
3
+ size 44
tests/{test_lambdaGetSample.py β†’ lambdas/test_lambdaGetSample.py} RENAMED
File without changes
tests/{test_lambdaSpeechToScore.py β†’ lambdas/test_lambdaSpeechToScore.py} RENAMED
File without changes
tests/lambdas/test_lambdaSpeechToScore_librosa.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from aip_trainer.lambdas import lambdaSpeechToScore
4
+ from aip_trainer.utils.utilities import hash_calculate
5
+ from tests import EVENTS_FOLDER
6
+
7
+
8
+ input_file_test_de = EVENTS_FOLDER / "test_de.wav"
9
+ hash_input = hash_calculate(input_file_test_de, is_file=True)
10
+ assert hash_input == b'tGNDknDQRwCAx4LJ88Ft3y2+YAxcqXW7GAqasxxZoBw='
11
+
12
+
13
+ class TestCalcStartEnd(unittest.TestCase):
14
+
15
+ def test_calc_start_end_zero_offset(self):
16
+ output = lambdaSpeechToScore.calc_start_end(48000, 0.0, 2)
17
+ self.assertEqual(output, 0)
18
+
19
+ def test_calc_start_end_non_zero_offset(self):
20
+ output = lambdaSpeechToScore.calc_start_end(48000, 1.0, 2)
21
+ self.assertEqual(output, 96000)
22
+
23
+ def test_calc_start_end_fractional_offset(self):
24
+ output = lambdaSpeechToScore.calc_start_end(48000, 0.5, 2)
25
+ self.assertEqual(output, 48000)
26
+
27
+ def test_calc_start_end_high_sample_rate(self):
28
+ output = lambdaSpeechToScore.calc_start_end(96000, 1.0, 2)
29
+ self.assertEqual(output, 192000)
30
+
31
+ def test_calc_start_end_low_sample_rate(self):
32
+ output = lambdaSpeechToScore.calc_start_end(24000, 1.0, 2)
33
+ self.assertEqual(output, 48000)
34
+
35
+ def test_calc_start_end_very_low_sample_rate(self):
36
+ output = lambdaSpeechToScore.calc_start_end(8000, 1.0, 2)
37
+ self.assertEqual(output, 16000)
38
+
39
+ def test_calc_start_end_single_channel(self):
40
+ output = lambdaSpeechToScore.calc_start_end(48000, 1.0, 1)
41
+ self.assertEqual(output, 48000)
42
+
43
+ def test_calc_start_end_multiple_channels(self):
44
+ output = lambdaSpeechToScore.calc_start_end(48000, 1.0, 4)
45
+ self.assertEqual(output, 48000 * 4)
46
+
47
+
48
+ class TestAudioReadLoad(unittest.TestCase):
49
+
50
+ def test_audioread_load_full_file(self):
51
+ signal, sr_native = lambdaSpeechToScore.audioread_load(input_file_test_de)
52
+ self.assertEqual(sr_native, 44100)
53
+ self.assertEqual(
54
+ signal.shape[0], 129653
55
+ ) # Assuming the audio file is ~2,93 seconds long (107603 / 44100)
56
+ hash_output = hash_calculate(signal, is_file=False)
57
+ self.assertEqual(hash_output, b'3bfNuuMk0ov5+E77cUZmzjijfBUaMxuy1mrPmyjFyeo=')
58
+
59
+ def test_audioread_load_with_offset(self):
60
+ signal, sr_native = lambdaSpeechToScore.audioread_load(input_file_test_de, offset=0.5)
61
+ self.assertEqual(sr_native, 44100)
62
+ self.assertAlmostEqual(signal.shape[0], 107603) # audio file is ~2.44 seconds long (107603 / 44100), offset is 0.5 seconds
63
+ hash_output = hash_calculate(signal, is_file=False)
64
+ self.assertEqual(hash_output, b'QiDTDSZ4xAUniANNz4M43oa2FwpTSjvzW3IsKyqCVeE=')
65
+
66
+ def test_audioread_load_with_duration(self):
67
+ signal, sr_native = lambdaSpeechToScore.audioread_load(input_file_test_de, duration=129653 / 44100)
68
+ self.assertEqual(sr_native, 44100)
69
+ self.assertEqual(signal.shape[0], 129653) # Assuming the duration is ~2,93 seconds long (129653 / 44100)
70
+ hash_output = hash_calculate(signal, is_file=False)
71
+ self.assertEqual(hash_output, b'3bfNuuMk0ov5+E77cUZmzjijfBUaMxuy1mrPmyjFyeo=')
72
+
73
+ def test_audioread_load_with_offset_and_duration(self):
74
+ signal, sr_native = lambdaSpeechToScore.audioread_load(input_file_test_de, offset=0.5, duration=129653 / 44100)
75
+ self.assertEqual(sr_native, 44100)
76
+ self.assertEqual(signal.shape[0], 107603) # Assuming the duration is 5 seconds starting from 2 seconds offset
77
+ hash_output = hash_calculate(signal, is_file=False)
78
+ self.assertEqual(hash_output, b'QiDTDSZ4xAUniANNz4M43oa2FwpTSjvzW3IsKyqCVeE=')
79
+
80
+ def test_audioread_load_empty_file(self):
81
+ # import soundfile as sf
82
+ # import numpy as np
83
+ # signal, sr_native = lambdaSpeechToScore.audioread_load(input_file_test_de, offset=5, duration=129653 / 44100)
84
+ # sf.write(EVENTS_FOLDER / "test_empty.wav", data=signal, samplerate=44100)
85
+ input_empty = EVENTS_FOLDER / "test_empty.wav"
86
+ hash_input_empty = hash_calculate(input_empty, is_file=True)
87
+ self.assertEqual(hash_input_empty, b'i4+6/oZ5B2RUQpdW+nLxHV9ELIc4HMakKFRR2Cap5ik=')
88
+ signal, sr_native = lambdaSpeechToScore.audioread_load(input_empty)
89
+ self.assertEqual(sr_native, 44100)
90
+ self.assertEqual(signal.shape, (0, )) # Assuming the file is empty
91
+ hash_output = hash_calculate(signal, is_file=False)
92
+ self.assertEqual(hash_output, b'47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=')
93
+
94
+
95
+ if __name__ == "__main__":
96
+ unittest.main()
tests/{test_lambdaTTS.py β†’ lambdas/test_lambdaTTS.py} RENAMED
File without changes
tests/{test_serialize.py β†’ utils/test_serialize.py} RENAMED
File without changes
tests/{test_utilities.py β†’ utils/test_utilities.py} RENAMED
File without changes