Techdebt: Replace sure with regular assertions in Polly (#6679)

This commit is contained in:
kbalk 2023-08-16 17:56:23 -04:00 committed by GitHub
parent 0b4889ad37
commit bbecbd2acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 265 additions and 274 deletions

View File

@ -1,6 +1,6 @@
from botocore.exceptions import ClientError
import boto3
import sure # noqa # pylint: disable=unused-import
from botocore.exceptions import ClientError
from moto import mock_polly
# Polly only available in a few regions
@ -26,15 +26,15 @@ def test_describe_voices():
client = boto3.client("polly", region_name=DEFAULT_REGION)
resp = client.describe_voices()
len(resp["Voices"]).should.be.greater_than(1)
assert len(resp["Voices"]) >= 1
resp = client.describe_voices(LanguageCode="en-GB")
len(resp["Voices"]).should.equal(4)
assert len(resp["Voices"]) == 4
try:
client.describe_voices(LanguageCode="SOME_LANGUAGE")
except ClientError as err:
err.response["Error"]["Code"].should.equal("400")
assert err.response["Error"]["Code"] == "400"
else:
raise RuntimeError("Should have raised an exception")
@ -47,7 +47,7 @@ def test_put_list_lexicon():
client.put_lexicon(Name="test", Content=LEXICON_XML)
resp = client.list_lexicons()
len(resp["Lexicons"]).should.equal(1)
assert len(resp["Lexicons"]) == 1
@mock_polly
@ -58,8 +58,8 @@ def test_put_get_lexicon():
client.put_lexicon(Name="test", Content=LEXICON_XML)
resp = client.get_lexicon(Name="test")
resp.should.contain("Lexicon")
resp.should.contain("LexiconAttributes")
assert "Lexicon" in resp
assert "LexiconAttributes" in resp
@mock_polly
@ -69,7 +69,7 @@ def test_put_lexicon_bad_name():
try:
client.put_lexicon(Name="test-invalid", Content=LEXICON_XML)
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
assert err.response["Error"]["Code"] == "InvalidParameterValue"
else:
raise RuntimeError("Should have raised an exception")
@ -91,7 +91,7 @@ def test_synthesize_speech():
TextType="text",
VoiceId="Astrid",
)
resp["ContentType"].should.equal(content_type)
assert resp["ContentType"] == content_type
@mock_polly
@ -109,7 +109,7 @@ def test_synthesize_speech_bad_lexicon():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal("LexiconNotFoundException")
assert err.response["Error"]["Code"] == "LexiconNotFoundException"
else:
raise RuntimeError("Should have raised LexiconNotFoundException")
@ -129,7 +129,7 @@ def test_synthesize_speech_bad_output_format():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
assert err.response["Error"]["Code"] == "InvalidParameterValue"
else:
raise RuntimeError("Should have raised ")
@ -149,7 +149,7 @@ def test_synthesize_speech_bad_sample_rate():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidSampleRateException")
assert err.response["Error"]["Code"] == "InvalidSampleRateException"
else:
raise RuntimeError("Should have raised ")
@ -169,7 +169,7 @@ def test_synthesize_speech_bad_text_type():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
assert err.response["Error"]["Code"] == "InvalidParameterValue"
else:
raise RuntimeError("Should have raised ")
@ -189,7 +189,7 @@ def test_synthesize_speech_bad_voice_id():
VoiceId="Luke",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
assert err.response["Error"]["Code"] == "InvalidParameterValue"
else:
raise RuntimeError("Should have raised ")
@ -209,7 +209,7 @@ def test_synthesize_speech_text_too_long():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal("TextLengthExceededException")
assert err.response["Error"]["Code"] == "TextLengthExceededException"
else:
raise RuntimeError("Should have raised ")
@ -230,9 +230,7 @@ def test_synthesize_speech_bad_speech_marks1():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal(
"MarksNotSupportedForFormatException"
)
assert err.response["Error"]["Code"] == "MarksNotSupportedForFormatException"
else:
raise RuntimeError("Should have raised ")
@ -253,9 +251,7 @@ def test_synthesize_speech_bad_speech_marks2():
VoiceId="Astrid",
)
except ClientError as err:
err.response["Error"]["Code"].should.equal(
"MarksNotSupportedForFormatException"
)
assert err.response["Error"]["Code"] == "MarksNotSupportedForFormatException"
else:
raise RuntimeError("Should have raised ")

View File

@ -1,12 +1,7 @@
import sure # noqa # pylint: disable=unused-import
"""Test the different server responses."""
import moto.server as server
from moto import mock_polly
"""
Test the different server responses
"""
@mock_polly
def test_polly_list():
@ -14,4 +9,4 @@ def test_polly_list():
test_client = backend.test_client()
res = test_client.get("/v1/lexicons")
res.status_code.should.equal(200)
assert res.status_code == 200