Browse Source

Use correct raw string format

You're not supposed to just randomly put backslashes in front of other
characters that don't need escaping unless it's a raw string. This is
deprecated in Python 3.6.

Change-Id: I7a69ba6dd10412bb065f2b6ba405840d0a98663a
changes/42/520842/1
Zane Bitter 4 years ago
parent
commit
22da551c8c
  1. 2
      heat/common/timeutils.py
  2. 2
      heat/engine/resources/openstack/monasca/notification.py
  3. 4
      heat/tests/clients/test_swift_client.py
  4. 4
      heat/tests/engine/service/test_stack_watch.py
  5. 5
      heat/tests/openstack/aodh/test_alarm.py
  6. 4
      heat/tests/openstack/heat/test_random_string.py
  7. 6
      heat/tests/openstack/heat/test_swiftsignal.py
  8. 2
      heat/tests/openstack/manila/test_share.py
  9. 2
      heat/tests/test_environment.py
  10. 2
      heat/tests/test_fault_middleware.py
  11. 5
      heat/tests/test_properties.py
  12. 8
      heat/tests/test_stack.py
  13. 2
      heat/tests/test_template_format.py
  14. 18
      tools/custom_guidelines.py

2
heat/common/timeutils.py

@ -20,7 +20,7 @@ import time
from heat.common.i18n import _
iso_duration_re = re.compile('PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$')
iso_duration_re = re.compile(r'PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$')
wallclock = time.time

2
heat/engine/resources/openstack/monasca/notification.py

@ -140,7 +140,7 @@ class MonascaNotification(resource.Resource):
}
raise exception.StackValidationFailed(message=msg)
elif (self.properties[self.TYPE] == self.EMAIL and
not re.match('^\S+@\S+$', address)):
not re.match(r'^\S+@\S+$', address)):
msg = _('Address "%(addr)s" doesn\'t satisfies allowed format for '
'"%(email)s" type of "%(type)s" property') % {
'addr': address,

4
heat/tests/clients/test_swift_client.py

@ -76,7 +76,7 @@ class SwiftUtilsTest(SwiftClientPluginTestCase):
url = self.swift_plugin.get_temp_url(container_name, obj_name)
self.assertFalse(self.swift_client.post_account.called)
regexp = ("http://fake-host.com:8080/v1/AUTH_demo/%s"
"/%s\?temp_url_sig=[0-9a-f]{40}&"
r"/%s\?temp_url_sig=[0-9a-f]{40}&"
"temp_url_expires=[0-9]{10}" %
(container_name, obj_name))
self.assertThat(url, matchers.MatchesRegex(regexp))
@ -119,7 +119,7 @@ class SwiftUtilsTest(SwiftClientPluginTestCase):
self.assertTrue(self.swift_client.put_container.called)
self.assertTrue(self.swift_client.put_object.called)
regexp = ("http://fake-host.com:8080/v1/AUTH_demo/%s"
"/%s\?temp_url_sig=[0-9a-f]{40}&"
r"/%s\?temp_url_sig=[0-9a-f]{40}&"
"temp_url_expires=[0-9]{10}" %
(container_name, obj_name))
self.assertThat(url, matchers.MatchesRegex(regexp))

4
heat/tests/engine/service/test_stack_watch.py

@ -245,7 +245,7 @@ class StackWatchTest(common.HeatTestCase):
state='NORMAL')
self.wr.store()
for state in ["HGJHGJHG", "1234", "!\*(&%"]:
for state in ["HGJHGJHG", "1234", "!\\*(&%"]:
self.assertRaises(ValueError,
self.eng.set_watch_state,
self.ctx, watch_name="OverrideAlarm2",
@ -253,7 +253,7 @@ class StackWatchTest(common.HeatTestCase):
calls = [mock.call("HGJHGJHG"),
mock.call("1234"),
mock.call("!\*(&%")]
mock.call("!\\*(&%")]
mock_set.assert_has_calls(calls)
@mock.patch.object(watchrule.WatchRule, 'load')

5
heat/tests/openstack/aodh/test_alarm.py

@ -372,8 +372,9 @@ class AodhAlarmTest(common.HeatTestCase):
# python 3.4.3 returns another error message
# so try to handle this by regexp
msg = ("Property error: Resources.MEMAlarmHigh.Properties.%s: "
"int\(\) argument must be a string(, a bytes-like "
"object)? or a number, not 'list'" % p)
r"int\(\) argument must be a string"
"(, a bytes-like object)?"
" or a number, not 'list'" % p)
self.assertRaisesRegex(exception.StackValidationFailed,
msg, rsrc.validate)

