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

six is not needed for literals #246

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions requests_mock/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@ class _IOReader(six.BytesIO):

def read(self, *args, **kwargs):
if self.closed:
return six.b('')
return b''

# if the file is open, but you asked for zero bytes read you should get
# back zero without closing the stream.
if len(args) > 0 and args[0] == 0:
return six.b('')
return b''

# not a new style object in python 2
result = six.BytesIO.read(self, *args, **kwargs)

# when using resp.iter_content(None) it'll go through a different
# request path in urllib3. This path checks whether the object is
# marked closed instead of the return value. see gh124.
if result == six.b(''):
if result == b'':
self.close()

return result
Expand Down Expand Up @@ -193,7 +193,7 @@ def create_response(request, **kwargs):
raw = HTTPResponse(status=status,
reason=reason,
headers=headers,
body=body or _IOReader(six.b('')),
body=body or _IOReader(b''),
decode_content=False,
enforce_content_length=False,
preload_content=False,
Expand Down
22 changes: 11 additions & 11 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def assertLastRequest(self, method='GET', body=None):
self.assertEqual(qs, self.adapter.last_request.qs)

def test_content(self):
data = six.b('testdata')
data = b'testdata'

self.adapter.register_uri('GET',
self.url,
Expand All @@ -72,7 +72,7 @@ def test_content(self):

def test_content_callback(self):
status_code = 401
data = six.b('testdata')
data = b'testdata'

def _content_cb(request, context):
context.status_code = status_code
Expand Down Expand Up @@ -127,8 +127,8 @@ def test_json(self):
json=json_data,
headers=self.headers)
resp = self.session.get(self.url)
self.assertEqual(six.b('{"hello": "world"}'), resp.content)
self.assertEqual(six.u('{"hello": "world"}'), resp.text)
self.assertEqual(b'{"hello": "world"}', resp.content)
self.assertEqual(u'{"hello": "world"}', resp.text)
self.assertEqual(json_data, resp.json())
self.assertEqual('utf-8', resp.encoding)
self.assertHeaders(resp)
Expand Down Expand Up @@ -157,16 +157,16 @@ def _json_cb(request, context):
def test_no_body(self):
self.adapter.register_uri('GET', self.url)
resp = self.session.get(self.url)
self.assertEqual(six.b(''), resp.content)
self.assertEqual(b'', resp.content)
self.assertEqual(200, resp.status_code)

def test_multiple_body_elements(self):
self.assertRaises(RuntimeError,
self.adapter.register_uri,
self.url,
'GET',
content=six.b('b'),
text=six.u('u'))
content=b'b',
text=u'u')

def test_multiple_responses(self):
inp = [{'status_code': 400, 'text': 'abcd'},
Expand Down Expand Up @@ -264,14 +264,14 @@ def test_dont_pass_unicode_as_content(self):
self.adapter.register_uri,
'GET',
self.url,
content=six.u('unicode'))
content=u'unicode')

def test_dont_pass_empty_string_as_content(self):
self.assertRaises(TypeError,
self.adapter.register_uri,
'GET',
self.url,
content=six.u(''))
content=u'')

def test_dont_pass_bytes_as_text(self):
if six.PY2:
Expand All @@ -281,7 +281,7 @@ def test_dont_pass_bytes_as_text(self):
self.adapter.register_uri,
'GET',
self.url,
text=six.b('bytes'))
text=b'bytes')

def test_dont_pass_empty_string_as_text(self):
if six.PY2:
Expand All @@ -291,7 +291,7 @@ def test_dont_pass_empty_string_as_text(self):
self.adapter.register_uri,
'GET',
self.url,
text=six.b(''))
text=b'')

def test_dont_pass_non_str_as_content(self):
self.assertRaises(TypeError,
Expand Down
5 changes: 2 additions & 3 deletions tests/test_custom_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# under the License.

import requests
import six

import requests_mock
from . import base
Expand All @@ -28,14 +27,14 @@ def __call__(self, request):


def match_all(request):
return requests_mock.create_response(request, content=six.b('data'))
return requests_mock.create_response(request, content=b'data')


class CustomMatchersTests(base.TestCase):

def assertMatchAll(self, resp):
self.assertEqual(200, resp.status_code)
self.assertEqual(resp.text, six.u('data'))
self.assertEqual(resp.text, u'data')

@requests_mock.Mocker()
def test_custom_matcher(self, mocker):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def test_content_type(self):

# this only works on python 2 because bytes is a string
if six.PY3:
self.assertRaises(TypeError, self.create_response, text=six.b(''))
self.assertRaises(TypeError, self.create_response, text=b'')

def test_text_type(self):
self.assertRaises(TypeError, self.create_response, content=six.u('t'))
self.assertRaises(TypeError, self.create_response, content=u't')
self.assertRaises(TypeError, self.create_response, content={'a': 1})
self.assertRaises(TypeError, self.create_response, content=six.u(''))
self.assertRaises(TypeError, self.create_response, content=u'')

def test_json_body(self):
data = {'a': 1}
Expand Down
Loading