Merge "Replace assertRaisesRegexp with assertRaisesRegex"

This commit is contained in:
Jenkins 2017-05-22 17:44:19 +00:00 committed by Gerrit Code Review
commit b017242c0b
13 changed files with 109 additions and 109 deletions

View File

@ -62,7 +62,7 @@ class TestSchemas(test_base.MuranoTestCase):
dummy_error = client.RemoteError(exc_type=exc_type,
value='dummy_value')
mock_rpc.engine().generate_schema.side_effect = dummy_error
with self.assertRaisesRegexp(exc.HTTPNotFound,
with self.assertRaisesRegex(exc.HTTPNotFound,
dummy_error.value):
self.controller.get_schema(mock_request, 'test_class')
@ -70,6 +70,6 @@ class TestSchemas(test_base.MuranoTestCase):
dummy_error = client.RemoteError(exc_type='TestExcType',
value='dummy_value')
mock_rpc.engine().generate_schema.side_effect = dummy_error
with self.assertRaisesRegexp(client.RemoteError,
with self.assertRaisesRegex(client.RemoteError,
dummy_error.value):
self.controller.get_schema(mock_request, 'test_class')

View File

@ -214,7 +214,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
for state in illegal_states:
mock_envs.EnvironmentServices.get_status.return_value = state
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_msg):
self.sessions_controller.configure(mock_request, 'test_env_id')
@ -229,7 +229,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
'access session <SessionId {1}>.'\
.format(mock_request.context.user, 'test_sess_id')
with self.assertRaisesRegexp(exc.HTTPUnauthorized,
with self.assertRaisesRegex(exc.HTTPUnauthorized,
expected_error_msg):
self.sessions_controller.show(mock_request, None, 'test_sess_id')
@ -247,7 +247,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
' has been updated or updating right now with'\
' other session'.format('test_sess_id')
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_msg):
self.sessions_controller.show(mock_request, None, 'test_sess_id')
@ -262,7 +262,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
'access session <SessionId {1}>.'\
.format(mock_request.context.user, 'test_sess_id')
with self.assertRaisesRegexp(exc.HTTPUnauthorized,
with self.assertRaisesRegex(exc.HTTPUnauthorized,
expected_error_msg):
self.sessions_controller.delete(mock_request, None, 'test_sess_id')
@ -281,7 +281,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
'state and could not be deleted'\
.format('test_sess_id')
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_msg):
self.sessions_controller.delete(mock_request, None, 'test_sess_id')
@ -297,7 +297,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
' has been updated or updating right now with'\
' other session'.format('test_sess_id')
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_msg):
self.sessions_controller.deploy(mock_request, None, 'test_sess_id')
@ -321,7 +321,7 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
mock_session = mock.MagicMock(state=state)
mock_db_session.get_session().query().get.return_value =\
mock_session
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_msg):
self.sessions_controller.deploy(
mock_request, None, 'test_sess_id')

View File

@ -217,7 +217,7 @@ class TestManage(test_base.MuranoWithDBTestCase):
def test_main_except_runtime_error(self, mock_conf):
mock_conf.side_effect = RuntimeError
with self.assertRaisesRegexp(SystemExit, 'ERROR:'):
with self.assertRaisesRegex(SystemExit, 'ERROR:'):
manage.main()
@mock.patch('murano.cmd.manage.CONF')
@ -226,5 +226,5 @@ class TestManage(test_base.MuranoWithDBTestCase):
expected_err_msg = "murano-manage command failed:"
with self.assertRaisesRegexp(SystemExit, expected_err_msg):
with self.assertRaisesRegex(SystemExit, expected_err_msg):
manage.main()

View File

