2017-03-10 11:20:59 +01:00
|
|
|
from googletrans import utils
|
|
|
|
from pytest import raises
|
|
|
|
|
|
|
|
|
|
|
|
def test_format_json():
|
|
|
|
text = '[,,"en",,,,0.96954316,,[["en"],,[0.96954316]]]'
|
|
|
|
|
2020-06-14 08:42:32 +02:00
|
|
|
result = utils.format_json(text)
|
2017-03-10 11:20:59 +01:00
|
|
|
|
|
|
|
assert result == [None, None, 'en', None, None, None, 0.96954316, None,
|
|
|
|
[['en'], None, [0.96954316]]]
|
|
|
|
|
2020-06-14 08:42:32 +02:00
|
|
|
|
2017-03-10 11:20:59 +01:00
|
|
|
def test_format_malformed_json():
|
|
|
|
text = '[,,"en",,,,0.96954316,,[["en"],,0.96954316]]]'
|
|
|
|
|
|
|
|
with raises(ValueError):
|
2020-06-14 08:42:32 +02:00
|
|
|
utils.format_json(text)
|
|
|
|
|
2017-03-10 11:20:59 +01:00
|
|
|
|
|
|
|
def test_rshift():
|
|
|
|
value, n = 1000, 3
|
|
|
|
|
|
|
|
result = utils.rshift(value, n)
|
|
|
|
|
2017-10-02 16:26:34 +02:00
|
|
|
assert result == 125
|
2020-06-14 08:42:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_build_params_with_override():
|
|
|
|
params = utils.build_params(
|
|
|
|
query='',
|
|
|
|
src='',
|
|
|
|
dest='',
|
|
|
|
token='',
|
|
|
|
override={
|
|
|
|
'otf': '3',
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
assert params['otf'] == '3'
|