11# -*- coding: utf-8 -*-
2+ """
3+ Test `ivona_api.ivona_api` module
4+ """
25from __future__ import absolute_import , unicode_literals
36
47import os
58import tempfile
6- import filecmp
79
810import pytest
911import requests
1012import requests_aws4auth
11- from flaky import flaky
1213
1314from ivona_api import IvonaAPI
1415from ivona_api .ivona_api import IVONA_ACCESS_KEY_ENV , IVONA_SECRET_KEY_ENV
1516
1617
17- BASE_DIR = os .path .dirname (os .path .realpath (__file__ ))
18-
19-
2018# Tests
2119def test_init ():
2220 """Test initializing"""
2321 ivona_api = IvonaAPI ()
2422
25- assert ivona_api ._access_key == os .environ [ IVONA_ACCESS_KEY_ENV ]
26- assert ivona_api ._secret_key == os .environ [ IVONA_SECRET_KEY_ENV ]
23+ assert ivona_api ._access_key == os .getenv ( IVONA_ACCESS_KEY_ENV )
24+ assert ivona_api ._secret_key == os .getenv ( IVONA_SECRET_KEY_ENV )
2725
2826 assert ivona_api .region == 'eu-west-1'
2927 assert ivona_api .codec == 'mp3'
@@ -47,7 +45,6 @@ def test_init_no_auth_data(monkeypatch):
4745 IvonaAPI ()
4846
4947
50- @flaky
5148def test_available_voices ():
5249 """Test getting available voices"""
5350 ivona_api = IvonaAPI ()
@@ -62,20 +59,20 @@ def test_available_voices():
6259 )
6360
6461
65- @flaky
66- @pytest .mark .parametrize ('voice_name,voice_language,content,org_file' , [
67- ('Salli' , 'en-US' , 'Hello world' , 'files/salli_hello_world.mp3' ),
68- ('Maja' , 'pl-PL' , 'Dzień dobry' , 'files/maja_dzien_dobry.mp3' ),
62+ @pytest .mark .parametrize ('voice_name,voice_language,content' , [
63+ ('Salli' , 'en-US' , 'Hello world' ),
64+ ('Maja' , 'pl-PL' , 'Dzień dobry' ),
6965])
70- def test_text_to_speech (voice_name , voice_language , content , org_file ):
66+ def test_text_to_speech (voice_name , voice_language , content ):
7167 """Test synthesizing text to audio files"""
7268 ivona_api = IvonaAPI (
7369 voice_name = voice_name , language = voice_language ,
7470 )
7571
76- org_file = os .path .join (BASE_DIR , org_file )
77-
7872 with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
7973 ivona_api .text_to_speech (content , temp_file )
8074
81- assert filecmp .cmp (org_file , temp_file .name )
75+ assert os .path .getsize (temp_file .name ) > 0
76+
77+
78+ # TODO: Fully mock API responses and don't require API keys for running tests
0 commit comments