Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: Ieaccbf47ceccade0bd109f42769e42bca0edd0f4
This commit is contained in:
@@ -28,3 +28,8 @@ repos:
|
||||
hooks:
|
||||
- id: bandit
|
||||
args: ['-x', 'tests']
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.18.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py3-only]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
|
||||
@@ -53,7 +53,7 @@ class MessageRouter():
|
||||
try:
|
||||
metric_definition = getattr(mod, metric.name)
|
||||
except AttributeError as e:
|
||||
LOG.error("Failed to load metrics %s: %s" % (metric.name, e))
|
||||
LOG.error("Failed to load metrics {}: {}".format(metric.name, e))
|
||||
return
|
||||
|
||||
# Get labels
|
||||
@@ -64,7 +64,7 @@ class MessageRouter():
|
||||
LOG.error("Failed to load labels func from metrics %s: %s" %
|
||||
(metric.name, e))
|
||||
return
|
||||
LOG.debug("Get labels with %s: %s" % (metric.name, metric.labels))
|
||||
LOG.debug("Get labels with {}: {}".format(metric.name, metric.labels))
|
||||
|
||||
# perform action
|
||||
try:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
@@ -28,10 +26,10 @@ import prometheus_client
|
||||
class TestProcessMessage(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestProcessMessage, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def test_process_counter(self):
|
||||
received_json = """{
|
||||
received_json = b"""{
|
||||
"module": "oslo_messaging",
|
||||
"name": "rpc_server_invocation_start_total",
|
||||
"action": {
|
||||
@@ -48,7 +46,7 @@ class TestProcessMessage(base.BaseTestCase):
|
||||
"method": "get",
|
||||
"process": "done"
|
||||
}
|
||||
}""".encode()
|
||||
}"""
|
||||
|
||||
with mock.patch.object(
|
||||
prometheus_client.Counter, 'inc',
|
||||
@@ -58,7 +56,7 @@ class TestProcessMessage(base.BaseTestCase):
|
||||
mock_inc.assert_called_once_with()
|
||||
|
||||
def test_process_histogram(self):
|
||||
received_json = """{
|
||||
received_json = b"""{
|
||||
"module": "oslo_messaging",
|
||||
"name": "rpc_client_processing_seconds",
|
||||
"action": {
|
||||
@@ -77,7 +75,7 @@ class TestProcessMessage(base.BaseTestCase):
|
||||
"fanout": "foo",
|
||||
"timeout": 10
|
||||
}
|
||||
}""".encode()
|
||||
}"""
|
||||
|
||||
with mock.patch.object(
|
||||
prometheus_client.Histogram, 'observe',
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
@@ -25,7 +23,7 @@ from oslotest import base
|
||||
|
||||
class TestMetricValidation(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestMetricValidation, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def assertRaisesWithMessage(self, message, func, *args, **kwargs):
|
||||
try:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
|
||||
Reference in New Issue
Block a user