2017-03-10 11:20:59 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from googletrans import gtoken
|
|
|
|
from pytest import fixture
|
|
|
|
|
|
|
|
|
|
|
|
@fixture
|
|
|
|
def acquirer():
|
|
|
|
return gtoken.TokenAcquirer()
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
2017-03-10 14:53:00 +01:00
|
|
|
def unichar(i):
|
|
|
|
try:
|
|
|
|
return unichr(i)
|
|
|
|
except NameError:
|
|
|
|
return chr(i)
|
|
|
|
text = unichar(55296) + unichar(56320)
|
2017-03-10 11:20:59 +01:00
|
|
|
|
|
|
|
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)
|
2017-03-10 14:53:00 +01:00
|
|
|
assert func() == value
|