Skip to content

Commit

Permalink
[tests] add faker provider for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daggx committed Nov 21, 2023
1 parent f1fea02 commit 210aade
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions edenai_apis/apis/faker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .faker_api import FakerApi
71 changes: 71 additions & 0 deletions edenai_apis/apis/faker/faker_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Fake provider class used for tests
"""
from io import BufferedReader
from random import randint
from time import sleep
from typing import Dict, List, Optional

from edenai_apis.features import AudioInterface, ProviderInterface
from edenai_apis.features.audio import SpeechToTextAsyncDataClass, SpeechDiarization
from edenai_apis.utils.types import (
AsyncBaseResponseType,
AsyncLaunchJobResponseType,
AsyncPendingResponseType,
AsyncResponseType,
)

class FakerApi(ProviderInterface, AudioInterface):
provider_name = "faker"

def __init__(self, api_keys: Dict = {}) -> None:
super().__init__()

def audio__speech_to_text_async__launch_job(
self,
file: str,
language: str,
speakers: int,
profanity_filter: bool,
vocabulary: list,
audio_attributes: tuple,
file_url: str = "",
provider_params: dict = dict(),
) -> AsyncLaunchJobResponseType:
sleep(randint(1, 3))
return AsyncLaunchJobResponseType(provider_job_id="SomeFakeID")

def audio__speech_to_text_async__get_job_result(
self, provider_job_id: str
) -> AsyncBaseResponseType[SpeechToTextAsyncDataClass]:
sleep(randint(1, 3))

standardized_response = SpeechToTextAsyncDataClass(
text="empty",
diarization=SpeechDiarization(
total_speakers = 1
)
)
provider_correct_response = AsyncResponseType[SpeechToTextAsyncDataClass](
original_response={},
standardized_response=standardized_response,
provider_job_id=provider_job_id,
)

chance_to_stop = randint(2, 1000)

if provider_job_id == 'FINISHED':
return provider_correct_response
if provider_job_id == 'ERROR':
raise Exception("error")
if provider_job_id == "pending":
return AsyncPendingResponseType[SpeechToTextAsyncDataClass](
provider_job_id=provider_job_id
)
if chance_to_stop < 250:
return provider_correct_response
if chance_to_stop > 994:
raise Exception("error")
return AsyncPendingResponseType[SpeechToTextAsyncDataClass](
provider_job_id=provider_job_id
)
53 changes: 53 additions & 0 deletions edenai_apis/apis/faker/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"audio": {
"speech_to_text_async": {
"constraints": {
"languages": [
"ar",
"bg",
"ca",
"hr",
"cs",
"da",
"nl",
"en",
"fa",
"fi",
"fr",
"de",
"el",
"he",
"hi",
"hu",
"id",
"it",
"ja",
"ko",
"lv",
"lt",
"ms",
"cmn",
"no",
"pl",
"pt",
"ro",
"ru",
"sk",
"sl",
"es",
"sv",
"ta",
"te",
"tr"
],
"file_extensions": [
"flac",
"wav",
"mp3"
],
"allow_null_language": true
},
"version": "v1"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"status": "succeeded",
"provider_job_id": "SomeFakeID",
"original_response": {},
"standardized_response": {
"text": "empty",
"diarization": {
"total_speakers": 1,
"entries": [],
"error_message": null
}
}
}

0 comments on commit 210aade

Please sign in to comment.