Merge "remove unicode prefix from code (2)"

This commit is contained in:
Zuul
2023-12-19 14:05:56 +00:00
committed by Gerrit Code Review
8 changed files with 85 additions and 85 deletions

View File

@@ -41,12 +41,12 @@ def _construct_yaml_str(self, node):
return self.construct_scalar(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 # 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 # datetime.data which causes problems in API layer when being processed by
# openstack.common.jsonutils. Therefore, make unicode string out of timestamps # openstack.common.jsonutils. Therefore, make unicode string out of timestamps
# until jsonutils can handle dates. # 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) _construct_yaml_str)

View File

@@ -282,7 +282,7 @@ class TestResourceSignal(TestResource):
parsed_args = self.check_parser(self.cmd, arglist, []) parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.resource_client.signal.assert_called_with(**{ self.resource_client.signal.assert_called_with(**{
'data': {u'message': u'Content'}, 'data': {'message': 'Content'},
'stack_id': 'my_stack', 'stack_id': 'my_stack',
'resource_name': 'my_resource' 'resource_name': 'my_resource'
}) })
@@ -315,7 +315,7 @@ class TestResourceSignal(TestResource):
parsed_args = self.check_parser(self.cmd, arglist, []) parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.resource_client.signal.assert_called_with(**{ self.resource_client.signal.assert_called_with(**{
'data': {u'message': u'Content'}, 'data': {'message': 'Content'},
'stack_id': 'my_stack', 'stack_id': 'my_stack',
'resource_name': 'my_resource' 'resource_name': 'my_resource'
}) })

View File

@@ -41,7 +41,7 @@ class EventManagerTest(testtools.TestCase):
def test_list_event_with_unicode_resource_name(self): def test_list_event_with_unicode_resource_name(self):
stack_id = 'teststack', stack_id = 'teststack',
resource_name = u'\u5de5\u4f5c' resource_name = '\u5de5\u4f5c'
manager = events.EventManager(None) manager = events.EventManager(None)
with mock.patch('heatclient.v1.events.EventManager._resolve_stack_id')\ with mock.patch('heatclient.v1.events.EventManager._resolve_stack_id')\
as mock_re: as mock_re:
@@ -130,7 +130,7 @@ class EventManagerTest(testtools.TestCase):
@mock.patch('heatclient.common.utils.get_response_body') @mock.patch('heatclient.common.utils.get_response_body')
def test_get_event_with_unicode_resource_name(self, mock_utils, mock_re): def test_get_event_with_unicode_resource_name(self, mock_utils, mock_re):
fields = {'stack_id': 'teststack', fields = {'stack_id': 'teststack',
'resource_name': u'\u5de5\u4f5c', 'resource_name': '\u5de5\u4f5c',
'event_id': '1'} 'event_id': '1'}
class FakeAPI(object): class FakeAPI(object):

View File

@@ -141,7 +141,7 @@ abcde
format_utils.print_software_deployment_output(ov, out=out, format_utils.print_software_deployment_output(ov, out=out,
name='deploy_stderr') name='deploy_stderr')
self.assertEqual( self.assertEqual(
u'''\ '''\
deploy_stderr: | deploy_stderr: |
... ...
2 2
@@ -161,7 +161,7 @@ abcde
name='deploy_stderr', name='deploy_stderr',
long=True) long=True)
self.assertEqual( self.assertEqual(
u'''\ '''\
deploy_stderr: | deploy_stderr: |
1 1
2 2

View File

@@ -94,7 +94,7 @@ class ResourceManagerTest(testtools.TestCase):
def test_get_with_unicode_resource_name(self): def test_get_with_unicode_resource_name(self):
fields = {'stack_id': 'teststack', fields = {'stack_id': 'teststack',
'resource_name': u'\u5de5\u4f5c'} 'resource_name': '\u5de5\u4f5c'}
expect = ('GET', expect = ('GET',
'/stacks/teststack/abcd1234/resources' '/stacks/teststack/abcd1234/resources'
'/%E5%B7%A5%E4%BD%9C') '/%E5%B7%A5%E4%BD%9C')

View File

@@ -872,7 +872,7 @@ class ShellTestUserPass(ShellBase):
"stack_name": "teststack", "stack_name": "teststack",
"stack_status": 'CREATE_COMPLETE', "stack_status": 'CREATE_COMPLETE',
"creation_time": "2012-10-25T01:58:47Z", "creation_time": "2012-10-25T01:58:47Z",
"tags": [u'tag1', u'tag2'] "tags": ['tag1', 'tag2']
}} }}
self.mock_request_get('/stacks/teststack/1', resp_dict) self.mock_request_get('/stacks/teststack/1', resp_dict)
@@ -996,7 +996,7 @@ class ShellTestUserPass(ShellBase):
' "AWSTemplateFormatVersion": "2010-09-09"', ' "AWSTemplateFormatVersion": "2010-09-09"',
' "Outputs": {}', ' "Outputs": {}',
' "Parameters": {}', ' "Parameters": {}',
u' "Description": "test\u2665"', ' "Description": "test\u2665"',
' "Resources": {}', ' "Resources": {}',
'}' '}'
] ]
@@ -2424,7 +2424,7 @@ class ShellTestUserPass(ShellBase):
'output_value', 'output_value',
'description', 'description',
'output2', 'output2',
"[u'output', u'value', u'2']", "['output', 'value', '2']",
'test output 2', 'test output 2',
] ]
for r in required: for r in required:
@@ -2470,7 +2470,7 @@ class ShellTestUserPass(ShellBase):
self._output_fake_response('output_uni') self._output_fake_response('output_uni')
list_text = self.shell('output-show teststack/1 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): def test_output_show_error(self):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()
@@ -3672,7 +3672,7 @@ class ShellTestDeployment(ShellBase):
'id': 'abcd'}} 'id': 'abcd'}}
deploy_data = {'action': 'UPDATE', deploy_data = {'action': 'UPDATE',
'config_id': u'abcd', 'config_id': 'abcd',
'server_id': 'inst01', 'server_id': 'inst01',
'status': 'IN_PROGRESS', 'status': 'IN_PROGRESS',
'tenant_id': 'asdf'} 'tenant_id': 'asdf'}

