Mark raw strings as such

This is raising warnings now and will be an error in future versions of
Python 3.

Change-Id: I8827cb36ef2ef85e8f245a2a181fb23ee75bfd16
This commit is contained in:
Stephen Finucane 2018-07-06 13:58:21 +01:00
parent a6353c452e
commit 7f4a6211bf
21 changed files with 26 additions and 18 deletions

View File

@ -84,6 +84,6 @@ class KeyPairsNegativeTestJSON(base.BaseKeypairTest):
@decorators.idempotent_id('45fbe5e0-acb5-49aa-837a-ff8d0719db91')
def test_create_keypair_invalid_name(self):
# Keypairs with name being an invalid name should not be created
k_name = 'key_/.\@:'
k_name = r'key_/.\@:'
self.assertRaises(lib_exc.BadRequest, self.create_keypair,
k_name)

View File

@ -227,7 +227,7 @@ class ListServerFiltersTestJSON(base.BaseV2ComputeTest):
@decorators.idempotent_id('24a89b0c-0d55-4a28-847f-45075f19b27b')
def test_list_servers_filtered_by_name_regex(self):
# list of regex that should match s1, s2 and s3
regexes = ['^.*\-instance\-[0-9]+$', '^.*\-instance\-.*$']
regexes = [r'^.*\-instance\-[0-9]+$', r'^.*\-instance\-.*$']
for regex in regexes:
params = {'name': regex}
body = self.client.list_servers(**params)

View File

@ -59,7 +59,7 @@ class QuotasNegativeTest(base.BaseAdminNetworkTest):
# Try to create a third network while the quota is two
with self.assertRaisesRegex(
lib_exc.Conflict,
"Quota exceeded for resources: \['network'\].*"):
r"Quota exceeded for resources: \['network'\].*"):
n3 = self.networks_client.create_network()
self.addCleanup(self.networks_client.delete_network,
n3['network']['id'])

View File

@ -311,5 +311,6 @@ def main(opts=None):
resources.extend(generate_resources(cred_provider, opts.admin))
dump_accounts(resources, opts.identity_version, opts.accounts)
if __name__ == "__main__":
main()

View File

@ -26,7 +26,7 @@ from tempest.cmd import workspace
LOG = logging.getLogger(__name__)
STESTR_CONF = """[DEFAULT]
STESTR_CONF = r"""[DEFAULT]
test_path=%s
top_dir=%s
group_regex=([^\.]*\.)*

View File

@ -95,7 +95,7 @@ class UrlParser(testtools.TestResult):
ip_re = re.compile(r'(^|[^0-9])[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]'
'{1,3}([^0-9]|$)')
url_re = re.compile(r'.*INFO.*Request \((?P<name>.*)\): (?P<code>[\d]{3}) '
'(?P<verb>\w*) (?P<url>.*) .*')
r'(?P<verb>\w*) (?P<url>.*) .*')
port_re = re.compile(r'.*:(?P<port>\d+).*')
path_re = re.compile(r'http[s]?://[^/]*/(?P<path>.*)')
request_re = re.compile(r'.* Request - Headers: (?P<headers>.*)')

View File

@ -488,5 +488,6 @@ class TempestVerifyConfig(command.Command):
traceback.print_exc()
raise
if __name__ == "__main__":
main()

View File

@ -210,6 +210,7 @@ def is_alt_available(identity_version):
except exceptions.InvalidConfiguration:
return False
# === Credentials
# Type of credentials available from configuration

View File

@ -225,9 +225,9 @@ class AreAllWellFormatted(object):
elif key in ('content-type', 'date', 'last-modified',
'x-copied-from-last-modified') and not value:
return InvalidFormat(key, value)
elif key == 'x-timestamp' and not re.match("^\d+\.?\d*\Z", value):
elif key == 'x-timestamp' and not re.match(r"^\d+\.?\d*\Z", value):
return InvalidFormat(key, value)
elif key == 'x-copied-from' and not re.match("\S+/\S+", value):
elif key == 'x-copied-from' and not re.match(r"\S+/\S+", value):
return InvalidFormat(key, value)
elif key == 'x-trans-id' and \
not re.match("^tx[0-9a-f]{21}-[0-9a-f]{10}.*", value):

View File

