Skip to content

Commit f6076e3

Browse files
committed
Add tests for sync and async response tests
1 parent b9101d6 commit f6076e3

7 files changed

+151
-67
lines changed

test/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# coding: utf-8
2+
3+
"""
4+
DeepAffects
5+
6+
OpenAPI Specification of DeepAffects APIs
7+
8+
OpenAPI spec version: 0.1.0
9+
10+
Generated by: https://github.com/swagger-api/swagger-codegen.git
11+
"""
12+
13+
14+
from __future__ import absolute_import
15+
16+
# import apis into sdk package
17+
from .test_base_setup import DIR

test/data/reconstructed.wav

-50.7 KB
Binary file not shown.

test/test_denoise_api.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
import os
1313
import sys
1414
import unittest
15-
15+
import uuid
1616
import deepaffects
1717
from deepaffects.models.audio import Audio
1818
from .test_base_setup import DIR
1919

2020

21+
2122
class TestDenoiseApi(unittest.TestCase):
2223
""" DenoiseApi unit test stubs """
2324

@@ -29,9 +30,21 @@ def sdr(clean, reconstructed):
2930
def setUp(self):
3031
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
3132
self.api = deepaffects.DenoiseApi()
33+
self.webhook_url = os.environ["DEEPAFFECTS_API_WEBHOOK"]
3234

3335
def tearDown(self):
3436
pass
37+
def test_async_denoise_audio(self):
38+
"""
39+
Test case for sync_denoise_audio
40+
41+
Denoise an audio file
42+
"""
43+
self.request_id = str(uuid.uuid4())
44+
test_noisy_audio = os.path.normpath(os.path.join(DIR, "data/noisy.wav"))
45+
body = Audio.from_file(file_name=test_noisy_audio)
46+
api_response = self.api.async_denoise_audio(body=body, webhook=self.webhook_url, request_id=self.request_id)
47+
assert api_response.request_id, self.request_id
3548

3649
def test_sync_denoise_audio(self):
3750
"""
@@ -45,8 +58,7 @@ def test_sync_denoise_audio(self):
4558
body = Audio.from_file(file_name=test_noisy_audio)
4659
api_response = self.api.sync_denoise_audio(body=body)
4760
api_response.to_file(test_reconstructed_audio)
48-
self.assertTrue(TestDenoiseApi.sdr(test_clean_audio, test_reconstructed_audio) > 5)
49-
pass
61+
assert TestDenoiseApi.sdr(test_clean_audio, test_reconstructed_audio) > 5
5062

5163

5264
if __name__ == '__main__':

test/test_diarize_api_v2.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import os
1313
import sys
1414
import unittest
15-
1615
import deepaffects
1716
from deepaffects import Audio
1817
from deepaffects.rest import ApiException
@@ -27,23 +26,36 @@ class TestDiarizeApiV2(unittest.TestCase):
2726
def setUp(self):
2827
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
2928
self.webhook_url = os.environ["DEEPAFFECTS_API_WEBHOOK"]
30-
self.api = deepaffects.apis.diarize_api_v2.DiarizeApiV2()
31-
self.request_id = str(uuid.uuid4())
29+
self.api = deepaffects.apis.diarize_api_v2.DiarizeApiV2()
3230

3331
def tearDown(self):
3432
pass
3533

36-
def test_async_diarize_audio(self):
34+
def test_async_diarize_audio_with_request_id(self):
3735
"""
3836
Test case for diarize_audio
3937
4038
Diarize an audio file
4139
"""
40+
self.request_id = str(uuid.uuid4())
4241
test_conversation_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
43-
body = Audio.from_file(file_name=test_conversation_audio)
44-
42+
body = Audio.from_file(file_name=test_conversation_audio)
4543
api_response = self.api.async_diarize_audio(body=body, webhook=self.webhook_url, request_id=self.request_id)
46-
self.assertTrue(api_response.request_id, self.request_id)
44+
print(api_response)
45+
assert api_response.request_id, self.request_id
46+
47+
def test_async_diarize_audio_without_request_id(self):
48+
"""
49+
Test case for diarize_audio
50+
51+
Diarize an audio file
52+
"""
53+
test_conversation_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
54+
body = Audio.from_file(file_name=test_conversation_audio)
55+
api_response = self.api.async_diarize_audio(body=body, webhook=self.webhook_url)
56+
print(api_response)
57+
assert api_response.request_id
58+
4759

4860
if __name__ == '__main__':
49-
unittest.main()
61+
unittest.main()

test/test_emotion_api.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,49 @@
1515
import unittest
1616

1717
from deepaffects import Audio
18-
18+
import uuid
1919
import deepaffects
2020
from deepaffects.rest import ApiException
2121
from deepaffects.apis.emotion_api import EmotionApi
2222
from deepaffects.models.emotion_score import EmotionScore
23-
from .test_base_setup import DIR, AudioTest
23+
from .test_base_setup import DIR
24+
2425

2526

2627
class TestEmotionApi(unittest.TestCase):
2728
""" EmotionApi unit test stubs """
2829

2930
def setUp(self):
3031
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
32+
self.webhook_url = os.environ["DEEPAFFECTS_API_WEBHOOK"]
3133
self.api = deepaffects.apis.emotion_api.EmotionApi()
3234

3335
def tearDown(self):
3436
pass
3537

36-
def test_async_recognise_emotion(self):
38+
def test_async_recognise_emotion_with_request_id(self):
3739
"""
3840
Test case for async_recognise_emotion
3941
4042
Find emotion in an audio file
4143
"""
42-
pass
44+
self.request_id = str(uuid.uuid4())
45+
test_happy_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
46+
body = Audio.from_file(file_name=test_happy_audio)
47+
api_response = self.api.async_recognise_emotion(body=body, webhook=self.webhook_url, request_id=self.request_id)
48+
print(api_response)
49+
assert api_response.request_id, self.request_id
50+
def test_async_recognise_emotion_without_request_id(self):
51+
"""
52+
Test case for async_recognise_emotion
53+
54+
Find emotion in an audio file
55+
"""
56+
test_happy_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
57+
body = Audio.from_file(file_name=test_happy_audio)
58+
api_response = self.api.async_recognise_emotion(body=body, webhook=self.webhook_url)
59+
print(api_response)
60+
assert api_response.request_id
4361

4462
def test_sync_recognise_emotion(self):
4563
"""
@@ -50,6 +68,7 @@ def test_sync_recognise_emotion(self):
5068
test_happy_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
5169
body = Audio.from_file(file_name=test_happy_audio)
5270
api_response = self.api.sync_recognise_emotion(body=body)
71+
print(api_response)
5372
for obj in api_response:
5473
if obj.emotion == 'Happy':
5574
assert obj.score > 0.8

