Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests #6

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
flake8 src tests --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 src tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
- name: Run unit tests
run: |
invoke test
- name: Generate coverage report
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ python -m nltk.downloader punkt -d ./venv/nltk_data

# Run tests and generate coverage report
invoke test cov

# Run integration tests
invoke integration
```

## Running Tasks
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ docs = [
test = [
"coverage",
"parameterized",
"pytest",
]
amazon-polly = [
"boto3",
Expand Down
8 changes: 7 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
@task
def test(c):
"""Run tests with coverage."""
c.run('coverage run --branch --source=src -m unittest')
c.run('coverage run --branch --source=src -m pytest tests/unit')


@task
def integration(c):
"""Run integration tests."""
c.run('pytest tests/integration')


@task
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions tests/integration/test_all_ttss_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Type

import boto3
from google.cloud.texttospeech import TextToSpeechClient, VoiceSelectionParams
from parameterized import parameterized

from voicebox.tts import *

TTS_CLASSES = (
AmazonPolly,
ElevenLabsTTS,
ESpeakNG,
GoogleCloudTTS,
gTTS,
PicoTTS,
Pyttsx3TTS,
)


def get_speech_name_func(testcase_func, param_num, param) -> str:
test_name = testcase_func.__name__
tts_class_name = param.args[0].__name__
return f'{test_name}({tts_class_name})'


@parameterized.expand(TTS_CLASSES, name_func=get_speech_name_func)
def test_get_speech(tts_class: Type[TTS]):
if tts_class is AmazonPolly:
session = boto3.Session(region_name='us-east-1', profile_name='polly')
client = session.client('polly')
tts = AmazonPolly(client=client, voice_id='Aditi')

elif tts_class is GoogleCloudTTS:
tts = GoogleCloudTTS(
client=TextToSpeechClient(),
voice_params=VoiceSelectionParams(language_code='en-US'),
)

else:
tts = tts_class()

audio = tts.get_speech('Hello, world!')
audio.check()
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from parameterized import parameterized

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.audio import Audio
from voicebox.effects.chain import SeriesChain, ParallelChain

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest.mock import Mock

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.sinks.distributor import Distributor


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from parameterized import parameterized

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.sinks.sounddevice import SoundDevice, Device, Latency


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_audio.py → tests/unit/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from parameterized import parameterized

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.audio import Audio


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest.mock import Mock, call

from tests.utils import assert_called_with_exactly, build_audio
from unit.utils import assert_called_with_exactly, build_audio
from voicebox.effects.normalize import Normalize
from voicebox.sinks.sounddevice import SoundDevice
from voicebox.tts.picotts import PicoTTS
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from mypy_boto3_polly.literals import VoiceIdType

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.ssml import SSML
from voicebox.tts.amazonpolly import AmazonPolly

Expand Down
2 changes: 1 addition & 1 deletion tests/tts/test_cache.py → tests/unit/tts/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cachetools
from parameterized import parameterized

from tests.utils import assert_called_with_exactly, build_audio
from unit.utils import assert_called_with_exactly, build_audio
from voicebox.audio import Audio
from voicebox.tts.cache import CachedTTS
from voicebox.tts.cache import PrerecordedTTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from elevenlabs.client import ElevenLabs

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.tts.elevenlabs import ElevenLabsTTS


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from unittest.mock import Mock, patch

from tests.utils import build_audio, assert_first_call
from unit.utils import build_audio, assert_first_call
from voicebox.ssml import SSML
from voicebox.tts import ESpeakNG, ESpeakConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from parameterized import parameterized

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.ssml import SSML
from voicebox.tts.googlecloudtts import GoogleCloudTTS

Expand Down
2 changes: 1 addition & 1 deletion tests/tts/test_gtts.py → tests/unit/tts/test_gtts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest.mock import patch

from tests.utils import assert_first_call, build_audio
from unit.utils import assert_first_call, build_audio
from voicebox.ssml import SSML
from voicebox.tts.gtts import gTTS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from unittest.mock import Mock, patch

from tests.utils import build_audio, assert_first_call
from unit.utils import build_audio, assert_first_call
from voicebox.ssml import SSML
from voicebox.tts.picotts import PicoTTS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from unittest.mock import Mock, patch

from tests.utils import build_audio
from unit.utils import build_audio
from voicebox.tts import Pyttsx3TTS


Expand Down
2 changes: 1 addition & 1 deletion tests/tts/test_tts.py → tests/unit/tts/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from parameterized import parameterized

from tests.utils import assert_called_with_exactly, build_audio
from unit.utils import assert_called_with_exactly, build_audio
from voicebox.tts import TTS, FallbackTTS, RetryTTS

log = Mock()
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from parameterized import parameterized

from tests.utils import assert_called_with_exactly
from unit.utils import assert_called_with_exactly
from voicebox.effects import Normalize
from voicebox.sinks import SoundDevice
from voicebox.tts import PicoTTS
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import unittest
from typing import List
from unittest import TestCase

from parameterized import parameterized

Expand All @@ -25,16 +23,16 @@
]


class NoopSplitterTest(TestCase):
class TestNoopSplitter:
@parameterized.expand(map(lambda it: it[0], commonly_handled_sentences))
def test_does_not_split(self, text: str):
splitter = NoopSplitter()
actual = list(splitter.split(text))
self.assertListEqual([text], actual)
assert [text] == actual


class SimpleSentenceSplitterTest(TestCase):
def setUp(self):
class TestSimpleSentenceSplitter:
def setup_method(self):
self.splitter = SimpleSentenceSplitter()

@parameterized.expand(commonly_handled_sentences + [
Expand All @@ -45,11 +43,11 @@ def setUp(self):
])
def test_split(self, text: str, expected: List[str]):
actual = list(self.splitter.split(text))
self.assertListEqual(expected, actual)
assert expected == actual


class PunktSentenceSplitterTest(TestCase):
def setUp(self):
class TestPunktSentenceSplitter:
def setup_method(self):
self.splitter = PunktSentenceSplitter()

@parameterized.expand(commonly_handled_sentences + [
Expand All @@ -60,13 +58,9 @@ def setUp(self):
])
def test_split(self, text: str, expected: List[str]):
actual = list(self.splitter.split(text))
self.assertListEqual(expected, actual)
assert expected == actual


class DefaultSplitterTest(unittest.TestCase):
class TestDefaultSplitter:
def test(self):
self.assertIsInstance(default_splitter(), NoopSplitter)


if __name__ == '__main__':
unittest.main()
assert isinstance(default_splitter(), NoopSplitter)