wmt-2020-pl-en/tests/test_gtoken.py
Suhun Han ee02d4b6fd
feat(http2): add http2 support (#213)
* feat(client): add http2 option

* chore(deps): update httpx

* refactor(gtoken): gtoken should always accept client argument in order to follow client's options

* chore(ci): change dist to ubuntu 18.04 bionic

* chore:test available service_urls and multi-lang result in different service_urls (#216)

* feat(models): add Base model

* test: reuse test client

* feat(client): return Translated and Detected with the original response

* test(client): ConnectError has been replaced with httpx.ConnectTimeout

* fix: possible merge conflict

* chore(docs): add a description for checking http2

* chore(deps): add sphinx to dev deps

* test(client): httpx will raise ConnectError in some conditions

omg i missed

Co-authored-by: Terry Zhuo <terryzhuo25@gmail.com>
2020-09-05 13:00:21 +10:00

67 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
import httpx
from googletrans import gtoken
from pytest import fixture
@fixture(scope='session')
def acquirer():
client = httpx.Client(http2=True)
return gtoken.TokenAcquirer(client=client)
def test_acquire_token(acquirer):
text = 'test'
result = acquirer.do(text)
assert result
def test_acquire_token_ascii_less_than_2048(acquirer):
text = u'Ѐ'
result = acquirer.do(text)
assert result
def test_acquire_token_ascii_matches_special_condition(acquirer):
def unichar(i):
try:
return unichr(i)
except NameError:
return chr(i)
text = unichar(55296) + unichar(56320)
result = acquirer.do(text)
assert result
def test_acquire_token_ascii_else(acquirer):
text = u''
result = acquirer.do(text)
assert result
def test_reuse_valid_token(acquirer):
text = 'test'
first = acquirer.do(text)
second = acquirer.do(text)
assert first == second
def test_map_lazy_return(acquirer):
value = True
func = acquirer._lazy(value)
assert callable(func)
assert func() == value