diff --git a/tests/facial/test_api_facial_activity.py b/tests/facial/test_api_facial_activity.py new file mode 100644 index 00000000..ed491552 --- /dev/null +++ b/tests/facial/test_api_facial_activity.py @@ -0,0 +1,42 @@ +# import numpy as np +import pandas as pd +from numpy.testing import assert_allclose +from pytest import mark + + +# @mark.smoke +# @mark.body +@mark.facial +class FacialTest: + def test_get_landmark(self, processing_facial_activity): + df_act = pd.read_csv("tests/test_data/landmark.csv") + res = processing_facial_activity.get_landmark() + + assert_allclose(df_act.mean(), res.mean(), rtol=0.1, atol=1e-8) + assert_allclose(df_act.std(), res.std(), rtol=0.1, atol=1e-8) + + def test_get_action_unit(self, processing_facial_activity): + + df_act = pd.read_csv("tests/test_data/action_unit.csv") + res = processing_facial_activity.get_action_unit() + + assert_allclose(df_act.mean(), res.mean(), rtol=0.1, atol=1e-8) + assert_allclose(df_act.std(), res.std(), rtol=0.1, atol=1e-8) + + def test_get_asymmetry(self, processing_facial_activity): + actual_mean = [2.58260995, 3.34416172, 3.0563894, 2.94777878] + actual_std = [1.74161635, 2.17995634, 2.19173686, 1.82435901] + res = processing_facial_activity.get_asymmetry() + + assert_allclose(actual_mean, res.mean(), rtol=0.1, atol=1e-8) + assert_allclose(actual_std, res.std(), rtol=0.1, atol=1e-8) + + def test_get_expressivity(self, processing_facial_activity): + df_act = pd.read_csv("tests/test_data/expressivity.csv") + res = processing_facial_activity.get_expressivity() + + assert_allclose(df_act.mean(), res.mean(), rtol=0.35, atol=1e-8) + assert_allclose(df_act.std(), res.std(), rtol=0.35, atol=1e-8) + + def test_dummy_facial(self): + assert True diff --git a/tests/movement/test_api_movement.py b/tests/movement/test_api_movement.py new file mode 100644 index 00000000..c53cbca9 --- /dev/null +++ b/tests/movement/test_api_movement.py @@ -0,0 +1,86 @@ +# import numpy as np +from numpy.testing import assert_allclose +from pytest import mark + + +# @mark.smoke +# @mark.body +@mark.movement +class MovementTest: + def test_get_head_movement(self, processing_movement): + actual_mean = [1.3946, 0.3011, -0.1183, 0.003, 0.0094] + actual_std = [1.2644, 0.0786, 0.0649, 0.0342, 0.008] + res = processing_movement.get_head_movement() + + assert_allclose(actual_mean, res.mean(), rtol=0.1, atol=1e-8) + assert_allclose(actual_std, res.std(), rtol=0.1, atol=1e-8) + + def test_get_eye_blink(self, processing_movement): + actual_mean = [0.1101, 455.5, 2.2931, 29.0] + actual_std = [0.0241, 311.8611, 1.1407, 0.0] + res = processing_movement.get_eye_blink() + + assert_allclose(actual_mean, res.mean(), rtol=0.1, atol=1e-8) + assert_allclose(actual_std, res.std(), rtol=0.1, atol=1e-8) + + def test_get_eye_gaze(self, processing_movement): + actual_mean = [0.2292, 0.4174, -0.8761, 0.0209, 0.4191, -0.9046, 0.0145, 0.0132] + actual_std = [0.0546, 0.048, 0.0218, 0.0462, 0.0542, 0.0243, 0.0156, 0.0169] + res = processing_movement.get_eye_gaze() + + assert_allclose(actual_mean, res.mean(), rtol=0.1, atol=1e-8) + assert_allclose(actual_std, res.std(), rtol=0.1, atol=1e-8) + + def test_get_facial_tremor(self, processing_movement): + actual_mean = [ + 8.5948, + 3.8759, + 0.7286, + 0.2546, + 3.7195, + 2.8068, + 0.7231, + 0.4562, + 6.7215, + 3.5861, + 0.8253, + 0.3912, + 2.8608, + 2.1741, + 0.8614, + 0.6464, + 3.6781, + 2.6698, + 0.887, + 0.5783, + 0.0, + 0.0, + 0.6772, + 1.0, + 0.7655, + 0.5476, + 0.7504, + 0.8978, + 1.9713, + 1.4991, + 0.9381, + 0.7761, + 2.706, + 2.019, + 0.9885, + 0.7138, + ] + + res = processing_movement.get_facial_tremor() + + assert_allclose(actual_mean, res.mean(), rtol=0.1, atol=1e-8) + + def test_get_vocal_tremor(self, processing_movement): + actual_mean = [4.23, 9.437, 7.634, 7.38, 61.642, 54.287] + + res = processing_movement.get_vocal_tremor() + + assert_allclose(actual_mean, res.mean(), rtol=0.1, atol=1e-8) + + def test_dummy_movement(self): + assert True diff --git a/tests/speech/test_api_speech.py b/tests/speech/test_api_speech.py new file mode 100644 index 00000000..ceb39bf1 --- /dev/null +++ b/tests/speech/test_api_speech.py @@ -0,0 +1,76 @@ +import numpy as np +from pytest import mark + + +@mark.non_docker +@mark.speech +class SpeechTest: + def test_dummy_3(self): + assert True + + def test_get_transcribe(self, processing_speech_mp4, processing_speech_wav): + actual_totaltime = 87.978685 + len_words_count = 57 + + res_mp4 = processing_speech_mp4.get_transcribe().to_dataframe() + audio_duration_mp4 = res_mp4["nlp_totalTime"].item() + transcribed_text_mp4 = res_mp4["nlp_transcribe"].item() + + res_wav = processing_speech_wav.get_transcribe().to_dataframe() + audio_duration_wav = res_wav["nlp_totalTime"].item() + transcribed_text_wav = res_wav["nlp_transcribe"].item() + + # test if duration is matched + assert np.isclose(audio_duration_mp4, actual_totaltime, rtol=0.1, atol=1e-8) + assert np.isclose(audio_duration_wav, actual_totaltime, rtol=0.1, atol=1e-8) + + # test if there is transcribed text or not + assert type(transcribed_text_mp4) == str + assert type(transcribed_text_wav) == str + + # test the length of the text + assert np.isclose( + len(transcribed_text_mp4.split(" ")), len_words_count, rtol=0.5, atol=1e-8 + ) + assert np.isclose( + len(transcribed_text_wav.split(" ")), len_words_count, rtol=0.5, atol=1e-8 + ) + + def test_get_speech_features(self, processing_speech_mp4, processing_speech_wav): + # actual = [ + # 1.0, + # 2.0, + # 2.0, + # 1.0, + # 1.0, + # 6.0, + # 6.0, + # 11.0, + # 11.0, + # 5.0, + # 5.0, + # 15.0, + # 15.0, + # -0.8256, + # 0.08860759493670886, + # 38.873052120437336, + # 87.97868480725624, + # ] + + res_mp4 = ( + processing_speech_mp4.get_speech_features() + .to_dataframe() + .drop(columns="dbm_master_url") + ) + res_wav = ( + processing_speech_wav.get_speech_features() + .to_dataframe() + .drop(columns="dbm_master_url") + ) + desired_mp4 = np.array((res_mp4.iloc[0])) + desired_wav = np.array((res_wav.iloc[0])) + + # check if there is any zero value or not + for v1, v2 in zip(desired_mp4, desired_wav): + assert bool(v1) + assert bool(v2) diff --git a/tests/verbal_acoustics/test_api_acoustics.py b/tests/verbal_acoustics/test_api_acoustics.py new file mode 100644 index 00000000..4eb9e0b9 --- /dev/null +++ b/tests/verbal_acoustics/test_api_acoustics.py @@ -0,0 +1,183 @@ +import numpy as np +from numpy.testing import assert_allclose +from pytest import mark + + +@mark.non_docker +@mark.acoustic +class AcousticTest: + def test_get_audio_intensity( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = 52.867660826299 + actual_std = 6.357796 + + res_mp4 = processing_verbal_acoustics_mp4.get_audio_intensity() + res_wav = processing_verbal_acoustics_wav.get_audio_intensity() + + # testing mean actual vs desired + assert np.isclose(res_mp4.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + + # testing std actual vs desired + assert np.isclose(res_mp4.std().item(), actual_std, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.std().item(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_pitch_frequency( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = 27.270735 + actual_std = 58.073703 + + res_mp4 = processing_verbal_acoustics_mp4.get_pitch_frequency() + res_wav = processing_verbal_acoustics_wav.get_pitch_frequency() + + assert np.isclose(res_mp4.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + + assert np.isclose(res_mp4.std().item(), actual_std, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.std().item(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_formant_frequency( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = [679.47914618, 1788.237625, 2931.83885151, 4075.29506138] + actual_std = [366.35888699, 472.92129736, 543.15256087, 431.39331643] + + res_mp4 = processing_verbal_acoustics_mp4.get_formant_frequency() + res_wav = processing_verbal_acoustics_wav.get_formant_frequency() + + assert_allclose(res_mp4.mean(), actual_mean, rtol=0.1, atol=1e-8) + assert_allclose(res_wav.mean(), actual_mean, rtol=0.1, atol=1e-8) + + assert_allclose(res_mp4.std(), actual_std, rtol=0.1, atol=1e-8) + assert_allclose(res_wav.std(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_harmonic_noise( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = 3.154794 + actual_std = 7.389723 + + res_mp4 = processing_verbal_acoustics_mp4.get_harmonic_noise() + res_wav = processing_verbal_acoustics_wav.get_harmonic_noise() + + assert np.isclose(res_mp4.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + + assert np.isclose(res_mp4.std().item(), actual_std, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.std().item(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_glottal_noise( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = 0.86287177 + actual_std = 0.106516901 + + res_mp4 = processing_verbal_acoustics_mp4.get_glottal_noise() + res_wav = processing_verbal_acoustics_wav.get_glottal_noise() + + assert np.isclose(res_mp4.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + + assert np.isclose(res_mp4.std().item(), actual_std, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.std().item(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_jitter( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = 0.041403506 + actual_std = 0.026209854 + + res_mp4 = processing_verbal_acoustics_mp4.get_jitter() + res_wav = processing_verbal_acoustics_wav.get_jitter() + + assert np.isclose(res_mp4.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + + assert np.isclose(res_mp4.std().item(), actual_std, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.std().item(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_shimmer( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = 0.2018721891 + actual_std = 0.0584668629 + + res_mp4 = processing_verbal_acoustics_mp4.get_shimmer() + res_wav = processing_verbal_acoustics_wav.get_shimmer() + + assert np.isclose(res_mp4.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.mean().item(), actual_mean, rtol=0.1, atol=1e-8) + + assert np.isclose(res_mp4.std().item(), actual_std, rtol=0.1, atol=1e-8) + assert np.isclose(res_wav.std().item(), actual_std, rtol=0.1, atol=1e-8) + + def test_get_pause_characteristics( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = [84.76, 28.84, 32, 55.92, 0.65974516] + + res_mp4 = processing_verbal_acoustics_mp4.get_pause_characteristics() + res_wav = processing_verbal_acoustics_wav.get_pause_characteristics() + + assert_allclose(res_mp4.mean(), actual_mean, rtol=0.1, atol=1e-8) + assert_allclose(res_wav.mean(), actual_mean, rtol=0.1, atol=1e-8) + + def test_get_voice_prevalence( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = [1865.0, 8794.0, 21.207641573800316] + + res_mp4 = processing_verbal_acoustics_mp4.get_voice_prevalence() + res_wav = processing_verbal_acoustics_wav.get_voice_prevalence() + + assert_allclose(res_mp4.mean(), actual_mean, rtol=0.1, atol=1e-8) + assert_allclose(res_wav.mean(), actual_mean, rtol=0.1, atol=1e-8) + + def test_get_mfcc( + self, processing_verbal_acoustics_mp4, processing_verbal_acoustics_wav + ): + actual_mean = [ + 491.835, + -37.714, + 82.164, + 64.293, + -33.829, + 54.35, + 6.563, + -6.669, + 31.392, + -8.672, + 9.302, + 8.096, + ] + actual_std = [ + 71.555, + 83.91, + 65.506, + 32.296, + 38.059, + 35.283, + 30.122, + 23.462, + 21.292, + 21.183, + 18.607, + 17.101, + ] + + res_mp4 = processing_verbal_acoustics_mp4.get_mfcc() + res_wav = processing_verbal_acoustics_wav.get_mfcc() + + assert_allclose(res_mp4.mean(), actual_mean, rtol=0.1, atol=1e-8) + assert_allclose(res_wav.mean(), actual_mean, rtol=0.1, atol=1e-8) + + assert_allclose(res_mp4.std(), actual_std, rtol=0.1, atol=1e-8) + assert_allclose(res_wav.std(), actual_std, rtol=0.1, atol=1e-8) + + def test_dummy_1(self): + assert True + + def test_dummy_2(self): + assert True