Skip to content

Commit

Permalink
fixed poetry install
Browse files Browse the repository at this point in the history
  • Loading branch information
Nidhal Baccouri committed Jan 7, 2024
1 parent 9bef22f commit 81548de
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/production-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion deep_translator/microsoft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_microsoft_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81548de

Please sign in to comment.