diff --git a/heat/common/timeutils.py b/heat/common/timeutils.py index 570bbf39b2..fd0376e3cd 100644 --- a/heat/common/timeutils.py +++ b/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 diff --git a/heat/engine/resources/openstack/monasca/notification.py b/heat/engine/resources/openstack/monasca/notification.py index 511f6df271..fc66816602 100644 --- a/heat/engine/resources/openstack/monasca/notification.py +++ b/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, diff --git a/heat/tests/clients/test_swift_client.py b/heat/tests/clients/test_swift_client.py index 3ceaadaa44..4b6d1060fe 100644 --- a/heat/tests/clients/test_swift_client.py +++ b/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)) diff --git a/heat/tests/engine/service/test_stack_watch.py b/heat/tests/engine/service/test_stack_watch.py index 5e995d27e6..3f1d97dfa2 100644 --- a/heat/tests/engine/service/test_stack_watch.py +++ b/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') diff --git a/heat/tests/openstack/aodh/test_alarm.py b/heat/tests/openstack/aodh/test_alarm.py index 0411c86701..746ac37887 100644 --- a/heat/tests/openstack/aodh/test_alarm.py +++ b/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) diff --git a/heat/tests/openstack/heat/test_random_string.py b/heat/tests/openstack/heat/test_random_string.py index 5f35578d67..0445478cb4 100644 --- a/heat/tests/openstack/heat/test_random_string.py +++ b/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) diff --git a/heat/tests/openstack/heat/test_swiftsignal.py b/heat/tests/openstack/heat/test_swiftsignal.py index a5bf36d134..b688dea058 100644 --- a/heat/tests/openstack/heat/test_swiftsignal.py +++ b/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)) diff --git a/heat/tests/openstack/manila/test_share.py b/heat/tests/openstack/manila/test_share.py index ecf7f0bf50..edaa01a6f1 100644 --- a/heat/tests/openstack/manila/test_share.py +++ b/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): diff --git a/heat/tests/test_environment.py b/heat/tests/test_environment.py index 46efdbe948..fc96afb869 100644 --- a/heat/tests/test_environment.py +++ b/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): diff --git a/heat/tests/test_fault_middleware.py b/heat/tests/test_fault_middleware.py index 3292bb6686..37b0316afb 100644 --- a/heat/tests/test_fault_middleware.py +++ b/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: diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index 5acbc146f5..3c347cfd6e 100644 --- a/heat/tests/test_properties.py +++ b/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'} diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index 1b59fc4229..4cde5f4aaf 100644 --- a/heat/tests/test_stack.py +++ b/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): diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index eb8daa5962..beffdcaff6 100644 --- a/heat/tests/test_template_format.py +++ b/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) diff --git a/tools/custom_guidelines.py b/tools/custom_guidelines.py index 3d3627f1c3..ce0defc80c 100644 --- a/tools/custom_guidelines.py +++ b/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 '