test/test_text_recoginse_emotion.py

-52
This file was deleted.

test/test_text_recognise_emotion.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# coding: utf-8
2+
3+
"""
4+
DeepAffects
5+
6+
OpenAPI spec version: v1
7+
"""
8+
9+
10+
from __future__ import absolute_import
11+
12+
import os
13+
import sys
14+
import unittest
15+
16+
sys.path.insert(0, '/Users/VivekNimkarde/DeepAffects/deepaffects-python')
17+
import deepaffects
18+
from deepaffects import Audio
19+
from deepaffects.rest import ApiException
20+
from .test_base_setup import DIR
21+
import uuid
22+
23+
24+
class TestTextEmootion(unittest.TestCase):
25+
""" Text Emotion unit test stubs """
26+
27+
def setUp(self):
28+
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
29+
self.api = deepaffects.apis.emotion_api.EmotionApi()
30+
31+
def tearDown(self):
32+
pass
33+
34+
def test_sync_diarize_audio_sample_text(self):
35+
"""
36+
Test case for Text Emotion
37+
38+
Diarize text file
39+
"""
40+
41+
body = {
42+
"content": "Awesome"
43+
}
44+
api_response = self.api.sync_text_recognise_emotion(body=body)
45+
print(api_response)
46+
assert api_response['response']['trust']> 0.8
47+
def test_sync_diarize_audio_check_response_field_exists(self):
48+
"""
49+
Test case for Text Emotion
50+
51+
Diarize text file
52+
"""
53+
54+
body = {
55+
"content": "Awesome"
56+
}
57+
api_response = self.api.sync_text_recognise_emotion(body=body)
58+
print(api_response)
59+
assert api_response['response']
60+
def test_sync_diarize_audio_check_version_field_exists(self):
61+
"""
62+
Test case for Text Emotion
63+
64+
Diarize text file
65+
"""
66+
67+
body = {
68+
"content": "Awesome"
69+
}
70+
api_response = self.api.sync_text_recognise_emotion(body=body)
71+
print(api_response)
72+
assert api_response['version']
73+
74+
75+
if __name__ == '__main__':
76+
unittest.main()

0 commit comments

Comments
 (0)