-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from DavideGalilei/dev
❇️ Fixes #5
- Loading branch information
Showing
6 changed files
with
89 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ "dev", "master" ] | ||
pull_request: | ||
branches: [ "dev", "master" ] | ||
|
||
jobs: | ||
tests: | ||
name: "Python ${{ matrix.version }} compatibility" | ||
runs-on: "ubuntu-latest" | ||
|
||
strategy: | ||
matrix: | ||
version: [ "3.6", "3.7", "3.8", "3.9" ] | ||
|
||
steps: | ||
- uses: "actions/checkout@v2" | ||
- uses: "actions/setup-python@v2" | ||
with: | ||
python-version: "${{ matrix.version }}" | ||
- name: "Install Gpytranslate" | ||
run: python setup.py install | ||
- name: "Install pytest" | ||
run: python -m pip install pytest-asyncio | ||
- name: "Run tests" | ||
run: python -m pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="gpytranslate", | ||
version="1.0.2", | ||
version="1.0.3", | ||
author="Davide Galilei", | ||
author_email="[email protected]", | ||
description="A Python3 library for translating text using Google Translate API.", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
import unittest | ||
import pytest | ||
|
||
|
||
from gpytranslate import Translator | ||
|
||
|
||
class Test(unittest.IsolatedAsyncioTestCase): | ||
async def test_detect(self): | ||
translator = Translator() | ||
language: str = await translator.detect( | ||
text="Ciao Mondo." | ||
) | ||
@pytest.mark.asyncio | ||
async def test_detect(): | ||
translator = Translator() | ||
language: str = await translator.detect(text="Ciao Mondo.") | ||
|
||
self.assertEqual( | ||
language, | ||
"it", | ||
"Translations are not equal.", | ||
) | ||
assert language == "it", "Translations are not equal." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,50 @@ | ||
import unittest | ||
import pytest | ||
|
||
from typing import List, Dict, Any | ||
|
||
from gpytranslate import Translator, TranslatedObject | ||
|
||
|
||
class Test(unittest.IsolatedAsyncioTestCase): | ||
async def test_translate_auto(self): | ||
translator = Translator() | ||
translation: TranslatedObject = await translator.translate( | ||
"Ciao Mondo.", targetlang="en" | ||
) | ||
self.assertEqual( | ||
translation.text, | ||
"Hello World.", | ||
"Translations are not equal.", | ||
) | ||
|
||
async def test_translate_source(self): | ||
translator = Translator() | ||
translation: TranslatedObject = await translator.translate( | ||
"Ciao.", sourcelang="it", targetlang="en" | ||
) | ||
|
||
self.assertEqual( | ||
translation.text, | ||
"Hello.", | ||
"Translations are not equal.", | ||
) | ||
|
||
async def test_translate_list(self): | ||
translator = Translator() | ||
translations: List[TranslatedObject] = await translator.translate( | ||
["Ciao Mondo.", "Come stai?"], targetlang="en" | ||
) | ||
|
||
self.assertEqual( | ||
[translation.text for translation in translations], | ||
["Hello World.", "How are you?"], | ||
"Translations are not equal.", | ||
) | ||
|
||
async def test_translate_dict(self): | ||
translator = Translator() | ||
translations: Dict[Any, TranslatedObject] = await translator.translate( | ||
{1: "Ciao Mondo.", 2: "Come stai?"}, targetlang="en" | ||
) | ||
|
||
self.assertEqual( | ||
{k: v.text for k, v in translations.items()}, | ||
{1: "Hello World.", 2: "How are you?"}, | ||
"Translations are not equal.", | ||
) | ||
@pytest.mark.asyncio | ||
async def test_translate_auto(): | ||
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(): | ||
translator = Translator() | ||
translation: TranslatedObject = await translator.translate( | ||
"Ciao.", sourcelang="it", targetlang="en" | ||
) | ||
|
||
assert translation.text == "Hello.", "Translations are not equal." | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_translate_list(): | ||
translator = Translator() | ||
translations: List[TranslatedObject] = await translator.translate( | ||
["Ciao Mondo.", "Come stai?"], targetlang="en" | ||
) | ||
|
||
assert [translation.text for translation in translations] == [ | ||
"Hello World.", | ||
"How are you?", | ||
], "Translations are not equal." | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_translate_dict(): | ||
translator = Translator() | ||
translations: Dict[Any, TranslatedObject] = await translator.translate( | ||
{1: "Ciao Mondo.", 2: "Come stai?"}, targetlang="en" | ||
) | ||
|
||
assert {k: v.text for k, v in translations.items()} == { | ||
1: "Hello World.", | ||
2: "How are you?", | ||
}, "Translations are not equal." |