Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
ssut committed Nov 23, 2024
1 parent 9880a80 commit a0eb858
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[pytest]
addopts = -v
addopts = -v --asyncio-mode=auto
omit =
tests/*
asyncio_default_fixture_loop_scope = function

[run]
include = googletrans/*
Expand Down
18 changes: 13 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from pytest import fixture
import httpx
import pytest

from googletrans import Translator, gtoken

@fixture(scope="session")
def translator():
from googletrans import Translator

return Translator()
@pytest.fixture(scope="function")
async def translator():
async with Translator() as t:
yield t


@pytest.fixture(scope="function")
async def acquirer():
async with httpx.AsyncClient(http2=True) as client:
yield gtoken.TokenAcquirer(client=client)
9 changes: 4 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,23 @@ async def test_translate_list(translator: Translator):
async def test_detect_language(translator: Translator):
ko = await translator.detect("한국어")
en = await translator.detect("English")
rubg = await translator.detect("тест")
rubg = await translator.detect("летóво")
russ = await translator.detect("привет")

assert ko.lang == "ko"
assert en.lang == "en"
assert rubg.lang == "mk"
assert rubg.lang == "bg"
assert russ.lang == "ru"
#'bg']


@pytest.mark.asyncio
async def test_detect_list(translator: Translator):
items = ["한국어", " English", "тест", "привет"]
items = ["한국어", " English", "летóво", "привет"]
result = await translator.detect(items)

assert result[0].lang == "ko"
assert result[1].lang == "en"
assert result[2].lang == "mk"
assert result[2].lang == "bg"
assert result[3].lang == "ru"


Expand Down
7 changes: 0 additions & 7 deletions tests/test_gtoken.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from typing import Any, Callable

import httpx
import pytest

from googletrans import gtoken


@pytest.fixture(scope="session")
def acquirer() -> gtoken.TokenAcquirer:
client = httpx.AsyncClient(http2=True)
return gtoken.TokenAcquirer(client=client)


@pytest.mark.asyncio
async def test_acquire_token(acquirer: gtoken.TokenAcquirer) -> None:
text: str = "test"
Expand Down

0 comments on commit a0eb858

Please sign in to comment.