From d9a4c29a4fae59c9f4a91873d3010575997e0b2a Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 7 Aug 2022 01:00:45 +0900 Subject: [PATCH] remove unicode prefix from code (2) In Python 3, unicode prefix is meaningless. This removes unicode prefix from code implementation and unit tests. Change-Id: Ic4534dfb3fb6a2d8f7fcf4859a0eacbc3bd146e4 --- heatclient/common/template_format.py | 4 +- heatclient/tests/unit/osc/v1/test_resource.py | 4 +- heatclient/tests/unit/test_events.py | 4 +- heatclient/tests/unit/test_format_utils.py | 4 +- heatclient/tests/unit/test_resources.py | 2 +- heatclient/tests/unit/test_shell.py | 10 +- heatclient/tests/unit/test_template_utils.py | 120 +++++++++--------- heatclient/tests/unit/test_utils.py | 22 ++-- 8 files changed, 85 insertions(+), 85 deletions(-) diff --git a/heatclient/common/template_format.py b/heatclient/common/template_format.py index 6aaf1e01..ff2fdf98 100644 --- a/heatclient/common/template_format.py +++ b/heatclient/common/template_format.py @@ -41,12 +41,12 @@ def _construct_yaml_str(self, node): return self.construct_scalar(node) -yaml_loader.add_constructor(u'tag:yaml.org,2002:str', _construct_yaml_str) +yaml_loader.add_constructor('tag:yaml.org,2002:str', _construct_yaml_str) # Unquoted dates like 2013-05-23 in yaml files get loaded as objects of type # datetime.data which causes problems in API layer when being processed by # openstack.common.jsonutils. Therefore, make unicode string out of timestamps # until jsonutils can handle dates. -yaml_loader.add_constructor(u'tag:yaml.org,2002:timestamp', +yaml_loader.add_constructor('tag:yaml.org,2002:timestamp', _construct_yaml_str) diff --git a/heatclient/tests/unit/osc/v1/test_resource.py b/heatclient/tests/unit/osc/v1/test_resource.py index 8d0b3145..c9e4a603 100644 --- a/heatclient/tests/unit/osc/v1/test_resource.py +++ b/heatclient/tests/unit/osc/v1/test_resource.py @@ -282,7 +282,7 @@ class TestResourceSignal(TestResource): parsed_args = self.check_parser(self.cmd, arglist, []) self.cmd.take_action(parsed_args) self.resource_client.signal.assert_called_with(**{ - 'data': {u'message': u'Content'}, + 'data': {'message': 'Content'}, 'stack_id': 'my_stack', 'resource_name': 'my_resource' }) @@ -315,7 +315,7 @@ class TestResourceSignal(TestResource): parsed_args = self.check_parser(self.cmd, arglist, []) self.cmd.take_action(parsed_args) self.resource_client.signal.assert_called_with(**{ - 'data': {u'message': u'Content'}, + 'data': {'message': 'Content'}, 'stack_id': 'my_stack', 'resource_name': 'my_resource' }) diff --git a/heatclient/tests/unit/test_events.py b/heatclient/tests/unit/test_events.py index ebae3273..289b3e09 100644 --- a/heatclient/tests/unit/test_events.py +++ b/heatclient/tests/unit/test_events.py @@ -41,7 +41,7 @@ class EventManagerTest(testtools.TestCase): def test_list_event_with_unicode_resource_name(self): stack_id = 'teststack', - resource_name = u'\u5de5\u4f5c' + resource_name = '\u5de5\u4f5c' manager = events.EventManager(None) with mock.patch('heatclient.v1.events.EventManager._resolve_stack_id')\ as mock_re: @@ -130,7 +130,7 @@ class EventManagerTest(testtools.TestCase): @mock.patch('heatclient.common.utils.get_response_body') def test_get_event_with_unicode_resource_name(self, mock_utils, mock_re): fields = {'stack_id': 'teststack', - 'resource_name': u'\u5de5\u4f5c', + 'resource_name': '\u5de5\u4f5c', 'event_id': '1'} class FakeAPI(object): diff --git a/heatclient/tests/unit/test_format_utils.py b/heatclient/tests/unit/test_format_utils.py index 4f149fba..87200c45 100644 --- a/heatclient/tests/unit/test_format_utils.py +++ b/heatclient/tests/unit/test_format_utils.py @@ -141,7 +141,7 @@ abcde format_utils.print_software_deployment_output(ov, out=out, name='deploy_stderr') self.assertEqual( - u'''\ + '''\ deploy_stderr: | ... 2 @@ -161,7 +161,7 @@ abcde name='deploy_stderr', long=True) self.assertEqual( - u'''\ + '''\ deploy_stderr: | 1 2 diff --git a/heatclient/tests/unit/test_resources.py b/heatclient/tests/unit/test_resources.py index 8728238f..f7b9dba5 100644 --- a/heatclient/tests/unit/test_resources.py +++ b/heatclient/tests/unit/test_resources.py @@ -94,7 +94,7 @@ class ResourceManagerTest(testtools.TestCase): def test_get_with_unicode_resource_name(self): fields = {'stack_id': 'teststack', - 'resource_name': u'\u5de5\u4f5c'} + 'resource_name': '\u5de5\u4f5c'} expect = ('GET', '/stacks/teststack/abcd1234/resources' '/%E5%B7%A5%E4%BD%9C') diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index 112226d8..f52876fc 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -872,7 +872,7 @@ class ShellTestUserPass(ShellBase): "stack_name": "teststack", "stack_status": 'CREATE_COMPLETE', "creation_time": "2012-10-25T01:58:47Z", - "tags": [u'tag1', u'tag2'] + "tags": ['tag1', 'tag2'] }} self.mock_request_get('/stacks/teststack/1', resp_dict) @@ -996,7 +996,7 @@ class ShellTestUserPass(ShellBase): ' "AWSTemplateFormatVersion": "2010-09-09"', ' "Outputs": {}', ' "Parameters": {}', - u' "Description": "test\u2665"', + ' "Description": "test\u2665"', ' "Resources": {}', '}' ] @@ -2424,7 +2424,7 @@ class ShellTestUserPass(ShellBase): 'output_value', 'description', 'output2', - "[u'output', u'value', u'2']", + "['output', 'value', '2']", 'test output 2', ] for r in required: @@ -2470,7 +2470,7 @@ class ShellTestUserPass(ShellBase): self._output_fake_response('output_uni') list_text = self.shell('output-show teststack/1 output_uni') - self.assertEqual(u'test\u2665\n', list_text) + self.assertEqual('test\u2665\n', list_text) def test_output_show_error(self): self.register_keystone_auth_fixture() @@ -3672,7 +3672,7 @@ class ShellTestDeployment(ShellBase): 'id': 'abcd'}} deploy_data = {'action': 'UPDATE', - 'config_id': u'abcd', + 'config_id': 'abcd', 'server_id': 'inst01', 'status': 'IN_PROGRESS', 'tenant_id': 'asdf'} diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py index 1820278d..83a75851 100644 --- a/heatclient/tests/unit/test_template_utils.py +++ b/heatclient/tests/unit/test_template_utils.py @@ -61,9 +61,9 @@ class ShellEnvironmentTest(testtools.TestCase): _, env_dict = template_utils.process_environment_and_files( env_file) self.assertEqual( - {u'resource_registry': {u'resources': { - u'bar': {u'hooks': u'pre_create', - u'restricted_actions': u'replace'}}}}, + {'resource_registry': {'resources': { + 'bar': {'hooks': 'pre_create', + 'restricted_actions': 'replace'}}}}, env_dict) mock_url.assert_called_with('file://%s' % env_file) @@ -942,22 +942,22 @@ parameters: json.loads(files.get('file:///home/my/dir/spam/egg.yaml'))) self.assertEqual({ - u'heat_template_version': u'2013-05-23', - u'parameters': { - u'param1': { - u'type': u'string' + 'heat_template_version': '2013-05-23', + 'parameters': { + 'param1': { + 'type': 'string' } }, - u'resources': { - u'resource1': { - u'type': u'file:///home/my/dir/foo.yaml', - u'properties': {u'foo': u'bar'} + 'resources': { + 'resource1': { + 'type': 'file:///home/my/dir/foo.yaml', + 'properties': {'foo': 'bar'} }, - u'resource2': { - u'type': u'OS::Heat::ResourceGroup', - u'properties': { - u'resource_def': { - u'type': u'file:///home/my/dir/spam/egg.yaml' + 'resource2': { + 'type': 'OS::Heat::ResourceGroup', + 'properties': { + 'resource_def': { + 'type': 'file:///home/my/dir/spam/egg.yaml' } } } @@ -1018,13 +1018,13 @@ parameters: json.loads(files.get('file:///home/my/dir/bar.yaml'))) self.assertEqual({ - u'heat_template_version': u'2013-05-23', - u'resources': { - u'foo': { - u'type': u'OS::Type1', - u'properties': { - u'config': { - u'get_file': u'file:///home/my/dir/bar.yaml' + 'heat_template_version': '2013-05-23', + 'resources': { + 'foo': { + 'type': 'OS::Type1', + 'properties': { + 'config': { + 'get_file': 'file:///home/my/dir/bar.yaml' } } } @@ -1032,13 +1032,13 @@ parameters: }, json.loads(files.get('file:///home/my/dir/foo.yaml'))) self.assertEqual({ - u'heat_template_version': u'2013-05-23', - u'resources': { - u'resource1': { - u'type': u'OS::Heat::Stack', - u'properties': { - u'template': { - u'get_file': u'file:///home/my/dir/foo.yaml' + 'heat_template_version': '2013-05-23', + 'resources': { + 'resource1': { + 'type': 'OS::Heat::Stack', + 'properties': { + 'template': { + 'get_file': 'file:///home/my/dir/foo.yaml' } } } @@ -1102,13 +1102,13 @@ parameters: resource_registry: "OS::Thingy": template.yaml ''' - template_url = u'file:///home/my/dir/template.yaml' - foo_url = u'file:///home/my/dir/foo.yaml' - egg_url = u'file:///home/my/dir/spam/egg.yaml' - ham_url = u'file:///home/my/dir/spam/ham.yaml' - one_url = u'file:///home/my/dir/spam/one.yaml' - two_url = u'file:///home/my/dir/spam/two.yaml' - three_url = u'file:///home/my/dir/spam/three.yaml' + template_url = 'file:///home/my/dir/template.yaml' + foo_url = 'file:///home/my/dir/foo.yaml' + egg_url = 'file:///home/my/dir/spam/egg.yaml' + ham_url = 'file:///home/my/dir/spam/ham.yaml' + one_url = 'file:///home/my/dir/spam/one.yaml' + two_url = 'file:///home/my/dir/spam/two.yaml' + three_url = 'file:///home/my/dir/spam/three.yaml' def side_effect(args): if env_url == args: @@ -1138,19 +1138,19 @@ parameters: env_dict) self.assertEqual({ - u'heat_template_version': u'2013-05-23', - u'parameters': {u'param1': {u'type': u'string'}}, - u'resources': { - u'resource1': { - u'properties': {u'foo': u'bar'}, - u'type': foo_url + 'heat_template_version': '2013-05-23', + 'parameters': {'param1': {'type': 'string'}}, + 'resources': { + 'resource1': { + 'properties': {'foo': 'bar'}, + 'type': foo_url }, - u'resource2': { - u'type': u'OS::Heat::ResourceGroup', - u'properties': { - u'resource_def': { - u'type': egg_url}, - u'with': {u'get_file': ham_url} + 'resource2': { + 'type': 'OS::Heat::ResourceGroup', + 'properties': { + 'resource_def': { + 'type': egg_url}, + 'with': {'get_file': ham_url} } } } @@ -1159,17 +1159,17 @@ parameters: self.assertEqual(yaml.safe_load(self.foo_template.decode('utf-8')), json.loads(files.get(foo_url))) self.assertEqual({ - u'heat_template_version': u'2013-05-23', - u'parameters': {u'param1': {u'type': u'string'}}, - u'resources': { - u'resource1': { - u'properties': {u'foo': u'bar'}, - u'type': one_url}, - u'resource2': { - u'type': u'OS::Heat::ResourceGroup', - u'properties': { - u'resource_def': {u'type': two_url}, - u'with': {u'get_file': three_url} + 'heat_template_version': '2013-05-23', + 'parameters': {'param1': {'type': 'string'}}, + 'resources': { + 'resource1': { + 'properties': {'foo': 'bar'}, + 'type': one_url}, + 'resource2': { + 'type': 'OS::Heat::ResourceGroup', + 'properties': { + 'resource_def': {'type': two_url}, + 'with': {'get_file': three_url} } } } diff --git a/heatclient/tests/unit/test_utils.py b/heatclient/tests/unit/test_utils.py index ec700f2e..24454e34 100644 --- a/heatclient/tests/unit/test_utils.py +++ b/heatclient/tests/unit/test_utils.py @@ -122,21 +122,21 @@ class ShellTest(testtools.TestCase): def test_resource_nested_identifier(self): rsrc_info = {'resource_name': 'aresource', - 'links': [{'href': u'http://foo/name/id/resources/0', - 'rel': u'self'}, - {'href': u'http://foo/name/id', - 'rel': u'stack'}, - {'href': u'http://foo/n_name/n_id', - 'rel': u'nested'}]} + 'links': [{'href': 'http://foo/name/id/resources/0', + 'rel': 'self'}, + {'href': 'http://foo/name/id', + 'rel': 'stack'}, + {'href': 'http://foo/n_name/n_id', + 'rel': 'nested'}]} rsrc = hc_res.Resource(manager=None, info=rsrc_info) self.assertEqual('n_name/n_id', utils.resource_nested_identifier(rsrc)) def test_resource_nested_identifier_none(self): rsrc_info = {'resource_name': 'aresource', - 'links': [{'href': u'http://foo/name/id/resources/0', - 'rel': u'self'}, - {'href': u'http://foo/name/id', - 'rel': u'stack'}]} + 'links': [{'href': 'http://foo/name/id/resources/0', + 'rel': 'self'}, + {'href': 'http://foo/name/id', + 'rel': 'stack'}]} rsrc = hc_res.Resource(manager=None, info=rsrc_info) self.assertIsNone(utils.resource_nested_identifier(rsrc)) @@ -145,7 +145,7 @@ class ShellTest(testtools.TestCase): self.assertEqual('{}', utils.json_formatter({})) self.assertEqual('{\n "foo": "bar"\n}', utils.json_formatter({"foo": "bar"})) - self.assertEqual(u'{\n "Uni": "test\u2665"\n}', + self.assertEqual('{\n "Uni": "test\u2665"\n}', utils.json_formatter({"Uni": u"test\u2665"})) def test_yaml_formatter(self):