Skip to content

Commit

Permalink
test(utils): cover more scopes
Browse files Browse the repository at this point in the history
TODO: mock legacy TKK code
  • Loading branch information
ssut committed Jun 10, 2020
1 parent 5460f43 commit 44957eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion googletrans/client.py
Expand Up @@ -45,7 +45,7 @@ def __init__(self, service_urls=None, user_agent=DEFAULT_USER_AGENT,
proxies: typing.Dict[str, httpcore.SyncHTTPTransport] = None, timeout: Timeout = None):

self.client = httpx.Client()
if proxies is not None:
if proxies is not None: # pragma: nocover
self.client.proxies = proxies
self.client.headers.update({
'User-Agent': user_agent,
Expand Down
20 changes: 18 additions & 2 deletions tests/test_utils.py
Expand Up @@ -5,20 +5,36 @@
def test_format_json():
text = '[,,"en",,,,0.96954316,,[["en"],,[0.96954316]]]'

result = utils.legacy_format_json(text)
result = utils.format_json(text)

assert result == [None, None, 'en', None, None, None, 0.96954316, None,
[['en'], None, [0.96954316]]]


def test_format_malformed_json():
text = '[,,"en",,,,0.96954316,,[["en"],,0.96954316]]]'

with raises(ValueError):
utils.legacy_format_json(text)
utils.format_json(text)


def test_rshift():
value, n = 1000, 3

result = utils.rshift(value, n)

assert result == 125


def test_build_params_with_override():
params = utils.build_params(
query='',
src='',
dest='',
token='',
override={
'otf': '3',
},
)

assert params['otf'] == '3'

0 comments on commit 44957eb

Please sign in to comment.