4
heat/tests/openstack/heat/test_random_string.py

@ -116,7 +116,7 @@ Resources:
self.assert_min('[0-9]', random_string, 1)
self.assert_min('[A-Z]', random_string, 1)
self.assert_min('[a-z]', random_string, 20)
self.assert_min('[(),\[\]{}]', random_string, 1)
self.assert_min(r'[(),\[\]{}]', random_string, 1)
self.assert_min('[$_]', random_string, 2)
self.assert_min('@', random_string, 5)
self.assertEqual(secret3.FnGetRefId(), random_string)
@ -132,7 +132,7 @@ Resources:
secret5 = stack['secret5']
random_string = secret5.FnGetAtt('value')
self.assertEqual(10, len(random_string))
self.assert_min('[(),\[\]{}]', random_string, 1)
self.assert_min(r'[(),\[\]{}]', random_string, 1)
self.assert_min('[$_]', random_string, 2)
self.assert_min('@', random_string, 5)
self.assertEqual(secret5.FnGetRefId(), random_string)

6
heat/tests/openstack/heat/test_swiftsignal.py

@ -137,7 +137,7 @@ class SwiftSignalHandleTest(common.HeatTestCase):
obj_name = "%s-%s-abcdefghijkl" % (st.name, handle.name)
regexp = ("http://fake-host.com:8080/v1/AUTH_test_tenant/%s/test_st-"
"test_wait_condition_handle-abcdefghijkl"
"\?temp_url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}"
r"\?temp_url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}"
% st.id)
res_id = st.resources['test_wait_condition_handle'].resource_id
self.assertEqual(res_id, handle.physical_resource_name())
@ -718,7 +718,7 @@ class SwiftSignalTest(common.HeatTestCase):
st.create()
self.assertEqual(('CREATE', 'COMPLETE'), st.state)
expected = ('http://fake-host.com:8080/v1/AUTH_test_tenant/%s/'
'test_st-test_wait_condition_handle-abcdefghijkl\?temp_'
r'test_st-test_wait_condition_handle-abcdefghijkl\?temp_'
'url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}') % st.id
self.assertThat(handle.FnGetAtt('endpoint'),
matchers.MatchesRegex(expected))
@ -749,7 +749,7 @@ class SwiftSignalTest(common.HeatTestCase):
self.assertEqual(('CREATE', 'COMPLETE'), st.state)
expected = ("curl -i -X PUT 'http://fake-host.com:8080/v1/"
"AUTH_test_tenant/%s/test_st-test_wait_condition_"
"handle-abcdefghijkl\?temp_url_sig=[0-9a-f]{40}&"
r"handle-abcdefghijkl\?temp_url_sig=[0-9a-f]{40}&"
"temp_url_expires=[0-9]{10}'") % st.id
self.assertThat(handle.FnGetAtt('curl_cli'),
matchers.MatchesRegex(expected))

2
heat/tests/openstack/manila/test_share.py

@ -229,7 +229,7 @@ class ManilaShareTest(common.HeatTestCase):
stack = utils.parse_stack(tmp, stack_name='access_type')
self.assertRaisesRegex(
exception.StackValidationFailed,
".* \"domain\" is not an allowed value \[ip, user, cert, cephx\]",
r'.* "domain" is not an allowed value \[ip, user, cert, cephx\]',
stack.validate)
def test_get_live_state(self):

2
heat/tests/test_environment.py

@ -844,7 +844,7 @@ class ResourceRegistryTest(common.HeatTestCase):
def test_list_type_with_invalid_type_name(self):
registry = resources.global_env().registry
types = registry.get_types(type_name="r'[^\+]'")
types = registry.get_types(type_name="r'[^\\+]'")
self.assertEqual([], types)
def test_list_type_with_version(self):

2
heat/tests/test_fault_middleware.py

@ -174,7 +174,7 @@ class FaultMiddlewareTest(common.HeatTestCase):
if hasattr(obj, 'msg_fmt'):
kwargs = {}
spec_names = re.findall('%\((\w+)\)([cdeEfFgGinorsxX])',
spec_names = re.findall(r'%\((\w+)\)([cdeEfFgGinorsxX])',
obj.msg_fmt)
for key, convtype in spec_names:

5
heat/tests/test_properties.py

@ -784,8 +784,9 @@ class PropertyTest(common.HeatTestCase):
# python 3.4.3 returns another error message
# try to handle this by regexp
self.assertRaisesRegex(
TypeError, "int\(\) argument must be a string(, a bytes-like "
"object)? or a number, not 'list'", p.get_value, [1])
TypeError, r"int\(\) argument must be a string"
"(, a bytes-like object)?"
" or a number, not 'list'", p.get_value, [1])
def test_str_from_int(self):
schema = {'Type': 'String'}

