Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma committed Mar 17, 2019
1 parent db171fc commit 3666a6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ install:
- "pip install coveralls"
- "sudo apt-get -V install sox libsox-fmt-mp3"
script:
- "export AUDIODEV=null" # see https://github.com/travis-ci/travis-ci/issues/1754
- "coverage run --source=google_speech setup.py test"
after_success:
- "coveralls"
Expand Down
34 changes: 25 additions & 9 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import itertools
import logging
import os
import socket
import sys
import tempfile
Expand All @@ -27,6 +28,16 @@ def is_internet_reachable():

class TestGoogleSpeech(unittest.TestCase):

def setUp(self):
self.orig_audiodev = os.environ.get("AUDIODEV")
os.environ["AUDIODEV"] = "null"

def tearDOwn(self):
if self.orig_audiodev is not None:
os.environ["AUDIODEV"] = self.orig_audiodev
else:
del os.environ["AUDIODEV"]

@unittest.skipUnless(is_internet_reachable(), "Need Internet access")
def test_speechLoremIpsum(self):
""" Play some reference speeches. """
Expand All @@ -38,14 +49,18 @@ def test_speechLoremIpsum(self):

def test_splitTest(self):
""" Split input text. """
text = "Aaaa, bbbb. Cccc, dddd. %s. %s, %s. %s? %s ! %s, %s %s." % ("e" * (google_speech.Speech.MAX_SEGMENT_SIZE + 10),
"f" * (google_speech.Speech.MAX_SEGMENT_SIZE - 1),
"g" * (google_speech.Speech.MAX_SEGMENT_SIZE),
"h" * (google_speech.Speech.MAX_SEGMENT_SIZE),
"i" * (google_speech.Speech.MAX_SEGMENT_SIZE),
"j" * (google_speech.Speech.MAX_SEGMENT_SIZE + 1),
"k" * google_speech.Speech.MAX_SEGMENT_SIZE,
"l" * 5)
text = ("Aaaa, bbbb. Cccc, dddd. "
"%s. %s, %s. %s? %s ! %s, %s %s. %s, %s %s" % ("e" * (google_speech.Speech.MAX_SEGMENT_SIZE + 10),
"f" * (google_speech.Speech.MAX_SEGMENT_SIZE - 1),
"g" * (google_speech.Speech.MAX_SEGMENT_SIZE),
"h" * (google_speech.Speech.MAX_SEGMENT_SIZE),
"i" * (google_speech.Speech.MAX_SEGMENT_SIZE),
"j" * (google_speech.Speech.MAX_SEGMENT_SIZE + 1),
"k" * google_speech.Speech.MAX_SEGMENT_SIZE,
"l" * 5,
"m" * (google_speech.Speech.MAX_SEGMENT_SIZE - 20),
"n" * 10,
"o" * 15))
split_text = ("Aaaa, bbbb. Cccc, dddd.",
"%s" % ("e" * google_speech.Speech.MAX_SEGMENT_SIZE),
"%s." % ("e" * 10),
Expand All @@ -56,7 +71,8 @@ def test_splitTest(self):
"j" * google_speech.Speech.MAX_SEGMENT_SIZE,
"j,",
"k" * google_speech.Speech.MAX_SEGMENT_SIZE,
"lllll.")
"lllll. %s," % ("m" * (google_speech.Speech.MAX_SEGMENT_SIZE - 20)),
"%s %s" % ("n" * 10, "o" * 15))

# input is text string
speech = google_speech.Speech(text, "en")
Expand Down

0 comments on commit 3666a6e

Please sign in to comment.