Skip to content

Commit

Permalink
Add tests for sync and async reposne tests
Browse files Browse the repository at this point in the history
  • Loading branch information
viveknimkarde committed Jun 21, 2018
1 parent b9101d6 commit 217cd50
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 21 deletions.
17 changes: 17 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# coding: utf-8

"""
DeepAffects
OpenAPI Specification of DeepAffects APIs
OpenAPI spec version: 0.1.0
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

# import apis into sdk package
from .test_base_setup import DIR
Binary file modified test/data/reconstructed.wav
Binary file not shown.
18 changes: 15 additions & 3 deletions test/test_denoise_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import os
import sys
import unittest

import uuid
import deepaffects
from deepaffects.models.audio import Audio
from .test_base_setup import DIR



class TestDenoiseApi(unittest.TestCase):
""" DenoiseApi unit test stubs """

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

def tearDown(self):
pass
def test_async_denoise_audio(self):
"""
Test case for sync_denoise_audio
Denoise an audio file
"""
self.request_id = str(uuid.uuid4())
test_noisy_audio = os.path.normpath(os.path.join(DIR, "data/noisy.wav"))
body = Audio.from_file(file_name=test_noisy_audio)
api_response = self.api.async_denoise_audio(body=body, webhook=self.webhook_url, request_id=self.request_id)
assert api_response.request_id, self.request_id

def test_sync_denoise_audio(self):
"""
Expand All @@ -45,8 +58,7 @@ def test_sync_denoise_audio(self):
body = Audio.from_file(file_name=test_noisy_audio)
api_response = self.api.sync_denoise_audio(body=body)
api_response.to_file(test_reconstructed_audio)
self.assertTrue(TestDenoiseApi.sdr(test_clean_audio, test_reconstructed_audio) > 5)
pass
assert TestDenoiseApi.sdr(test_clean_audio, test_reconstructed_audio) > 5


if __name__ == '__main__':
Expand Down
28 changes: 20 additions & 8 deletions test/test_diarize_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os
import sys
import unittest

import deepaffects
from deepaffects import Audio
from deepaffects.rest import ApiException
Expand All @@ -27,23 +26,36 @@ class TestDiarizeApiV2(unittest.TestCase):
def setUp(self):
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
self.webhook_url = os.environ["DEEPAFFECTS_API_WEBHOOK"]
self.api = deepaffects.apis.diarize_api_v2.DiarizeApiV2()
self.request_id = str(uuid.uuid4())
self.api = deepaffects.apis.diarize_api_v2.DiarizeApiV2()

def tearDown(self):
pass

def test_async_diarize_audio(self):
def test_async_diarize_audio_with_request_id(self):
"""
Test case for diarize_audio
Diarize an audio file
"""
self.request_id = str(uuid.uuid4())
test_conversation_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
body = Audio.from_file(file_name=test_conversation_audio)

body = Audio.from_file(file_name=test_conversation_audio)
api_response = self.api.async_diarize_audio(body=body, webhook=self.webhook_url, request_id=self.request_id)
self.assertTrue(api_response.request_id, self.request_id)
print(api_response)
assert api_response.request_id, self.request_id

def test_async_diarize_audio_without_request_id(self):
"""
Test case for diarize_audio
Diarize an audio file
"""
test_conversation_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
body = Audio.from_file(file_name=test_conversation_audio)
api_response = self.api.async_diarize_audio(body=body, webhook=self.webhook_url)
print(api_response)
assert api_response.request_id


if __name__ == '__main__':
unittest.main()
unittest.main()
27 changes: 23 additions & 4 deletions test/test_emotion_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,49 @@
import unittest

from deepaffects import Audio

import uuid
import deepaffects
from deepaffects.rest import ApiException
from deepaffects.apis.emotion_api import EmotionApi
from deepaffects.models.emotion_score import EmotionScore
from .test_base_setup import DIR, AudioTest
from .test_base_setup import DIR



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

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

def tearDown(self):
pass

def test_async_recognise_emotion(self):
def test_async_recognise_emotion_with_request_id(self):
"""
Test case for async_recognise_emotion
Find emotion in an audio file
"""
pass
self.request_id = str(uuid.uuid4())
test_happy_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
body = Audio.from_file(file_name=test_happy_audio)
api_response = self.api.async_recognise_emotion(body=body, webhook=self.webhook_url, request_id=self.request_id)
print(api_response)
assert api_response.request_id, self.request_id
def test_async_recognise_emotion_without_request_id(self):
"""
Test case for async_recognise_emotion
Find emotion in an audio file
"""
test_happy_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
body = Audio.from_file(file_name=test_happy_audio)
api_response = self.api.async_recognise_emotion(body=body, webhook=self.webhook_url)
print(api_response)
assert api_response.request_id

def test_sync_recognise_emotion(self):
"""
Expand All @@ -50,6 +68,7 @@ def test_sync_recognise_emotion(self):
test_happy_audio = os.path.normpath(os.path.join(DIR, "data/happy.mp3"))
body = Audio.from_file(file_name=test_happy_audio)
api_response = self.api.sync_recognise_emotion(body=body)
print(api_response)
for obj in api_response:
if obj.emotion == 'Happy':
assert obj.score > 0.8
Expand Down
36 changes: 30 additions & 6 deletions test/test_text_recoginse_emotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
import sys
import unittest

sys.path.insert(0, '/Users/VivekNimkarde/DeepAffects/deepaffects-python')
import deepaffects
from deepaffects import Audio
from deepaffects.rest import ApiException
from deepaffects.apis.diarize_api_v2 import DiarizeApiV2
DIR = os.path.dirname(os.path.realpath(__file__))
from .test_base_setup import DIR
import uuid


class TestTextEmootion(unittest.TestCase):
""" Text Emotion unit test stubs """

def setUp(self):
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
self.webhook_url = os.environ["DEEPAFFECTS_API_WEBHOOK"]
deepaffects.configuration.api_key['apikey'] = os.environ['DEEPAFFECTS_API_KEY']
self.api = deepaffects.apis.emotion_api.EmotionApi()
self.request_id = str(uuid.uuid4())

def tearDown(self):
pass

def test_async_diarize_audio(self):
def test_sync_diarize_audio_sample_text(self):
"""
Test case for Text Emotion
Expand All @@ -46,6 +44,32 @@ def test_async_diarize_audio(self):
api_response = self.api.sync_text_recognise_emotion(body=body)
print(api_response)
assert api_response['response']['trust']> 0.8
def test_sync_diarize_audio_check_response_field_exists(self):
"""
Test case for Text Emotion
Diarize text file
"""

body = {
"content": "Awesome"
}
api_response = self.api.sync_text_recognise_emotion(body=body)
print(api_response)
assert api_response['response']
def test_sync_diarize_audio_check_version_field_exists(self):
"""
Test case for Text Emotion
Diarize text file
"""

body = {
"content": "Awesome"
}
api_response = self.api.sync_text_recognise_emotion(body=body)
print(api_response)
assert api_response['version']


if __name__ == '__main__':
Expand Down

0 comments on commit 217cd50

Please sign in to comment.