8
heat/tests/test_stack.py

@ -1280,8 +1280,8 @@ class StackTest(common.HeatTestCase):
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv')
stack_names = ['_foo', '1bad', '.kcats', 'test stack', ' teststack',
'^-^', '"stack"', '1234', 'cat|dog', '$(foo)',
'test/stack', 'test\stack', 'test::stack', 'test;stack',
'test~stack', '#test', gt_255_chars]
'test/stack', 'test\\stack', 'test::stack',
'test;stack', 'test~stack', '#test', gt_255_chars]
for stack_name in stack_names:
ex = self.assertRaises(
exception.StackValidationFailed, stack.Stack,
@ -1879,7 +1879,7 @@ class StackTest(common.HeatTestCase):
self.assertRaisesRegex(
exception.StackValidationFailed,
('Outputs.Resource_attr.Value.Fn::GetAtt: The Referenced '
'Attribute \(AResource Bar\) is incorrect.'),
r'Attribute \(AResource Bar\) is incorrect.'),
self.stack.validate)
def test_incorrect_outputs_cfn_incorrect_reference(self):
@ -2242,7 +2242,7 @@ class StackTest(common.HeatTestCase):
self.assertRaisesRegex(
exception.StackValidationFailed,
('outputs.resource_attr.value.get_attr: The Referenced Attribute '
'\(AResource Bar\) is incorrect.'),
r'\(AResource Bar\) is incorrect.'),
self.stack.validate)
def test_snapshot_save_called_first(self):

2
heat/tests/test_template_format.py

@ -82,7 +82,7 @@ class JsonToYamlTest(common.HeatTestCase):
with open(path, 'r') as f:
json_str = f.read()
yml_str = template_format.convert_json_to_yaml(json_str)
match = re.search('[\s,{]\d+\s*:', yml_str)
match = re.search(r'[\s,{]\d+\s*:', yml_str)
# Check that there are no matches of integer-only keys
# lacking explicit quotes
self.assertIsNone(match)

18
tools/custom_guidelines.py

@ -167,12 +167,12 @@ class HeatCustomGuidelines(object):
while idx < len(lines):
if ('properties_schema' in lines[idx] or
'attributes_schema' in lines[idx]):
level = len(re.findall('(\{|\()', lines[idx]))
level -= len(re.findall('(\}|\))', lines[idx]))
level = len(re.findall(r'(\{|\()', lines[idx]))
level -= len(re.findall(r'(\}|\))', lines[idx]))
idx += 1
while level != 0:
level += len(re.findall('(\{|\()', lines[idx]))
level -= len(re.findall('(\}|\))', lines[idx]))
level += len(re.findall(r'(\{|\()', lines[idx]))
level -= len(re.findall(r'(\}|\))', lines[idx]))
if re.search("^((\'|\") )", lines[idx]):
kwargs.update(
{'details': 'line %s' % idx,
@ -180,8 +180,8 @@ class HeatCustomGuidelines(object):
'be on previous line'),
'snippet': lines[idx]})
self.print_guideline_error(**kwargs)
elif (re.search("(\S(\'|\"))$", lines[idx - 1]) and
re.search("^((\'|\")\S)", lines[idx])):
elif (re.search("(\\S(\'|\"))$", lines[idx - 1]) and
re.search("^((\'|\")\\S)", lines[idx])):
kwargs.update(
{'details': 'line %s' % (idx - 1),
'message': _('Omitted whitespace at the '
@ -205,7 +205,7 @@ class HeatCustomGuidelines(object):
'terminator at the end') % error_key.title(),
'snippet': description})
self.print_guideline_error(**error_kwargs)
if re.search("\s{2,}", description):
if re.search(r"\s{2,}", description):
error_kwargs.update(
{'message': _('%s description contains double or more '
'whitespaces') % error_key.title(),
@ -214,7 +214,7 @@ class HeatCustomGuidelines(object):
def _check_description_details(self, doclines, error_kwargs,
error_key):
if re.search("\S", doclines[1]):
if re.search(r"\S", doclines[1]):
error_kwargs.update(
{'message': _('%s description summary and '
'main resource description should be '
@ -240,7 +240,7 @@ class HeatCustomGuidelines(object):
params = False
for line in doclines[1:]:
if re.search("\s{2,}", line):
if re.search(r"\s{2,}", line):
error_kwargs.update(
{'message': _('%s description '
'contains double or more '

Loading…
Cancel
Save