From 81548de06bce0c21493bc0bb3ceb1eeb99252258 Mon Sep 17 00:00:00 2001 From: Nidhal Baccouri Date: Sun, 7 Jan 2024 16:56:34 +0100 Subject: [PATCH] fixed poetry install --- .github/workflows/production-tests.yml | 3 ++- .github/workflows/release.yml | 3 ++- .github/workflows/test-release.yml | 3 ++- .github/workflows/test.yml | 2 +- deep_translator/microsoft.py | 9 ++++++++- tests/test_microsoft_trans.py | 8 ++++---- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/production-tests.yml b/.github/workflows/production-tests.yml index f03b479..135ebc0 100644 --- a/.github/workflows/production-tests.yml +++ b/.github/workflows/production-tests.yml @@ -23,7 +23,8 @@ jobs: - name: Install poetry run: | which python - curl -sSL https://install.python-poetry.org | python${{ matrix.python-version }} - + which pipx + pipx install poetry - name: Install dependencies run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a006998..f0f7551 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,7 +29,8 @@ jobs: - name: Install poetry run: | which python - curl -sSL https://install.python-poetry.org | python3 - + which pipx + pipx install poetry - name: View poetry version run: poetry --version diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index 0faadda..4639c07 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -21,7 +21,8 @@ jobs: - name: Install poetry run: | which python - curl -sSL https://install.python-poetry.org | python3 - + which pipx + pipx install poetry - name: View poetry version run: poetry --version diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a35aeed..0da9ba3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: test: strategy: matrix: - python-version: ["3.7"] + python-version: [ "3.7", "3.8", "3.9" ] os: [ubuntu-latest] # we can add other os like macOS-latest runs-on: ${{ matrix.os }} steps: diff --git a/deep_translator/microsoft.py b/deep_translator/microsoft.py index a47f573..67d91cb 100644 --- a/deep_translator/microsoft.py +++ b/deep_translator/microsoft.py @@ -11,7 +11,11 @@ from deep_translator.base import BaseTranslator from deep_translator.constants import BASE_URLS, MSFT_ENV_VAR -from deep_translator.exceptions import ApiKeyException, MicrosoftAPIerror +from deep_translator.exceptions import ( + ApiKeyException, + MicrosoftAPIerror, + TranslationNotFound, +) from deep_translator.validate import is_input_valid @@ -100,6 +104,9 @@ def translate(self, text: str, **kwargs) -> str: exc_type, value, traceback = sys.exc_info() logging.warning(f"Returned error: {exc_type.__name__}") + if response is None: + raise TranslationNotFound(text) + # Where Microsoft API responds with an api error, it returns a dict in response.json() if type(response.json()) is dict: error_message = response.json()["error"] diff --git a/tests/test_microsoft_trans.py b/tests/test_microsoft_trans.py index 85c330b..483a3dd 100644 --- a/tests/test_microsoft_trans.py +++ b/tests/test_microsoft_trans.py @@ -36,10 +36,10 @@ def json_func(): def test_MicrosoftAPIerror(): - with pytest.raises(exceptions.MicrosoftAPIerror): - MicrosoftTranslator( - api_key="empty", source="de", target="en" - ).translate("text") + with pytest.raises(exceptions.ApiKeyException): + MicrosoftTranslator(api_key="", source="de", target="en").translate( + "text" + ) # the remaining tests are actual requests to Microsoft API and use an api key