Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests failure when chardet module is missed #108

Merged
merged 1 commit into from
Jul 8, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import aiohttp
from aiohttp.client import ClientRequest, ClientResponse, HttpClient

try:
import chardet
except ImportError:
chardet = None


class RequestTests(unittest.TestCase):

Expand Down Expand Up @@ -186,9 +191,14 @@ def second_call(*args, **kwargs):
content.read.side_effect = side_effect
self.response.close = unittest.mock.Mock()

res = self.loop.run_until_complete(self.response.text())
self.assertEqual(res, '{"тест": "пройден"}')
self.assertTrue(self.response.close.called)
if chardet is None:
self.assertRaises(UnicodeDecodeError,
self.loop.run_until_complete,
self.response.text())
else:
res = self.loop.run_until_complete(self.response.text())
self.assertEqual(res, '{"тест": "пройден"}')
self.assertTrue(self.response.close.called)

def test_json(self):
def side_effect(*args, **kwargs):
Expand Down Expand Up @@ -260,9 +270,14 @@ def second_call(*args, **kwargs):
content.read.side_effect = side_effect
self.response.close = unittest.mock.Mock()

res = self.loop.run_until_complete(self.response.json())
self.assertEqual(res, {'тест': 'пройден'})
self.assertTrue(self.response.close.called)
if chardet is None:
self.assertRaises(UnicodeDecodeError,
self.loop.run_until_complete,
self.response.json())
else:
res = self.loop.run_until_complete(self.response.json())
self.assertEqual(res, {'тест': 'пройден'})
self.assertTrue(self.response.close.called)

def test_override_flow_control(self):
class MyResponse(ClientResponse):
Expand Down