From 23e647539cb9c6872d9f72de99c21e113fded77c Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 9 May 2022 14:48:19 +0900 Subject: Remove six This library no longer supports Python 2, thus usage of six can be removed. Change-Id: I8d0c1cfd6dff375b3b7756a5b36c95a2df3f04c6 --- heatclient/tests/functional/osc/v1/base.py | 5 +- heatclient/tests/unit/osc/fakes.py | 3 +- heatclient/tests/unit/osc/v1/test_resource.py | 2 +- heatclient/tests/unit/osc/v1/test_snapshot.py | 6 +- .../tests/unit/osc/v1/test_software_config.py | 4 +- heatclient/tests/unit/osc/v1/test_stack.py | 7 +- heatclient/tests/unit/test_common_http.py | 10 +- heatclient/tests/unit/test_deployment_utils.py | 5 +- heatclient/tests/unit/test_environment_format.py | 3 +- heatclient/tests/unit/test_format_utils.py | 8 +- heatclient/tests/unit/test_resource_formatter.py | 4 +- heatclient/tests/unit/test_resources.py | 2 +- heatclient/tests/unit/test_shell.py | 28 +-- heatclient/tests/unit/test_template_format.py | 3 +- heatclient/tests/unit/test_template_utils.py | 190 ++++++++++----------- 15 files changed, 128 insertions(+), 152 deletions(-) (limited to 'heatclient/tests') diff --git a/heatclient/tests/functional/osc/v1/base.py b/heatclient/tests/functional/osc/v1/base.py index 591225a..1befa0e 100644 --- a/heatclient/tests/functional/osc/v1/base.py +++ b/heatclient/tests/functional/osc/v1/base.py @@ -12,7 +12,6 @@ import os -import six from tempest.lib.cli import base from tempest.lib.cli import output_parser from tempest.lib import exceptions as tempest_exc @@ -48,7 +47,7 @@ class OpenStackClientTestBase(base.ClientTestBase): obj = {} items = self.parser.listing(output) for item in items: - obj[item['Field']] = six.text_type(item['Value']) + obj[item['Field']] = str(item['Value']) return dict((self._key_name(k), v) for k, v in obj.items()) def _key_name(self, key): @@ -86,7 +85,7 @@ class OpenStackClientTestBase(base.ClientTestBase): self.openstack(cmd) except tempest_exc.CommandFailed as e: msg = "Stack not found: %s" % id - if msg in six.text_type(e.stdout): + if msg in str(e.stdout): return raise diff --git a/heatclient/tests/unit/osc/fakes.py b/heatclient/tests/unit/osc/fakes.py index ba624ad..e45cab1 100644 --- a/heatclient/tests/unit/osc/fakes.py +++ b/heatclient/tests/unit/osc/fakes.py @@ -16,7 +16,6 @@ import json import requests -import six class FakeStdout(object): @@ -41,5 +40,5 @@ class FakeResponse(requests.Response): self.headers.update(headers) self._content = json.dumps(data) - if not isinstance(self._content, six.binary_type): + if not isinstance(self._content, bytes): self._content = self._content.encode() diff --git a/heatclient/tests/unit/osc/v1/test_resource.py b/heatclient/tests/unit/osc/v1/test_resource.py index b932f7e..8d0b314 100644 --- a/heatclient/tests/unit/osc/v1/test_resource.py +++ b/heatclient/tests/unit/osc/v1/test_resource.py @@ -305,7 +305,7 @@ class TestResourceSignal(TestResource): self.assertEqual('Should only specify one of data or data-file', str(error)) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_resource_signal_file(self, urlopen): data = mock.Mock() data.read.side_effect = ['{"message":"Content"}'] diff --git a/heatclient/tests/unit/osc/v1/test_snapshot.py b/heatclient/tests/unit/osc/v1/test_snapshot.py index 1b99942..6b58303 100644 --- a/heatclient/tests/unit/osc/v1/test_snapshot.py +++ b/heatclient/tests/unit/osc/v1/test_snapshot.py @@ -12,8 +12,8 @@ from unittest import mock +import io from osc_lib import exceptions as exc -import six from heatclient import exc as heat_exc from heatclient.osc.v1 import snapshot @@ -160,7 +160,7 @@ class TestSnapshotDelete(TestStack): self.cmd.take_action, parsed_args) - @mock.patch('sys.stdin', spec=six.StringIO) + @mock.patch('sys.stdin', spec=io.StringIO) def test_snapshot_delete_prompt(self, mock_stdin): arglist = ['my_stack', 'snapshot_id'] mock_stdin.isatty.return_value = True @@ -173,7 +173,7 @@ class TestSnapshotDelete(TestStack): self.stack_client.snapshot_delete.assert_called_with('my_stack', 'snapshot_id') - @mock.patch('sys.stdin', spec=six.StringIO) + @mock.patch('sys.stdin', spec=io.StringIO) def test_snapshot_delete_prompt_no(self, mock_stdin): arglist = ['my_stack', 'snapshot_id'] mock_stdin.isatty.return_value = True diff --git a/heatclient/tests/unit/osc/v1/test_software_config.py b/heatclient/tests/unit/osc/v1/test_software_config.py index 470de12..f2afcb1 100644 --- a/heatclient/tests/unit/osc/v1/test_software_config.py +++ b/heatclient/tests/unit/osc/v1/test_software_config.py @@ -145,7 +145,7 @@ class TestCreateConfig(TestConfig): self.mock_client.software_configs.create.assert_called_with( **properties) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_config_create_config_file(self, urlopen): properties = { 'config': 'config', @@ -172,7 +172,7 @@ class TestCreateConfig(TestConfig): self.mock_client.software_configs.create.assert_called_with( **properties) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_config_create_definition_file(self, urlopen): definition = { 'inputs': [ diff --git a/heatclient/tests/unit/osc/v1/test_stack.py b/heatclient/tests/unit/osc/v1/test_stack.py index 7af48ff..49dc8e9 100644 --- a/heatclient/tests/unit/osc/v1/test_stack.py +++ b/heatclient/tests/unit/osc/v1/test_stack.py @@ -17,7 +17,6 @@ from unittest import mock from osc_lib import exceptions as exc from osc_lib import utils -import six import testscenarios import yaml @@ -274,7 +273,7 @@ class TestStackUpdate(TestStack): ex = self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) - self.assertEqual("--rollback invalid value: foo", six.text_type(ex)) + self.assertEqual("--rollback invalid value: foo", str(ex)) def test_stack_update_parameters(self): template_path = ('/'.join(self.template_path.split('/')[:-1]) + @@ -720,7 +719,7 @@ class TestStackDelete(TestStack): self.stack_client.delete.assert_any_call('stack3') self.assertEqual('Unable to delete 1 of the 3 stacks.', str(error)) - @mock.patch('sys.stdin', spec=six.StringIO) + @mock.patch('sys.stdin', spec=io.StringIO) def test_stack_delete_prompt(self, mock_stdin): arglist = ['my_stack'] mock_stdin.isatty.return_value = True @@ -732,7 +731,7 @@ class TestStackDelete(TestStack): mock_stdin.readline.assert_called_with() self.stack_client.delete.assert_called_with('my_stack') - @mock.patch('sys.stdin', spec=six.StringIO) + @mock.patch('sys.stdin', spec=io.StringIO) def test_stack_delete_prompt_no(self, mock_stdin): arglist = ['my_stack'] mock_stdin.isatty.return_value = True diff --git a/heatclient/tests/unit/test_common_http.py b/heatclient/tests/unit/test_common_http.py index 1d32ba1..eb124ca 100644 --- a/heatclient/tests/unit/test_common_http.py +++ b/heatclient/tests/unit/test_common_http.py @@ -15,9 +15,9 @@ import socket from unittest import mock +import io from keystoneauth1 import adapter from oslo_serialization import jsonutils -import six import testtools from heatclient.common import http @@ -608,7 +608,7 @@ class SessionClientTest(testtools.TestCase): e = self.assertRaises(exc.HTTPNotFound, client.request, '', 'GET') # Assert that the raised exception can be converted to string - self.assertIsNotNone(six.text_type(e)) + self.assertIsNotNone(str(e)) def test_redirect_302_location(self): fake1 = fakes.FakeHTTPResponse( @@ -687,7 +687,7 @@ class SessionClientTest(testtools.TestCase): auth=mock.ANY) e = self.assertRaises(exc.InvalidEndpoint, client.request, '', 'GET', redirect=True) - self.assertEqual("Location not returned with 302", six.text_type(e)) + self.assertEqual("Location not returned with 302", str(e)) def test_no_redirect_302_no_location(self): fake = fakes.FakeHTTPResponse( @@ -716,7 +716,7 @@ class SessionClientTest(testtools.TestCase): e = self.assertRaises(exc.HTTPMultipleChoices, client.request, '', 'GET') # Assert that the raised exception can be converted to string - self.assertIsNotNone(six.text_type(e)) + self.assertIsNotNone(str(e)) def test_504_error_response(self): # for 504 we don't have specific exception type @@ -766,7 +766,7 @@ class SessionClientTest(testtools.TestCase): {} ) mock_dumps.return_value = "{'files': test}}" - data = six.BytesIO(b'test') + data = io.BytesIO(b'test') kwargs = {'endpoint_override': 'http://no.where/', 'data': {'files': data}} client = http.SessionClient(mock.ANY) diff --git a/heatclient/tests/unit/test_deployment_utils.py b/heatclient/tests/unit/test_deployment_utils.py index 4a5dc13..d9a7857 100644 --- a/heatclient/tests/unit/test_deployment_utils.py +++ b/heatclient/tests/unit/test_deployment_utils.py @@ -13,7 +13,6 @@ from unittest import mock -import six import swiftclient.client import testscenarios import testtools @@ -231,7 +230,7 @@ class DerivedConfigTest(testtools.TestCase): if not self.result_error: raise e self.assertIsInstance(e, self.result_error) - self.assertEqual(self.result_error_msg, six.text_type(e)) + self.assertEqual(self.result_error_msg, str(e)) class TempURLSignalTest(testtools.TestCase): @@ -331,7 +330,7 @@ class TempURLSignalTest(testtools.TestCase): self.assertEqual(( 'Cannot use --os-no-client-auth, auth required to create ' 'a Swift TempURL.'), - six.text_type(e)) + str(e)) @mock.patch.object(deployment_utils, 'create_temp_url') @mock.patch.object(deployment_utils, 'create_swift_client') diff --git a/heatclient/tests/unit/test_environment_format.py b/heatclient/tests/unit/test_environment_format.py index e2a86a8..86ab0c2 100644 --- a/heatclient/tests/unit/test_environment_format.py +++ b/heatclient/tests/unit/test_environment_format.py @@ -12,7 +12,6 @@ from unittest import mock -import six import testscenarios import testtools import yaml @@ -106,4 +105,4 @@ but very: - incorrect """ ex = self.assertRaises(ValueError, environment_format.parse, yaml) - self.assertIn('but very:\n ^', six.text_type(ex)) + self.assertIn('but very:\n ^', str(ex)) diff --git a/heatclient/tests/unit/test_format_utils.py b/heatclient/tests/unit/test_format_utils.py index 28806d4..4f149fb 100644 --- a/heatclient/tests/unit/test_format_utils.py +++ b/heatclient/tests/unit/test_format_utils.py @@ -12,8 +12,8 @@ # # Copyright 2015 IBM Corp. +import io import json -import six import yaml from heatclient.common import format_utils @@ -128,7 +128,7 @@ abcde truncate_postfix='truncated')) def test_print_software_deployment_output(self): - out = six.StringIO() + out = io.StringIO() format_utils.print_software_deployment_output( {'deploy_stdout': ''}, out=out, name='deploy_stdout') self.assertEqual( @@ -137,7 +137,7 @@ abcde ov = {'deploy_stdout': '', 'deploy_stderr': '1\n2\n3\n4\n5\n6\n7\n8\n9' '\n10\n11', 'deploy_status_code': 0} - out = six.StringIO() + out = io.StringIO() format_utils.print_software_deployment_output(ov, out=out, name='deploy_stderr') self.assertEqual( @@ -156,7 +156,7 @@ abcde 11 (truncated, view all with --long) ''', out.getvalue()) - out = six.StringIO() + out = io.StringIO() format_utils.print_software_deployment_output(ov, out=out, name='deploy_stderr', long=True) diff --git a/heatclient/tests/unit/test_resource_formatter.py b/heatclient/tests/unit/test_resource_formatter.py index 073e12f..f69f649 100644 --- a/heatclient/tests/unit/test_resource_formatter.py +++ b/heatclient/tests/unit/test_resource_formatter.py @@ -14,7 +14,7 @@ import json import os -import six +import io from heatclient.common import resource_formatter from heatclient.osc.v1 import resource @@ -94,7 +94,7 @@ OS::Heat::RandomString" ]; self.resources.append(v1_resources.Resource(None, r)) def test_resource_list(self): - out = six.StringIO() + out = io.StringIO() formatter = resource_formatter.ResourceDotFormatter() formatter.emit_list(None, self.resources, out, None) diff --git a/heatclient/tests/unit/test_resources.py b/heatclient/tests/unit/test_resources.py index 65285e9..8728238 100644 --- a/heatclient/tests/unit/test_resources.py +++ b/heatclient/tests/unit/test_resources.py @@ -14,8 +14,8 @@ from unittest import mock -from six.moves.urllib import parse import testtools +from urllib import parse from heatclient.common import utils from heatclient.v1 import resources diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index c29a3a2..495588b 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -18,15 +18,15 @@ from unittest import mock import uuid import fixtures +import io from keystoneauth1 import fixture as keystone_fixture from oslo_serialization import jsonutils from oslo_utils import encodeutils from requests_mock.contrib import fixture as rm_fixture -import six -from six.moves.urllib import parse -from six.moves.urllib import request import testscenarios import testtools +from urllib import parse +from urllib import request import yaml from heatclient._i18n import _ @@ -411,7 +411,7 @@ class ShellBase(TestCase): def shell(self, argstr): orig = sys.stdout try: - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() _shell = heatclient.shell.HeatShell() _shell.main(argstr.split()) self.subcommands = _shell.subcommands.keys() @@ -525,7 +525,7 @@ class ShellTestNoMoxBase(TestCase): def shell(self, argstr): orig = sys.stdout try: - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() _shell = heatclient.shell.HeatShell() _shell.main(argstr.split()) self.subcommands = _shell.subcommands.keys() @@ -1354,7 +1354,7 @@ class ShellTestUserPass(ShellBase): def test_stack_create_url(self): self.register_keystone_auth_fixture() - url_content = six.StringIO( + url_content = io.StringIO( '{"AWSTemplateFormatVersion" : "2010-09-09"}') self.useFixture(fixtures.MockPatchObject(request, 'urlopen', return_value=url_content)) @@ -2001,7 +2001,7 @@ class ShellTestUserPass(ShellBase): # the main thing this @mock.patch is doing here is keeping # sys.stdin untouched for later tests - @mock.patch('sys.stdin', new_callable=six.StringIO) + @mock.patch('sys.stdin', new_callable=io.StringIO) def test_stack_delete_prompt_with_tty(self, ms): self.register_keystone_auth_fixture() mock_stdin = mock.Mock() @@ -2025,7 +2025,7 @@ class ShellTestUserPass(ShellBase): # the main thing this @mock.patch is doing here is keeping # sys.stdin untouched for later tests - @mock.patch('sys.stdin', new_callable=six.StringIO) + @mock.patch('sys.stdin', new_callable=io.StringIO) def test_stack_delete_prompt_with_tty_y(self, ms): self.register_keystone_auth_fixture() mock_stdin = mock.Mock() @@ -2159,7 +2159,7 @@ class ShellTestUserPass(ShellBase): # the main thing this @mock.patch is doing here is keeping # sys.stdin untouched for later tests - @mock.patch('sys.stdin', new_callable=six.StringIO) + @mock.patch('sys.stdin', new_callable=io.StringIO) def test_snapshot_delete_prompt_with_tty(self, ms): self.register_keystone_auth_fixture() resp_dict = {"snapshot": { @@ -2189,7 +2189,7 @@ class ShellTestUserPass(ShellBase): # the main thing this @mock.patch is doing here is keeping # sys.stdin untouched for later tests - @mock.patch('sys.stdin', new_callable=six.StringIO) + @mock.patch('sys.stdin', new_callable=io.StringIO) def test_snapshot_delete_prompt_with_tty_y(self, ms): self.register_keystone_auth_fixture() resp_dict = {"snapshot": { @@ -2477,7 +2477,7 @@ class ShellTestUserPass(ShellBase): exc.CommandError, self.shell, 'output-show teststack/1 output1') self.assertIn('The Referenced Attribute (0 PublicIP) is incorrect.', - six.text_type(error)) + str(error)) class ShellTestActions(ShellBase): @@ -3548,8 +3548,8 @@ class ShellTestConfig(ShellBase): }} output = [ - six.StringIO(yaml.safe_dump(definition, indent=2)), - six.StringIO('the config script'), + io.StringIO(yaml.safe_dump(definition, indent=2)), + io.StringIO('the config script'), ] self.useFixture(fixtures.MockPatchObject(request, 'urlopen', side_effect=output)) @@ -4082,7 +4082,7 @@ class MockShellBase(TestCase): def shell(self, argstr): orig = sys.stdout try: - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() _shell = heatclient.shell.HeatShell() _shell.main(argstr.split()) self.subcommands = _shell.subcommands.keys() diff --git a/heatclient/tests/unit/test_template_format.py b/heatclient/tests/unit/test_template_format.py index ab2aa1a..479bbac 100644 --- a/heatclient/tests/unit/test_template_format.py +++ b/heatclient/tests/unit/test_template_format.py @@ -12,7 +12,6 @@ from unittest import mock -import six import testscenarios import testtools import yaml @@ -60,4 +59,4 @@ but very: - incorrect """ ex = self.assertRaises(ValueError, template_format.parse, yaml) - self.assertIn('but very:\n ^', six.text_type(ex)) + self.assertIn('but very:\n ^', str(ex)) diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py index a13d7ae..1820278 100644 --- a/heatclient/tests/unit/test_template_utils.py +++ b/heatclient/tests/unit/test_template_utils.py @@ -15,11 +15,11 @@ import json import tempfile from unittest import mock +import io from oslo_serialization import base64 -import six -from six.moves.urllib import error import testtools from testtools import matchers +from urllib import error import yaml from heatclient.common import template_utils @@ -37,8 +37,8 @@ class ShellEnvironmentTest(testtools.TestCase): if url: def side_effect(args): if url == args: - return six.BytesIO(content) - with mock.patch('six.moves.urllib.request.urlopen') as mock_url: + return io.BytesIO(content) + with mock.patch('urllib.request.urlopen') as mock_url: mock_url.side_effect = side_effect template_utils.resolve_environment_urls( jenv.get('resource_registry'), files, env_base_url) @@ -47,7 +47,7 @@ class ShellEnvironmentTest(testtools.TestCase): template_utils.resolve_environment_urls( jenv.get('resource_registry'), files, env_base_url) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_ignore_env_keys(self, mock_url): env_file = '/home/my/dir/env.yaml' env = b''' @@ -57,7 +57,7 @@ class ShellEnvironmentTest(testtools.TestCase): hooks: pre_create restricted_actions: replace ''' - mock_url.return_value = six.BytesIO(env) + mock_url.return_value = io.BytesIO(env) _, env_dict = template_utils.process_environment_and_files( env_file) self.assertEqual( @@ -67,7 +67,7 @@ class ShellEnvironmentTest(testtools.TestCase): env_dict) mock_url.assert_called_with('file://%s' % env_file) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_environment_file(self, mock_url): env_file = '/home/my/dir/env.yaml' @@ -75,8 +75,8 @@ class ShellEnvironmentTest(testtools.TestCase): resource_registry: "OS::Thingy": "file:///home/b/a.yaml" ''' - mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] files, env_dict = template_utils.process_environment_and_files( env_file) @@ -92,7 +92,7 @@ class ShellEnvironmentTest(testtools.TestCase): mock.call('file:///home/b/a.yaml') ]) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_environment_relative_file(self, mock_url): env_file = '/home/my/dir/env.yaml' @@ -102,8 +102,8 @@ class ShellEnvironmentTest(testtools.TestCase): "OS::Thingy": a.yaml ''' - mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] self.assertEqual( env_url, @@ -139,7 +139,7 @@ class ShellEnvironmentTest(testtools.TestCase): self.assertEqual({}, files) self.assertEqual({}, env) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_environment_relative_file_up(self, mock_url): env_file = '/home/my/dir/env.yaml' @@ -148,8 +148,8 @@ class ShellEnvironmentTest(testtools.TestCase): resource_registry: "OS::Thingy": ../bar/a.yaml ''' - mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] env_url = 'file://%s' % env_file self.assertEqual( @@ -174,7 +174,7 @@ class ShellEnvironmentTest(testtools.TestCase): mock.call('file:///home/my/bar/a.yaml') ]) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_environment_url(self, mock_url): env = b''' resource_registry: @@ -182,8 +182,8 @@ class ShellEnvironmentTest(testtools.TestCase): ''' url = 'http://no.where/some/path/to/file.yaml' tmpl_url = 'http://no.where/some/path/to/a.yaml' - mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] files, env_dict = template_utils.process_environment_and_files( url) @@ -197,12 +197,12 @@ class ShellEnvironmentTest(testtools.TestCase): mock.call(tmpl_url) ]) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_environment_empty_file(self, mock_url): env_file = '/home/my/dir/env.yaml' env = b'' - mock_url.return_value = six.BytesIO(env) + mock_url.return_value = io.BytesIO(env) files, env_dict = template_utils.process_environment_and_files( env_file) @@ -216,7 +216,7 @@ class ShellEnvironmentTest(testtools.TestCase): self.assertEqual({}, env) self.assertEqual({}, files) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_multiple_environments_and_files(self, mock_url): env_file1 = '/home/my/dir/env1.yaml' @@ -235,12 +235,12 @@ class ShellEnvironmentTest(testtools.TestCase): "OS::Thingy2": "file:///home/b/b.yaml" ''' - mock_url.side_effect = [six.BytesIO(env1), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(env2), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env1), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(env2), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] files, env = template_utils.process_multiple_environments_and_files( [env_file1, env_file2]) @@ -267,7 +267,7 @@ class ShellEnvironmentTest(testtools.TestCase): mock.call('file:///home/b/b.yaml') ]) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_multiple_environments_default_resources(self, mock_url): env_file1 = '/home/my/dir/env1.yaml' @@ -289,16 +289,16 @@ class ShellEnvironmentTest(testtools.TestCase): resource2: "OS::Thingy4": "file:///home/b/b.yaml" ''' - mock_url.side_effect = [six.BytesIO(env1), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(env2), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env1), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(env2), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] files, env = template_utils.process_multiple_environments_and_files( [env_file1, env_file2]) @@ -378,7 +378,7 @@ class ShellEnvironmentTest(testtools.TestCase): self.assertEqual(self.template_a.decode('utf-8'), files['http://no.where/path/to/b/a.yaml']) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_multiple_environments_and_files_tracker(self, mock_url): # Setup env_file1 = '/home/my/dir/env1.yaml' @@ -389,9 +389,9 @@ class ShellEnvironmentTest(testtools.TestCase): resource_registry: "OS::Thingy1": "file:///home/b/a.yaml" ''' - mock_url.side_effect = [six.BytesIO(env1), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env1), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] # Test env_file_list = [] @@ -419,7 +419,7 @@ class ShellEnvironmentTest(testtools.TestCase): ]) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_environment_relative_file_tracker(self, mock_url): env_file = '/home/my/dir/env.yaml' @@ -428,9 +428,9 @@ class ShellEnvironmentTest(testtools.TestCase): resource_registry: "OS::Thingy": a.yaml ''' - mock_url.side_effect = [six.BytesIO(env), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a)] + mock_url.side_effect = [io.BytesIO(env), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a)] self.assertEqual( env_url, @@ -460,7 +460,7 @@ class ShellEnvironmentTest(testtools.TestCase): ]) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_process_multiple_environments_empty_registry(self, mock_url): # Setup env_file1 = '/home/my/dir/env1.yaml' @@ -473,10 +473,10 @@ class ShellEnvironmentTest(testtools.TestCase): env2 = b''' resource_registry: ''' - mock_url.side_effect = [six.BytesIO(env1), - six.BytesIO(self.template_a), - six.BytesIO(self.template_a), - six.BytesIO(env2)] + mock_url.side_effect = [io.BytesIO(env1), + io.BytesIO(self.template_a), + io.BytesIO(self.template_a), + io.BytesIO(env2)] # Test env_file_list = [] @@ -654,11 +654,11 @@ class TestGetTemplateContents(testtools.TestCase): matchers.MatchesRegex( 'Error parsing template file://%s ' % tmpl_file.name)) - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_get_template_contents_url(self, mock_url): tmpl = b'{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}' url = 'http://no.where/path/to/a.yaml' - mock_url.return_value = six.BytesIO(tmpl) + mock_url.return_value = io.BytesIO(tmpl) files, tmpl_parsed = template_utils.get_template_contents( template_url=url) @@ -726,9 +726,9 @@ class TestGetTemplateContents(testtools.TestCase): [{'path': '/tmp/%s' % filename, 'content': {'get_file': url}, 'encoding': 'b64'}]}}}}} - with mock.patch('six.moves.urllib.request.urlopen') as mock_url: + with mock.patch('urllib.request.urlopen') as mock_url: raw_content = base64.decode_as_bytes(content) - response = six.BytesIO(raw_content) + response = io.BytesIO(raw_content) mock_url.return_value = response files = {} template_utils.resolve_template_get_files( @@ -746,13 +746,7 @@ ABOkDAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA\n''' # zip has '\0' in stream self.assertIn(b'\0', base64.decode_as_bytes(content)) decoded_content = base64.decode_as_bytes(content) - if six.PY3: - self.assertRaises(UnicodeDecodeError, decoded_content.decode) - else: - self.assertRaises( - UnicodeDecodeError, - json.dumps, - {'content': decoded_content}) + self.assertRaises(UnicodeDecodeError, decoded_content.decode) self.check_non_utf8_content( filename=filename, content=content) @@ -762,13 +756,7 @@ ABOkDAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA\n''' # utf6 has '\0' in stream self.assertIn(b'\0', base64.decode_as_bytes(content)) decoded_content = base64.decode_as_bytes(content) - if six.PY3: - self.assertRaises(UnicodeDecodeError, decoded_content.decode) - else: - self.assertRaises( - UnicodeDecodeError, - json.dumps, - {'content': decoded_content}) + self.assertRaises(UnicodeDecodeError, decoded_content.decode) self.check_non_utf8_content(filename=filename, content=content) def test_get_gb18030_content(self): @@ -777,17 +765,11 @@ ABOkDAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA\n''' # gb18030 has no '\0' in stream self.assertNotIn('\0', base64.decode_as_bytes(content)) decoded_content = base64.decode_as_bytes(content) - if six.PY3: - self.assertRaises(UnicodeDecodeError, decoded_content.decode) - else: - self.assertRaises( - UnicodeDecodeError, - json.dumps, - {'content': decoded_content}) + self.assertRaises(UnicodeDecodeError, decoded_content.decode) self.check_non_utf8_content(filename=filename, content=content) -@mock.patch('six.moves.urllib.request.urlopen') +@mock.patch('urllib.request.urlopen') class TestTemplateGetFileFunctions(testtools.TestCase): hot_template = b'''heat_template_version: 2013-05-23 @@ -815,12 +797,12 @@ resources: tmpl_file = '/home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml' - mock_url.side_effect = [six.BytesIO(self.hot_template), - six.BytesIO(b'bar contents'), - six.BytesIO(b'foo contents'), - six.BytesIO(b'baz1 contents'), - six.BytesIO(b'baz2 contents'), - six.BytesIO(b'baz3 contents')] + mock_url.side_effect = [io.BytesIO(self.hot_template), + io.BytesIO(b'bar contents'), + io.BytesIO(b'foo contents'), + io.BytesIO(b'baz1 contents'), + io.BytesIO(b'baz2 contents'), + io.BytesIO(b'baz3 contents')] files, tmpl_parsed = template_utils.get_template_contents( template_file=tmpl_file) @@ -869,8 +851,8 @@ outputs:\n\ contents:\n\ value:\n\ get_file: foo.yaml\n''' - mock_url.side_effect = [six.BytesIO(contents), - six.BytesIO(b'foo contents')] + mock_url.side_effect = [io.BytesIO(contents), + io.BytesIO(b'foo contents')] files = template_utils.get_template_contents( template_file=tmpl_file)[0] self.assertEqual({foo_url: b'foo contents'}, files) @@ -892,8 +874,8 @@ outputs:\n\ template:\n\ value:\n\ get_file: foo.yaml\n''' - mock_url.side_effect = [six.BytesIO(contents), - six.BytesIO(b'foo contents')] + mock_url.side_effect = [io.BytesIO(contents), + io.BytesIO(b'foo contents')] # asserts that is fetched only once even though it is # referenced in the template twice files = template_utils.get_template_contents( @@ -935,18 +917,18 @@ parameters: type: string ''' - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_hot_template(self, mock_url): tmpl_file = '/home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml' def side_effect(args): if url == args: - return six.BytesIO(self.hot_template) + return io.BytesIO(self.hot_template) if 'file:///home/my/dir/foo.yaml' == args: - return six.BytesIO(self.foo_template) + return io.BytesIO(self.foo_template) if 'file:///home/my/dir/spam/egg.yaml' == args: - return six.BytesIO(self.egg_template) + return io.BytesIO(self.egg_template) mock_url.side_effect = side_effect files, tmpl_parsed = template_utils.get_template_contents( @@ -1013,7 +995,7 @@ parameters: type: string ''' - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_hot_template(self, mock_url): tmpl_file = '/home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml' @@ -1022,11 +1004,11 @@ parameters: def side_effect(args): if url == args: - return six.BytesIO(self.hot_template) + return io.BytesIO(self.hot_template) if foo_url == args: - return six.BytesIO(self.foo_template) + return io.BytesIO(self.foo_template) if bar_url == args: - return six.BytesIO(self.bar_template) + return io.BytesIO(self.bar_template) mock_url.side_effect = side_effect files, tmpl_parsed = template_utils.get_template_contents( @@ -1112,7 +1094,7 @@ parameters: type: string ''' - @mock.patch('six.moves.urllib.request.urlopen') + @mock.patch('urllib.request.urlopen') def test_env_nested_includes(self, mock_url): env_file = '/home/my/dir/env.yaml' env_url = 'file:///home/my/dir/env.yaml' @@ -1130,21 +1112,21 @@ parameters: def side_effect(args): if env_url == args: - return six.BytesIO(env) + return io.BytesIO(env) if template_url == args: - return six.BytesIO(self.hot_template) + return io.BytesIO(self.hot_template) if foo_url == args: - return six.BytesIO(self.foo_template) + return io.BytesIO(self.foo_template) if egg_url == args: - return six.BytesIO(self.egg_template) + return io.BytesIO(self.egg_template) if ham_url == args: - return six.BytesIO(b'ham contents') + return io.BytesIO(b'ham contents') if one_url == args: - return six.BytesIO(self.foo_template) + return io.BytesIO(self.foo_template) if two_url == args: - return six.BytesIO(self.foo_template) + return io.BytesIO(self.foo_template) if three_url == args: - return six.BytesIO(b'three contents') + return io.BytesIO(b'three contents') mock_url.side_effect = side_effect files, env_dict = template_utils.process_environment_and_files( -- cgit v1.2.1