Skip to content

Commit

Permalink
Fix for DeprecationWarning: Please use assertRaisesRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
nzlosh committed Mar 12, 2024
1 parent 071c2b0 commit a1d35a7
Show file tree
Hide file tree
Showing 49 changed files with 147 additions and 147 deletions.
18 changes: 9 additions & 9 deletions contrib/packs/tests/test_action_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def mock_acquire(self, timeout=None):
fp.write("")

expected_msg = "Timeout waiting to acquire lock for"
self.assertRaisesRegexp(
self.assertRaisesRegex(
LockTimeout,
expected_msg,
action.run,
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_run_pack_download_invalid_version(self):
"is not a valid version, hash, tag or branch.*?"
"Available versions are: 1.0.0, 2.0.0."
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -351,7 +351,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "2.2.0"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -364,7 +364,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "2.3.0"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -377,7 +377,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "1.5.9"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -390,7 +390,7 @@ def test_download_pack_stackstorm_version_identifier_check(self):
'Pack "test3" requires StackStorm ">=1.6.0, <2.2.0", but '
'current version is "1.5.0"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand Down Expand Up @@ -470,7 +470,7 @@ def test_download_pack_python_version_check(self):
r'Pack "test3" requires Python 2.x, but current Python version is '
'"3.5.2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand All @@ -497,7 +497,7 @@ def test_download_pack_python_version_check(self):
r'Pack "test3" requires Python 3.x, but current Python version is '
'"2.7.2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand Down Expand Up @@ -657,7 +657,7 @@ def test_run_pack_download_local_directory(self):

# 1. Local directory doesn't exist
expected_msg = r'Local pack directory ".*" doesn\'t exist'
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
action.run,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def test_chain_runner_bad_default(self, request):
expected_msg = (
'Unable to find node with name "bad_default" referenced in "default".'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand Down Expand Up @@ -434,7 +434,7 @@ def test_chain_runner_broken_on_success_path_static_task_name(self, request):
'Unable to find node with name "c5" referenced in "on-success" '
'in task "c2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand All @@ -453,7 +453,7 @@ def test_chain_runner_broken_on_failure_path_static_task_name(self, request):
'Unable to find node with name "c6" referenced in "on-failure" '
'in task "c2"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand Down Expand Up @@ -896,7 +896,7 @@ def test_chain_task_passes_invalid_parameter_type_to_action(self, mock_request):
r'Failed to cast value "stringnotanarray" \(type: str\) for parameter '
r'"arrtype" of type "array"'
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
chain_runner.run,
Expand Down Expand Up @@ -944,7 +944,7 @@ def test_exception_is_thrown_if_both_params_and_parameters_attributes_are_provid
'Either "params" or "parameters" attribute needs to be provided, but '
"not both"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_announcement_no_experimental(self, dispatch):
runner.liveaction = mock.Mock(context={})

expected_msg = "Experimental flag is missing for action some.thing"
self.assertRaisesRegexp(Exception, expected_msg, runner.pre_run)
self.assertRaisesRegex(Exception, expected_msg, runner.pre_run)

@mock.patch("st2common.models.api.trace.TraceContext.__new__")
def test_announcement_with_trace(self, context, dispatch):
Expand Down
8 changes: 4 additions & 4 deletions contrib/runners/http_runner/tests/unit/test_http_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_blacklisted_url_url_hosts_blacklist_runner_parameter(self, mock_request
client = HTTPClient(
url=url, method="GET", url_hosts_blacklist=url_hosts_blacklist
)
self.assertRaisesRegexp(ValueError, expected_msg, client.run)
self.assertRaisesRegex(ValueError, expected_msg, client.run)

# Non blacklisted URLs
urls = ["https://example2.com", "http://example3.com", "http://example4.com:81"]
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_whitelisted_url_url_hosts_whitelist_runner_parameter(self, mock_request
client = HTTPClient(
url=url, method="GET", url_hosts_whitelist=url_hosts_whitelist
)
self.assertRaisesRegexp(ValueError, expected_msg, client.run)
self.assertRaisesRegex(ValueError, expected_msg, client.run)

# Whitelisted URLS
urls = [
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_url_host_blacklist_and_url_host_blacklist_params_are_mutually_exclusive
r'"url_hosts_blacklist" and "url_hosts_whitelist" parameters are mutually '
"exclusive."
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
expected_msg,
HTTPClient,
Expand Down Expand Up @@ -423,4 +423,4 @@ def test_url_host_blacklist_and_url_host_blacklist_params_are_mutually_exclusive
r'"url_hosts_blacklist" and "url_hosts_whitelist" parameters are mutually '
"exclusive."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.run, {})
self.assertRaisesRegex(ValueError, expected_msg, runner.run, {})
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_key_exists(self):
self.assertIsNone(st2kv.st2kv_(MOCK_CTX, "foo_null"))

def test_key_does_not_exist(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
'The key ".*" does not exist in the StackStorm datastore.',
st2kv.st2kv_,
Expand All @@ -120,7 +120,7 @@ def test_key_decrypt(self):
kvp_util, "get_key", mock.MagicMock(side_effect=Exception("Mock failure."))
)
def test_get_key_exception(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
"Mock failure.",
st2kv.st2kv_,
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_key_exists(self):
self.assertIsNone(st2kv.st2kv_(MOCK_CTX, "system.foo_null"))

def test_key_does_not_exist(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
'The key ".*" does not exist in the StackStorm datastore.',
st2kv.st2kv_,
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_key_decrypt(self):
kvp_util, "get_key", mock.MagicMock(side_effect=Exception("Mock failure."))
)
def test_get_key_exception(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
exc.ExpressionEvaluationException,
"Mock failure.",
st2kv.st2kv_,
Expand Down
16 changes: 8 additions & 8 deletions contrib/runners/python_runner/tests/unit/test_pythonrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_simple_action_no_entry_point(self):
runner.entry_point = ""

expected_msg = "Action .*? is missing entry_point attribute"
self.assertRaisesRegexp(Exception, expected_msg, runner.run, {})
self.assertRaisesRegex(Exception, expected_msg, runner.run, {})

@mock.patch("st2common.util.concurrency.subprocess_popen")
def test_action_with_user_supplied_env_vars(self, mock_popen):
Expand Down Expand Up @@ -720,7 +720,7 @@ def test_python_action_wrapper_action_script_file_doesnt_exist_friendly_error(se
expected_msg = (
'File "/tmp/doesnt.exist" has no action class or the file doesn\'t exist.'
)
self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance)
self.assertRaisesRegex(Exception, expected_msg, wrapper._get_action_instance)

# File in a directory which is a Python package
wrapper = PythonActionWrapper(
Expand All @@ -732,7 +732,7 @@ def test_python_action_wrapper_action_script_file_doesnt_exist_friendly_error(se
r"\(action file most likely doesn\'t exist or contains invalid syntax\): "
r"\[Errno 2\] No such file or directory"
)
self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance)
self.assertRaisesRegex(Exception, expected_msg, wrapper._get_action_instance)

def test_python_action_wrapper_action_script_file_contains_invalid_syntax_friendly_error(
self,
Expand All @@ -745,7 +745,7 @@ def test_python_action_wrapper_action_script_file_contains_invalid_syntax_friend
r"\(action file most likely doesn\'t exist or contains invalid syntax\): "
r"No module named \'?invalid\'?"
)
self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance)
self.assertRaisesRegex(Exception, expected_msg, wrapper._get_action_instance)

def test_simple_action_log_messages_and_log_level_runner_param(self):
expected_msg_1 = (
Expand Down Expand Up @@ -927,7 +927,7 @@ def test_content_version_success(self, mock_get_sandbox_virtualenv_path):
'"v0.30.0" provided. Make sure that git repository is up '
"to date and contains that revision."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

@mock.patch("python_runner.python_runner.get_sandbox_virtualenv_path")
@mock.patch("st2common.util.concurrency.subprocess_popen")
Expand Down Expand Up @@ -998,7 +998,7 @@ def test_content_version_old_git_version(self, mock_run_command):
"doesn't support git worktree command. To be able to utilize this "
"functionality you need to use git >= 2.5.0."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

@mock.patch("st2common.runners.base.run_command")
def test_content_version_pack_repo_not_git_repository(self, mock_run_command):
Expand All @@ -1020,7 +1020,7 @@ def test_content_version_pack_repo_not_git_repository(self, mock_run_command):
"git repository. To utilize this functionality, pack directory needs to "
"be a git repository."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

@mock.patch("st2common.runners.base.run_command")
def test_content_version_invalid_git_revision(self, mock_run_command):
Expand All @@ -1040,7 +1040,7 @@ def test_content_version_invalid_git_revision(self, mock_run_command):
'"vinvalid" provided. Make sure that git repository is up '
"to date and contains that revision."
)
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

def test_missing_config_item_user_friendly_error(self):
runner = self._get_mock_runner_obj()
Expand Down
4 changes: 2 additions & 2 deletions st2actions/tests/unit/test_actions_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_register_action_invalid_parameter_type_attribute(self):
# "'list' is not valid under any of the given schemas"
# with jsonschema 3.2.0, the underlying enum (anyOf->enum) gets reported instead:
expected_msg = r"'list' is not one of \['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'\].*"
self.assertRaisesRegexp(
self.assertRaisesRegex(
jsonschema.ValidationError,
expected_msg,
registrar._register_action,
Expand All @@ -161,7 +161,7 @@ def test_register_action_invalid_parameter_name(self):
'Parameter name "action-name" is invalid. Valid characters for '
"parameter name are"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
jsonschema.ValidationError,
expected_msg,
registrar._register_action,
Expand Down
12 changes: 6 additions & 6 deletions st2actions/tests/unit/test_paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_key_files_and_key_material_arguments_are_mutual_exclusive(self):

client = ParamikoSSHClient(**conn_params)

self.assertRaisesRegexp(ValueError, expected_msg, client.connect)
self.assertRaisesRegex(ValueError, expected_msg, client.connect)

@patch("paramiko.SSHClient", Mock)
@patch.object(
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_key_material_argument_invalid_key(self):
mock = ParamikoSSHClient(**conn_params)

expected_msg = "Invalid or unsupported key type"
self.assertRaisesRegexp(
self.assertRaisesRegex(
paramiko.ssh_exception.SSHException, expected_msg, mock.connect
)

Expand All @@ -247,7 +247,7 @@ def test_passphrase_no_key_provided(self):

expected_msg = "passphrase should accompany private key material"
client = ParamikoSSHClient(**conn_params)
self.assertRaisesRegexp(ValueError, expected_msg, client.connect)
self.assertRaisesRegex(ValueError, expected_msg, client.connect)

@patch("paramiko.SSHClient", Mock)
def test_passphrase_not_provided_for_encrypted_key_file(self):
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_passphrase_and_no_key(self):
expected_msg = "passphrase should accompany private key material"
client = ParamikoSSHClient(**conn_params)

self.assertRaisesRegexp(ValueError, expected_msg, client.connect)
self.assertRaisesRegex(ValueError, expected_msg, client.connect)

@patch("paramiko.SSHClient", Mock)
@patch.object(
Expand All @@ -351,7 +351,7 @@ def test_incorrect_passphrase(self):
mock = ParamikoSSHClient(**conn_params)

expected_msg = "Invalid passphrase or invalid/unsupported key type"
self.assertRaisesRegexp(
self.assertRaisesRegex(
paramiko.ssh_exception.SSHException, expected_msg, mock.connect
)

Expand All @@ -375,7 +375,7 @@ def test_key_material_contains_path_not_contents(self):
conn_params["key_material"] = key_material
mock = ParamikoSSHClient(**conn_params)

self.assertRaisesRegexp(
self.assertRaisesRegex(
paramiko.ssh_exception.SSHException, expected_msg, mock.connect
)

Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/test_runner_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_pre_run_runner_is_disabled(self):
runner.runner_type.enabled = False

expected_msg = 'Runner "test-runner-1" has been disabled by the administrator'
self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
self.assertRaisesRegex(ValueError, expected_msg, runner.pre_run)

def test_created_temporary_auth_token_is_correctly_scoped_to_user_who_ran_the_action(
self,
Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/test_workflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_process_error_handling_has_error(self, mock_get_lock):
coordination.ToozConnectionError("foobar"),
coordination.ToozConnectionError("foobar"),
]
self.assertRaisesRegexp(
self.assertRaisesRegex(
Exception, "Unexpected error.", workflows.get_engine().process, t1_ac_ex_db
)

Expand Down
2 changes: 1 addition & 1 deletion st2api/tests/unit/controllers/v1/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ def test_router_invalid_url_path_friendly_error(self):
request = Request(environ={"PATH_INFO": "/v1/rules/好的".encode("utf-8")})

expected_msg = "URL likely contains invalid or incorrectly URL encoded values"
self.assertRaisesRegexp(
self.assertRaisesRegex(
webob.exc.HTTPBadRequest, expected_msg, router.match, request
)
Loading

0 comments on commit a1d35a7

Please sign in to comment.