Remove six from unit tests (part 1)

This is part of the steps to remove usage of six library, which is no
longer needed since python 2 support was removed.

Change-Id: I1143918d70da51b53fbb8112ecafa412cd7d0770
This commit is contained in:
Takashi Kajinami 2024-02-17 12:04:11 +09:00
parent aea63db390
commit 766089b7be
6 changed files with 12 additions and 22 deletions

View File

@ -19,12 +19,12 @@
# NOTE(deva): import auth_token so we can override a config option
from unittest import mock
from urllib import parse as urlparse
from keystonemiddleware import auth_token # noqa
from oslo_config import cfg
import pecan
import pecan.testing
from six.moves.urllib import parse as urlparse
from magnum.api import hooks
from magnum.tests.unit.db import base

View File

@ -12,11 +12,11 @@
import datetime
from unittest import mock
from urllib import parse as urlparse
from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
from six.moves.urllib import parse as urlparse
from webtest.app import AppError
from wsme import types as wtypes

View File

@ -16,7 +16,6 @@ from unittest import mock
from oslo_utils import uuidutils
import six
import webtest
import wsme
from wsme import types as wtypes
@ -192,7 +191,7 @@ class TestJsonPatchType(base.FunctionalTest):
class TestMultiType(base.FunctionalTest):
def test_valid_values(self):
vt = types.MultiType(wsme.types.text, six.integer_types)
vt = types.MultiType(wsme.types.text, int)
value = vt.validate("hello")
self.assertEqual("hello", value)
value = vt.validate(10)
@ -205,18 +204,18 @@ class TestMultiType(base.FunctionalTest):
value = vt.validate(uuid)
self.assertEqual(uuid, value)
vt = types.MultiType(types.UuidType, six.integer_types)
vt = types.MultiType(types.UuidType, int)
value = vt.validate(10)
self.assertEqual(10, value)
value = vt.validate(uuid)
self.assertEqual(uuid, value)
def test_invalid_values(self):
vt = types.MultiType(wsme.types.text, six.integer_types)
vt = types.MultiType(wsme.types.text, int)
self.assertRaises(ValueError, vt.validate, 0.10)
self.assertRaises(ValueError, vt.validate, object())
vt = types.MultiType(types.UuidType, six.integer_types)
vt = types.MultiType(types.UuidType, int)
self.assertRaises(ValueError, vt.validate, 'abc')
self.assertRaises(ValueError, vt.validate, 0.10)

View File

@ -15,8 +15,6 @@
from unittest import mock
import six
from oslo_config import cfg
import oslo_messaging as messaging
@ -107,13 +105,8 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest):
# instead of'\n'.join(trace). But since RemoteError is kind of very
# rare thing (happens due to wrong deserialization settings etc.)
# we don't care about this garbage.
if six.PY2:
expected_msg = ("Remote error: %s %s"
% (test_exc_type, self.MSG_WITHOUT_TRACE)
+ "\n[u'")
else:
expected_msg = ("Remote error: %s %s"
% (test_exc_type, self.MSG_WITHOUT_TRACE) + "\n['")
expected_msg = ("Remote error: %s %s"
% (test_exc_type, self.MSG_WITHOUT_TRACE) + "\n['")
actual_msg = response.json['errors'][0]['detail']
self.assertEqual(expected_msg, actual_msg)

View File

@ -13,10 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib
from unittest import mock
from six.moves import reload_module
from magnum.api import validation as v
from magnum.common import exception
import magnum.conf
@ -330,7 +329,7 @@ class TestValidation(base.BaseTestCase):
# Reload the validator module so that ClusterTemplate configs are
# re-evaluated.
reload_module(v)
importlib.reload(v)
validator = v.K8sValidator
with mock.patch.multiple(

View File

@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import io
from unittest import mock
import six
from magnum.cmd import db_manage
from magnum.tests import base
@ -35,7 +34,7 @@ class TestMagnumDbManage(base.TestCase):
@mock.patch('magnum.db.migration.version')
@mock.patch('sys.argv', ['magnum-db-manage', 'version'])
def test_db_manage_version(self, mock_version):
with mock.patch('sys.stdout', new=six.StringIO()) as fakeOutput:
with mock.patch('sys.stdout', new=io.StringIO()) as fakeOutput:
mock_version.return_value = '123456'
db_manage.main()
self.assertEqual('Current DB revision is 123456\n',