@ -40,6 +40,7 @@ class DataUtils(object):
self.__dict__[attr] = attr_obj
return attr_obj
data_utils = DataUtils()

View File

@ -287,10 +287,10 @@ def dont_put_admin_tests_on_nonadmin_path(logical_line, physical_line,
if pep8.noqa(physical_line):
return
if not re.match('class .*Test.*\(.*Admin.*\):', logical_line):
if not re.match(r'class .*Test.*\(.*Admin.*\):', logical_line):
return
if not re.match('.\/tempest\/api\/.*\/admin\/.*', filename):
if not re.match(r'.\/tempest\/api\/.*\/admin\/.*', filename):
msg = 'T115: All admin tests should exist under admin path.'
yield(0, msg)

View File

@ -20,7 +20,7 @@ set_get_flavor_extra_specs = {
'extra_specs': {
'type': 'object',
'patternProperties': {
'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'}
r'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'}
}
}
},
@ -34,7 +34,7 @@ set_get_flavor_extra_specs_key = {
'response_body': {
'type': 'object',
'patternProperties': {
'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'}
r'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'}
}
}
}

View File

@ -26,7 +26,7 @@ flavor = {
'extra_specs': {
'type': 'object',
'patternProperties': {
'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'}
r'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'}
}
}
},

View File

@ -25,7 +25,7 @@ from tempest.lib import exceptions
LOG = logging.getLogger(__name__)
delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')
delimiter_line = re.compile(r'^\+\-[\+\-]+\-\+$')
def details_multiple(output_lines, with_label=False):

View File

@ -358,5 +358,6 @@ def run():
"Run 'tox -v -e uuidgen' to automatically fix tests with\n"
"missing @decorators.idempotent_id decorators.")
if __name__ == '__main__':
run()

View File

@ -77,7 +77,7 @@ class TestRemoteClient(base.TestCase):
def test_write_to_console_special_chars(self):
self._test_write_to_console_helper(
'\`',
r'\`',
'sudo sh -c "echo \\"\\\\\\`\\" >/dev/console"')
self.conn.write_to_console('$')
self._assert_exec_called_with(

View File

@ -59,6 +59,7 @@ class FakePrivate(config.TempestConfigPrivate):
self._set_attrs()
self.lock_path = cfg.CONF.oslo_concurrency.lock_path
fake_service1_group = cfg.OptGroup(name='fake-service1', title='Fake service1')
FakeService1Group = [

View File

@ -88,7 +88,7 @@ class TestDataUtils(base.TestCase):
def test_rand_url(self):
actual = data_utils.rand_url()
self.assertIsInstance(actual, str)
self.assertRegex(actual, "^https://url-[0-9]*\.com$")
self.assertRegex(actual, r"^https://url-[0-9]*\.com$")
actual2 = data_utils.rand_url()
self.assertNotEqual(actual, actual2)

View File

@ -34,7 +34,7 @@ class TestTestList(base.TestCase):
"error on import %s" % ids)
ids = six.text_type(ids).split('\n')
for test_id in ids:
if re.match('(\w+\.){3}\w+', test_id):
if re.match(r'(\w+\.){3}\w+', test_id):
if not test_id.startswith('tempest.'):
parts = test_id.partition('tempest')
fail_id = parts[1] + parts[2]

View File

@ -96,7 +96,7 @@ def scan_content(content, regexp, whitelist):
def collect_url_logs(url):
page = urlreq.urlopen(url)
content = page.read()
logs = re.findall('(screen-[\w-]+\.txt\.gz)</a>', content)
logs = re.findall(r'(screen-[\w-]+\.txt\.gz)</a>', content)
return logs
@ -162,6 +162,7 @@ def main(opts):
print("ok")
return 0
usage = """
Find non-white-listed log errors in log files from a devstack-gate run.
Log files will be searched for ERROR or CRITICAL messages. If any

View File

@ -63,12 +63,13 @@ def has_tempest_plugin(proj):
except HTTPError as err:
if err.code == 404:
return False
p = re.compile('^tempest\.test_plugins', re.M)
p = re.compile(r'^tempest\.test_plugins', re.M)
if p.findall(r.read().decode('utf-8')):
return True
else:
False
r = urllib.urlopen(url)
# Gerrit prepends 4 garbage octets to the JSON, in order to counter
# cross-site scripting attacks. Therefore we must discard it so the