@ -194,7 +194,7 @@ class MQClientTest(base.MuranoTestCase):
queue_arguments={})
def test_declare_except_runtime_error(self):
with self.assertRaisesRegexp(RuntimeError,
with self.assertRaisesRegex(RuntimeError,
'Not connected to RabbitMQ'):
self.ssl_client.declare(None)
@ -212,7 +212,7 @@ class MQClientTest(base.MuranoTestCase):
body=jsonutils.dumps('test_message'), message_id='3')
def test_send_except_runtime_error(self):
with self.assertRaisesRegexp(RuntimeError,
with self.assertRaisesRegex(RuntimeError,
'Not connected to RabbitMQ'):
self.ssl_client.send(None, None)
@ -224,6 +224,6 @@ class MQClientTest(base.MuranoTestCase):
self.ssl_client._connection, 'test_queue', 2)
def test_open_except_runtime_error(self):
with self.assertRaisesRegexp(RuntimeError,
with self.assertRaisesRegex(RuntimeError,
'Not connected to RabbitMQ'):
self.ssl_client.open(None)

View File

@ -222,7 +222,7 @@ class TestAgent(base.MuranoTestCase):
expected_error_msg = 'The murano-agent did not respond within 1 '\
'seconds'
with self.assertRaisesRegexp(exceptions.TimeoutException,
with self.assertRaisesRegex(exceptions.TimeoutException,
expected_error_msg):
self.agent.call(template, self.resources, None)

View File

@ -98,7 +98,7 @@ class TestMistralClient(base.MuranoTestCase):
expected_error_msg = 'Mistral execution completed with ERROR.'\
' Execution id: {0}. Output: {1}'\
.format(mock_execution.id, mock_execution.output)
with self.assertRaisesRegexp(workflowclient.MistralError,
with self.assertRaisesRegex(workflowclient.MistralError,
expected_error_msg):
mc.run(run_name, timeout)
@ -114,7 +114,7 @@ class TestMistralClient(base.MuranoTestCase):
expected_error_msg = 'Mistral run timed out. Execution id: {0}.'\
.format(mock_execution.id)
with self.assertRaisesRegexp(workflowclient.MistralError,
with self.assertRaisesRegex(workflowclient.MistralError,
expected_error_msg):
mc.run(run_name, timeout)

View File

@ -190,7 +190,7 @@ class TestPackageCache(base.MuranoTestCase):
self.loader.import_fixation_table({fqn: [test_version]})
self.loader.register_package(package)
with self.assertRaisesRegexp(dsl_exceptions.NoPackageFound,
with self.assertRaisesRegex(dsl_exceptions.NoPackageFound,
expected_error_msg):
for spec in invalid_specs:
self.loader.load_package('test_package_name', spec)
@ -324,7 +324,7 @@ class TestPackageCache(base.MuranoTestCase):
for class_ in package.classes:
expected_error_msg = 'Package for class "{0}" is not found'\
.format(class_)
with self.assertRaisesRegexp(dsl_exceptions.NoPackageForClassFound,
with self.assertRaisesRegex(dsl_exceptions.NoPackageForClassFound,
expected_error_msg):
for spec in invalid_specs:
self.loader.load_class_package(class_, spec)
@ -371,7 +371,7 @@ class TestPackageCache(base.MuranoTestCase):
def test_get_definition_except_lookup_error(self, mock_log):
self.loader.client.packages.filter.return_value = []
with self.assertRaisesRegexp(LookupError, None):
with self.assertRaisesRegex(LookupError, None):
self.loader._get_definition({})
mock_log.debug.assert_called_once_with(
@ -382,7 +382,7 @@ class TestPackageCache(base.MuranoTestCase):
self.loader.client.packages.filter.side_effect =\
muranoclient_exc.HTTPException
with self.assertRaisesRegexp(LookupError, None):
with self.assertRaisesRegex(LookupError, None):
self.loader._get_definition({})
mock_log.debug.assert_called_once_with(
@ -445,7 +445,7 @@ class TestPackageCache(base.MuranoTestCase):
muranoclient_exc.HTTPException
expected_error_msg = 'Error loading package id {0}:'.format(package.id)
with self.assertRaisesRegexp(pkg_exc.PackageLoadError,
with self.assertRaisesRegex(pkg_exc.PackageLoadError,
expected_error_msg):
self.loader._get_package_by_definition(package)
@ -475,7 +475,7 @@ class TestPackageCache(base.MuranoTestCase):
expected_error_msg = 'Unable to extract package data for {0}'\
.format(package.id)
with self.assertRaisesRegexp(pkg_exc.PackageLoadError,
with self.assertRaisesRegex(pkg_exc.PackageLoadError,
expected_error_msg):
self.loader._get_package_by_definition(package)

View File

@ -133,7 +133,7 @@ class TestHotPackage(test_base.MuranoTestCase):
self.assertEqual(expected_result, result['templateParameters'])
def test_translate_param_to_contract_with_inappropriate_value(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
'Unsupported parameter type',
murano.packages.hot_package.HotPackage.
@ -149,7 +149,7 @@ class TestHotPackage(test_base.MuranoTestCase):
def test_get_class_name_with_invalid_template_name(self):
hot_package = self._get_hot_package(self.test_dirs[0])
self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.PackageClassLoadError,
'Class not defined in this package',
hot_package.get_class,
@ -157,7 +157,7 @@ class TestHotPackage(test_base.MuranoTestCase):
def test_get_class_name_with_invalid_template_format(self):
hot_package = self._get_hot_package(self.test_dirs[1])
self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.PackageFormatError,
'Not a HOT template',
hot_package.get_class,
@ -184,14 +184,14 @@ class TestHotPackage(test_base.MuranoTestCase):
def test_translate_ui_with_nonexistent_template(self):
hot_package = self._get_hot_package(self.test_dirs[2])
self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.PackageClassLoadError,
'File with class definition not found',
hot_package._translate_ui)
def test_translate_class_with_nonexistent_template(self):
hot_package = self._get_hot_package(self.test_dirs[2])
self.assertRaisesRegexp(
self.assertRaisesRegex(
exceptions.PackageClassLoadError,
'File with class definition not found',
hot_package._translate_class)

View File

@ -132,7 +132,7 @@ class TestLoadUtils(test_base.MuranoTestCase):
self._create_temp_zip_file(zip_path, manifest_path)
expected_error_msg = "Unsupported format {0}".format(test_format)
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
with load_utils.load_from_file(archive_path=zip_path,
target_dir=target_dir,
@ -143,7 +143,7 @@ class TestLoadUtils(test_base.MuranoTestCase):
def test_load_from_file_with_invalid_archive_path(self):
expected_error_msg = "Unable to find package file"
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
with load_utils.load_from_file('invalid file path'):
pass
@ -153,7 +153,7 @@ class TestLoadUtils(test_base.MuranoTestCase):
mock_os.listdir = mock.MagicMock(return_value=True)
temp_file = self._create_temp_file()
expected_error_msg = "Target directory is not empty"
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
this_dir = os.path.dirname(os.path.realpath(__file__))
with load_utils.load_from_file(temp_file.name,
@ -164,7 +164,7 @@ class TestLoadUtils(test_base.MuranoTestCase):
temp_file = self._create_temp_file()
expected_error_msg = "Uploaded file {0} is not a zip archive".\
format(temp_file.name)
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
with load_utils.load_from_file(temp_file.name):
pass
@ -177,7 +177,7 @@ class TestLoadUtils(test_base.MuranoTestCase):
mock_zipfile.is_zipfile = mock.MagicMock(
side_effect=ValueError(test_error_msg))
temp_file = self._create_temp_file()
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
with load_utils.load_from_file(temp_file.name):
pass
@ -186,14 +186,14 @@ class TestLoadUtils(test_base.MuranoTestCase):
def test_load_from_dir_without_source_directory(self):
expected_error_msg = 'Invalid package directory'
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
load_utils.load_from_dir('random_test_directory')
def test_load_from_dir_with_invalid_source_directory(self):
source_directory = self._create_temp_dir()
expected_error_msg = 'Unable to find package manifest'
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
load_utils.load_from_dir(source_directory)
@ -204,7 +204,7 @@ class TestLoadUtils(test_base.MuranoTestCase):
random_filename = ''.join(random.choice(string.ascii_lowercase)
for i in range(20))
expected_error_msg = 'Unable to load due to'
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_msg):
load_utils.load_from_dir(source_directory,
filename=random_filename)

View File

@ -56,7 +56,7 @@ class TestPackageBase(test_base.MuranoTestCase):
shutil.rmtree(cls.source_directory)
def test_create_package_base_without_full_name(self):
with self.assertRaisesRegexp(exceptions.PackageFormatError,
with self.assertRaisesRegex(exceptions.PackageFormatError,
'FullName is not specified'):
package_base.PackageBase('test_format',
'test_runtime_version',
@ -67,7 +67,7 @@ class TestPackageBase(test_base.MuranoTestCase):
full_names = ['.invalid_name_1', 'invalid..name..2', 'invalid name 3']
for full_name in full_names:
expected_error_message = 'Invalid FullName {0}'.format(full_name)
with self.assertRaisesRegexp(exceptions.PackageFormatError,
with self.assertRaisesRegex(exceptions.PackageFormatError,
expected_error_message):
package_base.PackageBase('test_format',
'test_runtime_version',
@ -76,7 +76,7 @@ class TestPackageBase(test_base.MuranoTestCase):
def test_create_package_base_with_invalid_type(self):
package_type = 'Invalid'
with self.assertRaisesRegexp(exceptions.PackageFormatError,
with self.assertRaisesRegex(exceptions.PackageFormatError,
'Invalid package Type {0}'
.format(package_type)):
package_base.PackageBase('test_format',
@ -86,19 +86,19 @@ class TestPackageBase(test_base.MuranoTestCase):
'Type': package_type})
def test_requirements_negative(self):
with self.assertRaisesRegexp(NotImplementedError, None):
with self.assertRaisesRegex(NotImplementedError, None):
self.package_base.requirements
def test_classes_negative(self):
with self.assertRaisesRegexp(NotImplementedError, None):
with self.assertRaisesRegex(NotImplementedError, None):
self.package_base.classes
def test_get_class_negative(self):
with self.assertRaisesRegexp(NotImplementedError, None):
with self.assertRaisesRegex(NotImplementedError, None):
self.package_base.get_class(None)
def test_ui_negative(self):
with self.assertRaisesRegexp(NotImplementedError, None):
with self.assertRaisesRegex(NotImplementedError, None):
self.package_base.ui
def test_full_name(self):
@ -144,7 +144,7 @@ class TestPackageBase(test_base.MuranoTestCase):
expected_error_message = 'Unable to load logo'
self.package_base._logo = ''.join(random.choice(string.ascii_letters)
for _ in range(10))
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_message):
self.package_base.logo
self.package_base._logo = self.mock_manifest['Logo']
@ -153,7 +153,7 @@ class TestPackageBase(test_base.MuranoTestCase):
what=mock.MagicMock(return_value='xyz'))
def test_load_image_with_invalid_extension(self, mock_imghdr):
expected_error_message = 'Unsupported Format.'
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_message):
self.package_base._load_image('logo.xyz', 'logo.xyz', 'logo')
full_path = os.path.join(self.package_base._source_directory,
@ -167,7 +167,7 @@ class TestPackageBase(test_base.MuranoTestCase):
mock_os.stat.return_value = mock.MagicMock(st_size=5000 * 1024)
mock_os.isfile = mock.MagicMock(return_value=True)
expected_error_message = 'Max allowed size is {0}'.format(500 * 1024)
with self.assertRaisesRegexp(exceptions.PackageLoadError,
with self.assertRaisesRegex(exceptions.PackageLoadError,
expected_error_message):
self.package_base._load_image('logo.xyz', 'logo.xyz', 'logo')

View File

@ -190,7 +190,7 @@ class TestActions(test_base.MuranoTestCase):
test_action_id = 'test_action_id'
test_session = mock.MagicMock(description=[])
with self.assertRaisesRegexp(LookupError, 'Action is not found'):
with self.assertRaisesRegex(LookupError, 'Action is not found'):
actions.ActionServices.execute(test_action_id, test_session,
None, None, None)
@ -210,7 +210,7 @@ class TestActions(test_base.MuranoTestCase):
}]
test_session = mock.MagicMock(description=test_description)
with self.assertRaisesRegexp(ValueError,
with self.assertRaisesRegex(ValueError,
'Cannot execute disabled action'):
actions.ActionServices.execute(test_action_id, test_session,
None, None, None)

View File

@ -694,7 +694,7 @@ class TestHeatStack(base.MuranoTestCase):
# Else EnvironmentError should be thrown.
expected_error_msg = "Unexpected stack state {0}"\
.format('NOT_FOUND')
with self.assertRaisesRegexp(EnvironmentError,
with self.assertRaisesRegex(EnvironmentError,
expected_error_msg):
hs._wait_state(lambda status: status == 'CREATE_COMPLETE')
@ -705,7 +705,7 @@ class TestHeatStack(base.MuranoTestCase):
hs = heat_stack.HeatStack('test-stack', None)
hs._client.stacks.get.side_effect = Exception('test_exception_msg')
with self.assertRaisesRegexp(Exception,
with self.assertRaisesRegex(Exception,
'test_exception_msg'):
hs._wait_state(lambda status: status == 'CREATE_COMPLETE')
@ -725,6 +725,6 @@ class TestHeatStack(base.MuranoTestCase):
expected_error_msg = "Unexpected stack state {0}: {1}"\
.format('UNEXPECTED_STATUS', 'test_reason')
with self.assertRaisesRegexp(EnvironmentError,
with self.assertRaisesRegex(EnvironmentError,
expected_error_msg):
hs._wait_state(lambda status: status == 'CREATE_COMPLETE')

View File

@ -45,7 +45,7 @@ class TestUtils(test_base.MuranoTestCase):
expected_error_message = 'Environment with id {env_id} not found'\
.format(env_id=test_env_id)
with self.assertRaisesRegexp(exc.HTTPNotFound,
with self.assertRaisesRegex(exc.HTTPNotFound,
expected_error_message):
utils.check_env(mock_request, test_env_id)
@ -60,7 +60,7 @@ class TestUtils(test_base.MuranoTestCase):
expected_error_message = 'User is not authorized to access these '\
'tenant resources'
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_message):
utils.check_env(mock_request, mock_env.environment_id)
@ -68,7 +68,7 @@ class TestUtils(test_base.MuranoTestCase):
"""Test check session with null session throws exception."""
expected_error_message = 'Session <SessionId {id}> is not found'\
.format(id=None)
with self.assertRaisesRegexp(exc.HTTPNotFound,
with self.assertRaisesRegex(exc.HTTPNotFound,
expected_error_message):
utils.check_session(None, None, None, None)
@ -82,7 +82,7 @@ class TestUtils(test_base.MuranoTestCase):
'with Environment <EnvId {environment_id}>'\
.format(session_id=mock_session.session_id,
environment_id=environment_id)
with self.assertRaisesRegexp(exc.HTTPBadRequest,
with self.assertRaisesRegex(exc.HTTPBadRequest,
expected_error_msg):
utils.check_session(None, environment_id, mock_session,
mock_session.session_id)
@ -95,7 +95,7 @@ class TestUtils(test_base.MuranoTestCase):
mock_request = mock.MagicMock(context=dummy_context)
expected_error_message = 'X-Configuration-Session header which '\
'indicates to the session is missed'
with self.assertRaisesRegexp(exc.HTTPBadRequest,
with self.assertRaisesRegex(exc.HTTPBadRequest,
expected_error_message):
self._test_verify_session(mock_request)
@ -108,7 +108,7 @@ class TestUtils(test_base.MuranoTestCase):
mock_db_session.get_session().query().get.return_value = None
expected_error_message = 'Session <SessionId {0}> is not found'\
.format(mock_request.context.session)
with self.assertRaisesRegexp(exc.HTTPNotFound,
with self.assertRaisesRegex(exc.HTTPNotFound,
expected_error_message):
self._test_verify_session(mock_request)
@ -123,7 +123,7 @@ class TestUtils(test_base.MuranoTestCase):
mock_env_template
expected_error_message = 'User is not authorized to access this'\
' tenant resources'
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_message):
self._test_verify_env_template(mock_request, None)
@ -133,7 +133,7 @@ class TestUtils(test_base.MuranoTestCase):
mock_db_session.get_session().query().get.return_value = None
expected_error_message = 'Environment Template with id {id} not found'\
.format(id='test_env_template_id')
with self.assertRaisesRegexp(exc.HTTPNotFound,
with self.assertRaisesRegex(exc.HTTPNotFound,
expected_error_message):
self._test_verify_env_template(None, 'test_env_template_id')
@ -157,7 +157,7 @@ class TestUtils(test_base.MuranoTestCase):
'environment has been updated or '\
'updating right now with other session'\
.format(mock_request.context.session)
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_message):
self._test_verify_session(mock_request)
@ -176,7 +176,7 @@ class TestUtils(test_base.MuranoTestCase):
expected_error_message = 'Session <SessionId {0}> is already in '\
'deployment state'\
.format(mock_request.context.session)
with self.assertRaisesRegexp(exc.HTTPForbidden,
with self.assertRaisesRegex(exc.HTTPForbidden,
expected_error_message):
self._test_verify_session(mock_request)