Skip to content

Commit

Permalink
feat: Add return type annotations to test and example functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideGalilei committed Dec 3, 2024
1 parent 0778a34 commit 88ed2a8
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/async/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from gpytranslate import Translator


async def main():
async def main() -> None:
t = Translator()
# Note: you can use proxies by passing proxies parameter to Translator
translation = await t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
Expand Down
2 changes: 1 addition & 1 deletion examples/async/https_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from gpytranslate import Translator


async def main():
async def main() -> None:
t = Translator(proxies={"https://": "https://{proxy_ip_here}"})
# Check out https://www.python-httpx.org/compatibility/#proxy-keys
translation = await t.translate("Ciao Mondo!", targetlang="en")
Expand Down
2 changes: 1 addition & 1 deletion examples/async/socks5_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from gpytranslate import Translator


async def main():
async def main() -> None:
t = Translator(proxies={"socks5": "socks5://user:password@127.0.0.1:1080"})
# Check out https://pypi.org/project/httpx-socks/
translation = await t.translate("Ciao Mondo!", targetlang="en")
Expand Down
2 changes: 1 addition & 1 deletion examples/async/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from gpytranslate import Translator


async def main():
async def main() -> None:
translator = Translator()

async with aiofiles.open("test.mp3", "wb") as file:
Expand Down
2 changes: 1 addition & 1 deletion tests/async/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.mark.asyncio
async def test_detect():
async def test_detect() -> None:
translator = Translator()
language: str = await translator.detect(text="Ciao Mondo.")

Expand Down
2 changes: 1 addition & 1 deletion tests/async/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@pytest.mark.asyncio
async def test_gather():
async def test_gather() -> None:
translator = Translator()
tasks = [
translator.translate("Hello world!", targetlang="it"),
Expand Down
8 changes: 4 additions & 4 deletions tests/async/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@


@pytest.mark.asyncio
async def test_translate_auto():
async def test_translate_auto() -> None:
translator = Translator()
translation: TranslatedObject = await translator.translate("Ciao Mondo.", targetlang="en")
assert translation.text == "Hello World.", "Translations are not equal."


@pytest.mark.asyncio
async def test_translate_source():
async def test_translate_source() -> None:
translator = Translator()
translation: TranslatedObject = await translator.translate("Ciao.", sourcelang="it", targetlang="en")

assert translation.text in ("Hello.", "HI."), "Translations are not equal."


@pytest.mark.asyncio
async def test_translate_list():
async def test_translate_list() -> None:
translator = Translator()
translations: List[TranslatedObject] = await translator.translate(["Ciao Mondo.", "Come stai?"], targetlang="en")

Expand All @@ -32,7 +32,7 @@ async def test_translate_list():


@pytest.mark.asyncio
async def test_translate_dict():
async def test_translate_dict() -> None:
translator = Translator()
translations: Dict[Any, TranslatedObject] = await translator.translate(
{1: "Ciao Mondo.", 2: "Come stai?"}, targetlang="en"
Expand Down
2 changes: 1 addition & 1 deletion tests/async/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.mark.asyncio
async def test_tts():
async def test_tts() -> None:
translator = Translator()
filename = "test.mp3"

Expand Down
2 changes: 1 addition & 1 deletion tests/sync/test_sync_detect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from gpytranslate import SyncTranslator


def test_sync_detect():
def test_sync_detect() -> None:
translator = SyncTranslator()
language: str = translator.detect(text="Ciao Mondo.")

Expand Down
8 changes: 4 additions & 4 deletions tests/sync/test_sync_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
from gpytranslate import SyncTranslator, TranslatedObject


def test_sync_translate_auto():
def test_sync_translate_auto() -> None:
translator = SyncTranslator()
translation: TranslatedObject = translator.translate("Ciao Mondo.", targetlang="en")
assert translation.text == "Hello World.", "Translations are not equal."


def test_sync_translate_source():
def test_sync_translate_source() -> None:
translator = SyncTranslator()
translation: TranslatedObject = translator.translate("Ciao.", sourcelang="it", targetlang="en")

assert translation.text in ("Hello.", "HI."), "Translations are not equal."


def test_sync_translate_list():
def test_sync_translate_list() -> None:
translator = SyncTranslator()
translations: List[TranslatedObject] = translator.translate(["Ciao Mondo.", "Come stai?"], targetlang="en")

Expand All @@ -26,7 +26,7 @@ def test_sync_translate_list():
], "Translations are not equal."


def test_sync_translate_dict():
def test_sync_translate_dict() -> None:
translator = SyncTranslator()
translations: Dict[Any, TranslatedObject] = translator.translate(
{1: "Ciao Mondo.", 2: "Come stai?"}, targetlang="en"
Expand Down
4 changes: 2 additions & 2 deletions tests/sync/test_sync_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from gpytranslate import SyncTranslator


def test_sync_tts():
def test_sync_tts() -> None:
translator = SyncTranslator()
filename = "test.mp3"

Expand All @@ -15,7 +15,7 @@ def test_sync_tts():
os.remove(filename)


def test_sync_tts_bytesio():
def test_sync_tts_bytesio() -> None:
translator = SyncTranslator()
file = io.BytesIO()

Expand Down

0 comments on commit 88ed2a8

Please sign in to comment.