Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Misc.} Change deprecated assertRaisesRegexp to assertRaisesRegex #20374

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/azure-cli-core/azure/cli/core/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def test_get_login_credentials_aux_tenants(self, get_user_credential_mock):
self.assertEqual(aux_tokens[0].token, MOCK_ACCESS_TOKEN)

# test input aux_tenants and aux_subscriptions
with self.assertRaisesRegexp(CLIError,
with self.assertRaisesRegex(CLIError,
"Please specify only one of aux_subscriptions and aux_tenants, not both"):
cred, subscription_id, _ = profile.get_login_credentials(subscription_id=test_subscription_id1,
aux_subscriptions=[test_subscription_id2],
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def mi_auth_factory(*args, **kwargs):
self.assertEqual(tenant_id, test_tenant_id)

# verify tenant shouldn't be specified for MSI account
with self.assertRaisesRegexp(CLIError, "Tenant shouldn't be specified"):
with self.assertRaisesRegex(CLIError, "Tenant shouldn't be specified"):
cred, subscription_id, _ = profile.get_raw_token(resource='http://test_resource', tenant=self.tenant_id)

@mock.patch('azure.cli.core._profile.in_cloud_console', autospec=True)
Expand Down Expand Up @@ -1211,7 +1211,7 @@ def mi_auth_factory(*args, **kwargs):
self.assertEqual(tenant_id, test_tenant_id)

# verify tenant shouldn't be specified for Cloud Shell account
with self.assertRaisesRegexp(CLIError, 'Cloud Shell'):
with self.assertRaisesRegex(CLIError, 'Cloud Shell'):
cred, subscription_id, _ = profile.get_raw_token(resource='http://test_resource', tenant=self.tenant_id)

@mock.patch('azure.cli.core.auth.identity.Identity.logout_user')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_ams_account_filter_create_and_show(self, storage_account_for_create_and
self.kwargs.update({
'nonexits_filter_name': nonexits_filter_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams account-filter show -a {amsname} -g {rg} -n {nonexits_filter_name}')

@ResourceGroupPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_ams_asset_filter_show(self, storage_account_for_show):
self.kwargs.update({
'nonexits_asset_filter_name': nonexits_asset_filter_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams asset-filter show -a {amsname} --asset-name {asset_name} -g {rg} -n {nonexits_asset_filter_name}')

@ResourceGroupPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_ams_asset(self, storage_account_for_create, storage_account_for_asset):
'nonexits_asset_name': nonexits_asset_name
})

with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams asset show -a {amsname} -g {rg} -n {nonexits_asset_name}')

list = self.cmd('az ams asset list -a {amsname} -g {rg}').get_output_in_json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_ams_job(self, resource_group, storage_account_for_create):
self.kwargs.update({
'nonexits_job_name': nonexits_job_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams job show -a {amsname} -n{nonexits_job_name} -g {rg} -t {transformName}')

list = self.cmd('az ams job list -a {amsname} -g {rg} -t {transformName}').get_output_in_json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_live_event_show(self, storage_account_for_create):
self.kwargs.update({
'nonexits_live_event_name': nonexits_live_event_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams live-event show -a {amsname} -n {nonexits_live_event_name} -g {rg}')

self.cmd('az ams live-event delete -a {amsname} -n {liveEventName} -g {rg}')
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_live_output_show(self, storage_account_for_create):
self.kwargs.update({
'nonexits_live_output_name': nonexits_live_output_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams live-output show -a {amsname} -n {liveOutputName} -g {rg} --live-event-name {nonexits_live_output_name}')

@ResourceGroupPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_ams_streaming_endpoint_show(self, storage_account_for_show):
self.kwargs.update({
'nonexits_streaming_endpoint_name': nonexits_streaming_endpoint_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams streaming-endpoint show -g {rg} -a {amsname} -n {nonexits_streaming_endpoint_name}')

self.cmd('az ams streaming-endpoint delete -g {rg} -a {amsname} -n {streamingEndpointName}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_ams_streaming_locator(self, resource_group, storage_account_for_create)
self.kwargs.update({
'nonexits_streaming_locator_name': nonexits_streaming_locator_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams streaming-locator show -a {amsname} -n {nonexits_streaming_locator_name} -g {rg}')

list = self.cmd('az ams streaming-locator list -a {amsname} -g {rg}').get_output_in_json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_ams_transform(self, storage_account_for_create):
self.kwargs.update({
'nonexits_transform_name': nonexits_transform_name
})
with self.assertRaisesRegexp(SystemExit, '3'):
with self.assertRaisesRegex(SystemExit, '3'):
self.cmd('az ams transform show -a {amsname} -n {nonexits_transform_name} -g {rg}')

self.cmd('az ams transform update --description mydesc -a {amsname} -n {transformName} -g {rg}', checks=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,14 +874,14 @@ def test_azconfig_import_export_naming_conventions(self, resource_group, locatio
self.kwargs.update({
'imported_file_path': import_multiple_feature_sections_path
})
with self.assertRaisesRegexp(CLIError, 'Unable to proceed because file contains multiple sections corresponding to "Feature Management".'):
with self.assertRaisesRegex(CLIError, 'Unable to proceed because file contains multiple sections corresponding to "Feature Management".'):
self.cmd('appconfig kv import -n {config_store_name} -s {import_source} --path "{imported_file_path}" --format {imported_format} --label {label} -y')

# Error if imported file has "enabled for" in wrong format
self.kwargs.update({
'imported_file_path': import_wrong_enabledfor_format_path
})
with self.assertRaisesRegexp(CLIError, 'definition or have a true/false value.'):
with self.assertRaisesRegex(CLIError, 'definition or have a true/false value.'):
self.cmd('appconfig kv import -n {config_store_name} -s {import_source} --path "{imported_file_path}" --format {imported_format} --label {label} -y')

# Import/Export yaml file
Expand Down Expand Up @@ -1074,7 +1074,7 @@ def test_appconfig_to_appconfig_import_export(self, resource_group, location):
self.kwargs.update({
'label': dest_label
})
with self.assertRaisesRegexp(CLIError, "Import failed! Please provide only one of these arguments: '--label' or '--preserve-labels'."):
with self.assertRaisesRegex(CLIError, "Import failed! Please provide only one of these arguments: '--label' or '--preserve-labels'."):
self.cmd('appconfig kv import --connection-string {dest_connection_string} -s {import_source} --src-connection-string {src_connection_string} --src-label {src_label} --label {label} --preserve-labels -y')

# Export tests from src config store to dest config store
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def test_appconfig_to_appconfig_import_export(self, resource_group, location):
self.kwargs.update({
'label': dest_label
})
with self.assertRaisesRegexp(CLIError, "Export failed! Please provide only one of these arguments: '--dest-label' or '--preserve-labels'."):
with self.assertRaisesRegex(CLIError, "Export failed! Please provide only one of these arguments: '--dest-label' or '--preserve-labels'."):
self.cmd('appconfig kv export --connection-string {src_connection_string} -d {import_source} --dest-connection-string {dest_connection_string} --label {src_label} --dest-label {label} --preserve-labels -y')


Expand Down Expand Up @@ -1352,19 +1352,19 @@ def test_azconfig_json_content_type(self, resource_group, location):
'value': entry_value,
'content_type': json_content_type_01
})
with self.assertRaisesRegexp(CLIError, "is not a valid JSON object, which conflicts with the content type."):
with self.assertRaisesRegex(CLIError, "is not a valid JSON object, which conflicts with the content type."):
self.cmd('appconfig kv set --connection-string {src_connection_string} --key {key} --value {value} --content-type {content_type} -y')

self.kwargs.update({
'value': '[abc,def]'
})
with self.assertRaisesRegexp(CLIError, "is not a valid JSON object, which conflicts with the content type."):
with self.assertRaisesRegex(CLIError, "is not a valid JSON object, which conflicts with the content type."):
self.cmd('appconfig kv set --connection-string {src_connection_string} --key {key} --value {value} --content-type {content_type} -y')

self.kwargs.update({
'value': 'True'
})
with self.assertRaisesRegexp(CLIError, "is not a valid JSON object, which conflicts with the content type."):
with self.assertRaisesRegex(CLIError, "is not a valid JSON object, which conflicts with the content type."):
self.cmd('appconfig kv set --connection-string {src_connection_string} --key {key} --value {value} --content-type {content_type} -y')

# Create a non-JSON key-value and update its content type in subsequent command
Expand All @@ -1375,7 +1375,7 @@ def test_azconfig_json_content_type(self, resource_group, location):
checks=[self.check('key', entry_key),
self.check('value', entry_value)])

with self.assertRaisesRegexp(CLIError, "Set the value again in valid JSON format."):
with self.assertRaisesRegex(CLIError, "Set the value again in valid JSON format."):
self.cmd('appconfig kv set --connection-string {src_connection_string} --key {key} --content-type {content_type} -y')

"""
Expand Down Expand Up @@ -1538,7 +1538,7 @@ def test_azconfig_json_content_type(self, resource_group, location):
'imported_file_path': imported_file_path,
'exported_file_path': exported_yaml_file_path
})
with self.assertRaisesRegexp(CLIError, "Please provide JSON file format to match your content type."):
with self.assertRaisesRegex(CLIError, "Please provide JSON file format to match your content type."):
self.cmd('appconfig kv import --connection-string {src_connection_string} -s {import_source} --path "{imported_file_path}" --format {imported_format} --separator {separator} --content-type {content_type} -y')

self.cmd(
Expand Down Expand Up @@ -1770,7 +1770,7 @@ def test_azconfig_feature(self, resource_group, location):
'feature': comma_pattern
})

with self.assertRaisesRegexp(CLIError, "Comma separated feature names are not supported"):
with self.assertRaisesRegex(CLIError, "Comma separated feature names are not supported"):
self.cmd('appconfig feature list -n {config_store_name} --feature {feature}')

# Invalid Pattern - contains invalid *
Expand All @@ -1779,7 +1779,7 @@ def test_azconfig_feature(self, resource_group, location):
'feature': invalid_pattern
})

with self.assertRaisesRegexp(CLIError, "Bad Request"):
with self.assertRaisesRegex(CLIError, "Bad Request"):
self.cmd('appconfig feature list -n {config_store_name} --feature {feature}')

# Invalid Pattern - starts with *
Expand All @@ -1788,7 +1788,7 @@ def test_azconfig_feature(self, resource_group, location):
'feature': invalid_pattern
})

with self.assertRaisesRegexp(CLIError, "Bad Request"):
with self.assertRaisesRegex(CLIError, "Bad Request"):
self.cmd('appconfig feature list -n {config_store_name} --feature {feature}')

# Invalid Pattern - contains multiple **
Expand All @@ -1797,7 +1797,7 @@ def test_azconfig_feature(self, resource_group, location):
'feature': invalid_pattern
})

with self.assertRaisesRegexp(CLIError, "Bad Request"):
with self.assertRaisesRegex(CLIError, "Bad Request"):
self.cmd('appconfig feature list -n {config_store_name} --feature {feature}')

# Delete Beta (label v2) feature flag using connection-string
Expand Down Expand Up @@ -1944,11 +1944,11 @@ def test_azconfig_feature_namespacing(self, resource_group, location):
'key': invalid_key
})

with self.assertRaisesRegexp(CLIError, "Feature flag key must start with the reserved prefix"):
with self.assertRaisesRegex(CLIError, "Feature flag key must start with the reserved prefix"):
self.cmd('appconfig feature set -n {config_store_name} --key {key}')

# Missing key and feature
with self.assertRaisesRegexp(CLIError, "Please provide either `--key` or `--feature` value."):
with self.assertRaisesRegex(CLIError, "Please provide either `--key` or `--feature` value."):
self.cmd('appconfig feature delete -n {config_store_name}')


Expand Down Expand Up @@ -2082,7 +2082,7 @@ def test_azconfig_feature_filter(self, resource_group, location):
self.check('state', conditional_state)])

# Delete Filter without index should throw error when duplicates exist
with self.assertRaisesRegexp(CLIError, "contains multiple instances of filter"):
with self.assertRaisesRegex(CLIError, "contains multiple instances of filter"):
self.cmd('appconfig feature filter delete -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} -y')

# Delete Filter with index succeeds when correct index is provided
Expand All @@ -2109,23 +2109,23 @@ def test_azconfig_feature_filter(self, resource_group, location):
'filter_name': invalid_filter_name,
'filter_parameters': invalid_filter_params
})
with self.assertRaisesRegexp(CLIError, "Filter parameter value must be a JSON escaped string"):
with self.assertRaisesRegex(CLIError, "Filter parameter value must be a JSON escaped string"):
self.cmd('appconfig feature filter add -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --filter-parameters {filter_parameters} -y')

# Error on adding duplicate filter parameters
invalid_filter_params = 'Name1=10 Name1=20'
self.kwargs.update({
'filter_parameters': invalid_filter_params
})
with self.assertRaisesRegexp(CLIError, 'Filter parameter name "Name1" cannot be duplicated.'):
with self.assertRaisesRegex(CLIError, 'Filter parameter name "Name1" cannot be duplicated.'):
self.cmd('appconfig feature filter add -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --filter-parameters {filter_parameters} -y')

# Error on filter parameter with empty name
invalid_filter_params = '=value'
self.kwargs.update({
'filter_parameters': invalid_filter_params
})
with self.assertRaisesRegexp(CLIError, 'Parameter name cannot be empty.'):
with self.assertRaisesRegex(CLIError, 'Parameter name cannot be empty.'):
self.cmd('appconfig feature filter add -n {config_store_name} --feature {feature} --label {label} --filter-name {filter_name} --filter-parameters {filter_parameters} -y')

# Test more inputs for filter param value
Expand Down Expand Up @@ -2199,40 +2199,40 @@ def test_azconfig_key_validation(self, resource_group, location):
'key': "Col%%or",
'value': "Red"
})
with self.assertRaisesRegexp(CLIError, "Key is invalid. Key cannot be a '.' or '..', or contain the '%' character."):
with self.assertRaisesRegex(CLIError, "Key is invalid. Key cannot be a '.' or '..', or contain the '%' character."):
self.cmd('appconfig kv set --connection-string {connection_string} --key {key} --value {value} -y')

self.kwargs.update({
'key': ""
})
with self.assertRaisesRegexp(CLIError, "Key cannot be empty."):
with self.assertRaisesRegex(CLIError, "Key cannot be empty."):
self.cmd('appconfig kv set --connection-string {connection_string} --key "{key}" --value {value} -y')

self.kwargs.update({
'key': "."
})
with self.assertRaisesRegexp(CLIError, "Key is invalid. Key cannot be a '.' or '..', or contain the '%' character."):
with self.assertRaisesRegex(CLIError, "Key is invalid. Key cannot be a '.' or '..', or contain the '%' character."):
self.cmd('appconfig kv set --connection-string {connection_string} --key {key} --value {value} -y')

# validate key for KeyVault ref
self.kwargs.update({
'key': "%KeyVault",
'secret_identifier': "https://fake.vault.azure.net/secrets/fakesecret"
})
with self.assertRaisesRegexp(CLIError, "Key is invalid. Key cannot be a '.' or '..', or contain the '%' character."):
with self.assertRaisesRegex(CLIError, "Key is invalid. Key cannot be a '.' or '..', or contain the '%' character."):
self.cmd('appconfig kv set-keyvault --connection-string {connection_string} --key {key} --secret-identifier {secret_identifier} -y')

# validate feature name
self.kwargs.update({
'feature': 'Beta%'
})
with self.assertRaisesRegexp(CLIError, "Feature name cannot contain the '%' character."):
with self.assertRaisesRegex(CLIError, "Feature name cannot contain the '%' character."):
self.cmd('appconfig feature set --connection-string {connection_string} --feature {feature} -y')

self.kwargs.update({
'feature': ''
})
with self.assertRaisesRegexp(CLIError, "Feature name cannot be empty."):
with self.assertRaisesRegex(CLIError, "Feature name cannot be empty."):
self.cmd('appconfig feature set --connection-string {connection_string} --feature "{feature}" -y')

# validate keys and features during file import
Expand Down
Loading