View File

@@ -61,9 +61,9 @@ class ShellEnvironmentTest(testtools.TestCase):
_, env_dict = template_utils.process_environment_and_files( _, env_dict = template_utils.process_environment_and_files(
env_file) env_file)
self.assertEqual( self.assertEqual(
{u'resource_registry': {u'resources': { {'resource_registry': {'resources': {
u'bar': {u'hooks': u'pre_create', 'bar': {'hooks': 'pre_create',
u'restricted_actions': u'replace'}}}}, 'restricted_actions': 'replace'}}}},
env_dict) env_dict)
mock_url.assert_called_with('file://%s' % env_file) 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'))) json.loads(files.get('file:///home/my/dir/spam/egg.yaml')))
self.assertEqual({ self.assertEqual({
u'heat_template_version': u'2013-05-23', 'heat_template_version': '2013-05-23',
u'parameters': { 'parameters': {
u'param1': { 'param1': {
u'type': u'string' 'type': 'string'
} }
}, },
u'resources': { 'resources': {
u'resource1': { 'resource1': {
u'type': u'file:///home/my/dir/foo.yaml', 'type': 'file:///home/my/dir/foo.yaml',
u'properties': {u'foo': u'bar'} 'properties': {'foo': 'bar'}
}, },
u'resource2': { 'resource2': {
u'type': u'OS::Heat::ResourceGroup', 'type': 'OS::Heat::ResourceGroup',
u'properties': { 'properties': {
u'resource_def': { 'resource_def': {
u'type': u'file:///home/my/dir/spam/egg.yaml' 'type': 'file:///home/my/dir/spam/egg.yaml'
} }
} }
} }
@@ -1018,13 +1018,13 @@ parameters:
json.loads(files.get('file:///home/my/dir/bar.yaml'))) json.loads(files.get('file:///home/my/dir/bar.yaml')))
self.assertEqual({ self.assertEqual({
u'heat_template_version': u'2013-05-23', 'heat_template_version': '2013-05-23',
u'resources': { 'resources': {
u'foo': { 'foo': {
u'type': u'OS::Type1', 'type': 'OS::Type1',
u'properties': { 'properties': {
u'config': { 'config': {
u'get_file': u'file:///home/my/dir/bar.yaml' 'get_file': 'file:///home/my/dir/bar.yaml'
} }
} }
} }
@@ -1032,13 +1032,13 @@ parameters:
}, json.loads(files.get('file:///home/my/dir/foo.yaml'))) }, json.loads(files.get('file:///home/my/dir/foo.yaml')))
self.assertEqual({ self.assertEqual({
u'heat_template_version': u'2013-05-23', 'heat_template_version': '2013-05-23',
u'resources': { 'resources': {
u'resource1': { 'resource1': {
u'type': u'OS::Heat::Stack', 'type': 'OS::Heat::Stack',
u'properties': { 'properties': {
u'template': { 'template': {
u'get_file': u'file:///home/my/dir/foo.yaml' 'get_file': 'file:///home/my/dir/foo.yaml'
} }
} }
} }
@@ -1102,13 +1102,13 @@ parameters:
resource_registry: resource_registry:
"OS::Thingy": template.yaml "OS::Thingy": template.yaml
''' '''
template_url = u'file:///home/my/dir/template.yaml' template_url = 'file:///home/my/dir/template.yaml'
foo_url = u'file:///home/my/dir/foo.yaml' foo_url = 'file:///home/my/dir/foo.yaml'
egg_url = u'file:///home/my/dir/spam/egg.yaml' egg_url = 'file:///home/my/dir/spam/egg.yaml'
ham_url = u'file:///home/my/dir/spam/ham.yaml' ham_url = 'file:///home/my/dir/spam/ham.yaml'
one_url = u'file:///home/my/dir/spam/one.yaml' one_url = 'file:///home/my/dir/spam/one.yaml'
two_url = u'file:///home/my/dir/spam/two.yaml' two_url = 'file:///home/my/dir/spam/two.yaml'
three_url = u'file:///home/my/dir/spam/three.yaml' three_url = 'file:///home/my/dir/spam/three.yaml'
def side_effect(args): def side_effect(args):
if env_url == args: if env_url == args:
@@ -1138,19 +1138,19 @@ parameters:
env_dict) env_dict)
self.assertEqual({ self.assertEqual({
u'heat_template_version': u'2013-05-23', 'heat_template_version': '2013-05-23',
u'parameters': {u'param1': {u'type': u'string'}}, 'parameters': {'param1': {'type': 'string'}},
u'resources': { 'resources': {
u'resource1': { 'resource1': {
u'properties': {u'foo': u'bar'}, 'properties': {'foo': 'bar'},
u'type': foo_url 'type': foo_url
}, },
u'resource2': { 'resource2': {
u'type': u'OS::Heat::ResourceGroup', 'type': 'OS::Heat::ResourceGroup',
u'properties': { 'properties': {
u'resource_def': { 'resource_def': {
u'type': egg_url}, 'type': egg_url},
u'with': {u'get_file': ham_url} 'with': {'get_file': ham_url}
} }
} }
} }
@@ -1159,17 +1159,17 @@ parameters:
self.assertEqual(yaml.safe_load(self.foo_template.decode('utf-8')), self.assertEqual(yaml.safe_load(self.foo_template.decode('utf-8')),
json.loads(files.get(foo_url))) json.loads(files.get(foo_url)))
self.assertEqual({ self.assertEqual({
u'heat_template_version': u'2013-05-23', 'heat_template_version': '2013-05-23',
u'parameters': {u'param1': {u'type': u'string'}}, 'parameters': {'param1': {'type': 'string'}},
u'resources': { 'resources': {
u'resource1': { 'resource1': {
u'properties': {u'foo': u'bar'}, 'properties': {'foo': 'bar'},
u'type': one_url}, 'type': one_url},
u'resource2': { 'resource2': {
u'type': u'OS::Heat::ResourceGroup', 'type': 'OS::Heat::ResourceGroup',
u'properties': { 'properties': {
u'resource_def': {u'type': two_url}, 'resource_def': {'type': two_url},
u'with': {u'get_file': three_url} 'with': {'get_file': three_url}
} }
} }
} }

View File

@@ -122,21 +122,21 @@ class ShellTest(testtools.TestCase):
def test_resource_nested_identifier(self): def test_resource_nested_identifier(self):
rsrc_info = {'resource_name': 'aresource', rsrc_info = {'resource_name': 'aresource',
'links': [{'href': u'http://foo/name/id/resources/0', 'links': [{'href': 'http://foo/name/id/resources/0',
'rel': u'self'}, 'rel': 'self'},
{'href': u'http://foo/name/id', {'href': 'http://foo/name/id',
'rel': u'stack'}, 'rel': 'stack'},
{'href': u'http://foo/n_name/n_id', {'href': 'http://foo/n_name/n_id',
'rel': u'nested'}]} 'rel': 'nested'}]}
rsrc = hc_res.Resource(manager=None, info=rsrc_info) rsrc = hc_res.Resource(manager=None, info=rsrc_info)
self.assertEqual('n_name/n_id', utils.resource_nested_identifier(rsrc)) self.assertEqual('n_name/n_id', utils.resource_nested_identifier(rsrc))
def test_resource_nested_identifier_none(self): def test_resource_nested_identifier_none(self):
rsrc_info = {'resource_name': 'aresource', rsrc_info = {'resource_name': 'aresource',
'links': [{'href': u'http://foo/name/id/resources/0', 'links': [{'href': 'http://foo/name/id/resources/0',
'rel': u'self'}, 'rel': 'self'},
{'href': u'http://foo/name/id', {'href': 'http://foo/name/id',
'rel': u'stack'}]} 'rel': 'stack'}]}
rsrc = hc_res.Resource(manager=None, info=rsrc_info) rsrc = hc_res.Resource(manager=None, info=rsrc_info)
self.assertIsNone(utils.resource_nested_identifier(rsrc)) self.assertIsNone(utils.resource_nested_identifier(rsrc))
@@ -145,7 +145,7 @@ class ShellTest(testtools.TestCase):
self.assertEqual('{}', utils.json_formatter({})) self.assertEqual('{}', utils.json_formatter({}))
self.assertEqual('{\n "foo": "bar"\n}', self.assertEqual('{\n "foo": "bar"\n}',
utils.json_formatter({"foo": "bar"})) 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"})) utils.json_formatter({"Uni": u"test\u2665"}))
def test_yaml_formatter(self): def test_yaml_formatter(self):