Python3: Use six.StringIO for io.Bytes()
The newer version of six (1.4.1) provides six.StringIO which is a fake file object for textual data. It's an alias for StringIO.StringIO in python2 and io.StringIO in Python3. Use the fake object where approiate. Change-Id: I364001933b4f2305ac27b293a9a4a3fec36c8a49 Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
parent
cab4617225
commit
28f9773420
novaclient/tests
@ -1,7 +1,7 @@
|
||||
import io
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient import utils
|
||||
@ -112,7 +112,7 @@ class _FakeResult(object):
|
||||
|
||||
|
||||
class PrintResultTestCase(test_utils.TestCase):
|
||||
@mock.patch('sys.stdout', io.BytesIO())
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
def test_print_list_sort_by_str(self):
|
||||
objs = [_FakeResult("k1", 1),
|
||||
_FakeResult("k3", 2),
|
||||
@ -129,7 +129,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'| k3 | 2 |\n'
|
||||
'+------+-------+\n')
|
||||
|
||||
@mock.patch('sys.stdout', io.BytesIO())
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
def test_print_list_sort_by_integer(self):
|
||||
objs = [_FakeResult("k1", 1),
|
||||
_FakeResult("k3", 2),
|
||||
@ -147,7 +147,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+------+-------+\n')
|
||||
|
||||
# without sorting
|
||||
@mock.patch('sys.stdout', io.BytesIO())
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
def test_print_list_sort_by_none(self):
|
||||
objs = [_FakeResult("k1", 1),
|
||||
_FakeResult("k3", 3),
|
||||
|
@ -1,7 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
@ -56,7 +54,7 @@ class ServersTest(utils.TestCase):
|
||||
key_name="fakekey",
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': io.BytesIO('data'), # a stream
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
}
|
||||
)
|
||||
cs.assert_called('POST', '/servers')
|
||||
@ -100,10 +98,10 @@ class ServersTest(utils.TestCase):
|
||||
image=1,
|
||||
flavor=1,
|
||||
meta={'foo': 'bar'},
|
||||
userdata=io.BytesIO('hello moto'),
|
||||
userdata=six.StringIO('hello moto'),
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': io.BytesIO('data'), # a stream
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
},
|
||||
)
|
||||
cs.assert_called('POST', '/servers')
|
||||
@ -119,7 +117,7 @@ class ServersTest(utils.TestCase):
|
||||
key_name="fakekey",
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': io.BytesIO('data'), # a stream
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
},
|
||||
)
|
||||
cs.assert_called('POST', '/servers')
|
||||
@ -135,7 +133,7 @@ class ServersTest(utils.TestCase):
|
||||
key_name="fakekey",
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': io.BytesIO('data'), # a stream
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
},
|
||||
)
|
||||
cs.assert_called('POST', '/servers')
|
||||
|
@ -17,13 +17,13 @@
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import io
|
||||
import os
|
||||
import mock
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
import six
|
||||
|
||||
import novaclient.client
|
||||
from novaclient import exceptions
|
||||
@ -71,7 +71,7 @@ class ShellTest(utils.TestCase):
|
||||
lambda *_: fakes.FakeClient))
|
||||
self.addCleanup(timeutils.clear_time_override)
|
||||
|
||||
@mock.patch('sys.stdout', io.BytesIO())
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
def run_command(self, cmd):
|
||||
if isinstance(cmd, list):
|
||||
self.shell.main(cmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user