Merge "PY3: Fix ipython extension as py3 compatible"

This commit is contained in:
Zuul 2019-11-29 23:13:02 +00:00 committed by Gerrit Code Review
commit 9d9cbb6068
3 changed files with 18 additions and 9 deletions
storlets/tools/extensions
tests
functional/ipython
unit/tools/extensions

@ -49,7 +49,6 @@ class Response(object):
self._body_iter = body_iter or iter([])
def __iter__(self):
print('hoge')
return self._body_iter
def iter_content(self):
@ -58,7 +57,7 @@ class Response(object):
@property
def content(self):
return ''.join([chunk for chunk in self._body_iter])
return b''.join([chunk for chunk in self._body_iter])
def get_swift_connection():

@ -66,7 +66,17 @@ class TestJupyterExcecution(unittest.TestCase):
if 'text' in node:
for line in node['text'].split('\n'):
if line:
texts.append(line.strip())
# NOTE: extract bytes lines appreared in the cell
# in PY2, it's NOT needed but in PY3 it is required
# because PY3 explicitly add 'b' prefix to bytes
# objects
if line.startswith("b\'"):
text = eval(line).decode('ascii')
for inline_text in text.split('\n'):
if inline_text:
texts.append(inline_text.strip())
else:
texts.append(line.strip())
return texts
return None
@ -112,8 +122,8 @@ class TestJupyterExcecution(unittest.TestCase):
expected_and_got = zip(
sorted(expected_line.items()),
sorted(got_line.items()))
for (expected_key, expected_value), (got_key, got_value) in \
expected_and_got:
for (expected_key, expected_value), (got_key, got_value) \
in expected_and_got:
self.assertEqual(expected_key, got_key)
if expected_key in COULD_BE_CHANGED:
# TODO(kota_): make more validation for each format

@ -41,7 +41,7 @@ class FakeConnection(object):
if 'resp_chunk_size' in kwargs:
resp_body = self._fake_iter
else:
resp_body = ''.join([chunk for chunk in self._fake_iter])
resp_body = b''.join([chunk for chunk in self._fake_iter])
return (self._fake_headers, resp_body)
@ -297,7 +297,7 @@ class TestStorletMagicGet(BaseTestIpythonExtension, unittest.TestCase):
self.assertEqual({}, resp.headers)
self.assertEqual(200, resp.status)
self.assertEqual('', ''.join([chunk for chunk in iter(resp)]))
self.assertEqual('', resp.content)
self.assertEqual(b'', resp.content)
def test_get(self):
outvar_name = 'a1234'
@ -393,7 +393,7 @@ class TestStorletMagicCopy(BaseTestIpythonExtension, unittest.TestCase):
self.assertEqual({}, resp.headers)
self.assertEqual(200, resp.status)
# sanity, no body
self.assertEqual('', resp.content)
self.assertEqual(b'', resp.content)
def test_copy(self):
outvar_name = 'a1234'
@ -475,7 +475,7 @@ class TestStorletMagicPut(BaseTestIpythonExtension, unittest.TestCase):
self.assertEqual({}, resp.headers)
self.assertEqual(201, resp.status)
# sanity, no body
self.assertEqual('', resp.content)
self.assertEqual(b'', resp.content)
def test_put(self):
outvar_name = 'a1234'