From b625d7b1822b04222f140adb76d23c6ae824d60f Mon Sep 17 00:00:00 2001 From: wangzihao Date: Thu, 22 Oct 2020 11:30:52 +0800 Subject: [PATCH] Remove six Remove six.moves Replace the following items with Python 3 style code. - six.moves.urllib - six.iteritems - six.PY2 - six.StringIO Change-Id: If3fe0e534b092d436e46fca944c2955911e38197 --- aodhclient/tests/functional/test_alarm.py | 7 +++---- aodhclient/tests/unit/test_shell.py | 6 +++--- aodhclient/utils.py | 2 +- aodhclient/v2/base.py | 4 +--- requirements.txt | 1 - 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/aodhclient/tests/functional/test_alarm.py b/aodhclient/tests/functional/test_alarm.py index 6d6c31d..a7eb450 100644 --- a/aodhclient/tests/functional/test_alarm.py +++ b/aodhclient/tests/functional/test_alarm.py @@ -15,7 +15,6 @@ import os from oslo_utils import uuidutils import requests import requests.auth -import six from tempest.lib import exceptions from aodhclient.tests.functional import base @@ -289,7 +288,7 @@ class AodhClientTest(base.ClientTestBase): def test(params): result = self.aodh('alarm', params=params) alarm = self.details_multiple(result)[0] - for key, value in six.iteritems(expected_lines): + for key, value in expected_lines.items(): self.assertEqual(value, alarm[key]) return alarm @@ -686,7 +685,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase): alarm = self.details_multiple(result)[0] ALARM_ID = alarm['alarm_id'] self.assertEqual('alarm1', alarm['name']) - metrics = "[u'cpu', u'cpu_util']" if six.PY2 else "['cpu', 'cpu_util']" + metrics = "['cpu', 'cpu_util']" self.assertEqual(metrics, alarm['metrics']) self.assertEqual('80.0', alarm['threshold']) self.assertEqual('last', alarm['aggregation_method']) @@ -865,7 +864,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase): % (ALARM_ID, METRIC1, METRIC2))) alarm_updated = self.details_multiple(result)[0] self.assertEqual(ALARM_ID, alarm_updated["alarm_id"]) - metrics = "[u'cpu', u'cpu_util']" if six.PY2 else "['cpu', 'cpu_util']" + metrics = "['cpu', 'cpu_util']" self.assertEqual(metrics, alarm_updated['metrics']) self.assertEqual('80.0', alarm_updated['threshold']) self.assertEqual('last', alarm_updated['aggregation_method']) diff --git a/aodhclient/tests/unit/test_shell.py b/aodhclient/tests/unit/test_shell.py index 70ce7a8..71ca8c4 100644 --- a/aodhclient/tests/unit/test_shell.py +++ b/aodhclient/tests/unit/test_shell.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +import io import sys from unittest import mock from keystoneauth1 import exceptions -import six import testtools from aodhclient import shell @@ -24,7 +24,7 @@ from aodhclient import shell class CliTest(testtools.TestCase): - @mock.patch('sys.stderr', six.StringIO()) + @mock.patch('sys.stderr', io.StringIO()) def test_cli_http_error_with_details(self): shell.AodhShell().clean_up( None, None, exceptions.HttpError('foo', details='bar')) @@ -32,7 +32,7 @@ class CliTest(testtools.TestCase): self.assertEqual(1, len(stderr_lines)) self.assertEqual('bar', stderr_lines[0]) - @mock.patch('sys.stderr', six.StringIO()) + @mock.patch('sys.stderr', io.StringIO()) def test_cli_http_error_without_details(self): shell.AodhShell().clean_up(None, None, exceptions.HttpError('foo')) stderr_lines = sys.stderr.getvalue().splitlines() diff --git a/aodhclient/utils.py b/aodhclient/utils.py index d683672..b10b592 100644 --- a/aodhclient/utils.py +++ b/aodhclient/utils.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. import re -from six.moves.urllib import parse as urllib_parse +from urllib import parse as urllib_parse import pyparsing as pp diff --git a/aodhclient/v2/base.py b/aodhclient/v2/base.py index 398b30b..9534bc9 100644 --- a/aodhclient/v2/base.py +++ b/aodhclient/v2/base.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - class Manager(object): DEFAULT_HEADERS = { @@ -26,7 +24,7 @@ class Manager(object): def _set_default_headers(self, kwargs): headers = kwargs.get('headers', {}) - for k, v in six.iteritems(self.DEFAULT_HEADERS): + for k, v in self.DEFAULT_HEADERS.items(): if k not in headers: headers[k] = v kwargs['headers'] = headers diff --git a/requirements.txt b/requirements.txt index 4e6f8c4..f2b84d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,5 +10,4 @@ oslo.serialization>=1.4.0 # Apache-2.0 oslo.utils>=2.0.0 # Apache-2.0 osprofiler>=1.4.0 # Apache-2.0 keystoneauth1>=1.0.0 -six pyparsing \ No newline at end of file