From 28f97734203a2df33805291673104742d45d34f3 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Sat, 7 Sep 2013 12:27:46 -0400 Subject: [PATCH] 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 --- novaclient/tests/test_utils.py | 8 ++++---- novaclient/tests/v1_1/test_servers.py | 12 +++++------- novaclient/tests/v1_1/test_shell.py | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/novaclient/tests/test_utils.py b/novaclient/tests/test_utils.py index 64c97614f..8809133ac 100644 --- a/novaclient/tests/test_utils.py +++ b/novaclient/tests/test_utils.py @@ -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), diff --git a/novaclient/tests/v1_1/test_servers.py b/novaclient/tests/v1_1/test_servers.py index 19cca5bb1..658068f77 100644 --- a/novaclient/tests/v1_1/test_servers.py +++ b/novaclient/tests/v1_1/test_servers.py @@ -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') diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index 236182c57..d7a5e0d38 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -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)