Avoid deprecated TestCase functions in unit tests. (#76678)

* Avoid deprecated TestCase functions in unit tests.
* Add assertRaisesRegex for Python 2.7.
* Fix indentation.
pull/76679/head
Matt Clay 3 years ago committed by GitHub
parent ace04087e7
commit 97104f1221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,7 +70,7 @@ class TestVaultCli(unittest.TestCase):
mock_setup_vault_secrets.return_value = []
cli = VaultCLI(args=['ansible-vault', 'view', '/dev/null/foo'])
cli.parse()
self.assertRaisesRegexp(errors.AnsibleOptionsError,
self.assertRaisesRegex(errors.AnsibleOptionsError,
"A vault password is required to use Ansible's Vault",
cli.run)
@ -79,7 +79,7 @@ class TestVaultCli(unittest.TestCase):
mock_setup_vault_secrets.return_value = []
cli = VaultCLI(args=['ansible-vault', 'encrypt', '/dev/null/foo'])
cli.parse()
self.assertRaisesRegexp(errors.AnsibleOptionsError,
self.assertRaisesRegex(errors.AnsibleOptionsError,
"A vault password is required to use Ansible's Vault",
cli.run)

@ -36,3 +36,7 @@ if sys.version_info < (2, 7):
print('You need unittest2 installed on python2.6.x to run tests')
else:
from unittest import *
if not hasattr(TestCase, 'assertRaisesRegex'):
# added in Python 3.2
TestCase.assertRaisesRegex = TestCase.assertRaisesRegexp

@ -265,7 +265,7 @@ class TestGetCollectorNames(unittest.TestCase):
valid_subsets = frozenset(['my_fact', 'something_else'])
minimal_gather_subset = frozenset(['my_fact'])
self.assertRaisesRegexp(TypeError,
self.assertRaisesRegex(TypeError,
r'Bad subset .* given to Ansible.*allowed\:.*all,.*my_fact.*',
collector.get_collector_names,
valid_subsets=valid_subsets,
@ -349,7 +349,7 @@ class TestResolveRequires(unittest.TestCase):
all_fact_subsets = {'env': [default_collectors.EnvFactCollector],
'network': [default_collectors.LinuxNetworkCollector],
'virtual': [default_collectors.LinuxVirtualCollector]}
self.assertRaisesRegexp(collector.UnresolvedFactDep,
self.assertRaisesRegex(collector.UnresolvedFactDep,
'unresolved fact dep.*required_thing2',
collector.resolve_requires,
unresolved, all_fact_subsets)
@ -556,7 +556,7 @@ class TestCollectorClassesFromGatherSubset(unittest.TestCase):
def test_unknown_collector(self):
# something claims 'unknown_collector' is a valid gather_subset, but there is
# no FactCollector mapped to 'unknown_collector'
self.assertRaisesRegexp(TypeError,
self.assertRaisesRegex(TypeError,
r'Bad subset.*unknown_collector.*given to Ansible.*allowed\:.*all,.*env.*',
self._classes,
all_collector_classes=default_collectors.collectors,

@ -138,7 +138,7 @@ class TestDataLoader(unittest.TestCase):
self.assertTrue(self._loader.is_directory(os.path.dirname(__file__)))
def test_get_file_contents_none_path(self):
self.assertRaisesRegexp(AnsibleParserError, 'Invalid filename',
self.assertRaisesRegex(AnsibleParserError, 'Invalid filename',
self._loader._get_file_contents, None)
def test_get_file_contents_non_existent_path(self):
@ -169,7 +169,7 @@ class TestPathDwimRelativeStackDataLoader(unittest.TestCase):
self._loader = DataLoader()
def test_none(self):
self.assertRaisesRegexp(AnsibleFileNotFound, 'on the Ansible Controller', self._loader.path_dwim_relative_stack, None, None, None)
self.assertRaisesRegex(AnsibleFileNotFound, 'on the Ansible Controller', self._loader.path_dwim_relative_stack, None, None, None)
def test_empty_strings(self):
self.assertEqual(self._loader.path_dwim_relative_stack('', '', ''), './')
@ -218,7 +218,7 @@ class TestDataLoaderWithVault(unittest.TestCase):
self.assertRaises(AnsibleVaultError, self._loader.get_real_file, self.test_vault_data_path)
def test_get_real_file_not_a_path(self):
self.assertRaisesRegexp(AnsibleParserError, 'Invalid filename', self._loader.get_real_file, None)
self.assertRaisesRegex(AnsibleParserError, 'Invalid filename', self._loader.get_real_file, None)
@patch.multiple(DataLoader, path_exists=lambda s, x: True, is_file=lambda s, x: True)
def test_parse_from_vault_1_1_file(self):

@ -51,7 +51,7 @@ class TestUnhexlify(unittest.TestCase):
def test_odd_length(self):
b_data = b'123456789abcdefghijklmnopqrstuvwxyz'
self.assertRaisesRegexp(vault.AnsibleVaultFormatError,
self.assertRaisesRegex(vault.AnsibleVaultFormatError,
'.*Vault format unhexlify error.*',
vault._unhexlify,
b_data)
@ -59,7 +59,7 @@ class TestUnhexlify(unittest.TestCase):
def test_nonhex(self):
b_data = b'6z36316566653264333665333637623064303639353237620a636366633565663263336335656532'
self.assertRaisesRegexp(vault.AnsibleVaultFormatError,
self.assertRaisesRegex(vault.AnsibleVaultFormatError,
'.*Vault format unhexlify error.*Non-hexadecimal digit found',
vault._unhexlify,
b_data)
@ -91,7 +91,7 @@ class TestParseVaulttext(unittest.TestCase):
b_vaulttext_envelope = to_bytes(vaulttext_envelope, errors='strict', encoding='utf-8')
b_vaulttext, b_version, cipher_name, vault_id = vault.parse_vaulttext_envelope(b_vaulttext_envelope)
self.assertRaisesRegexp(vault.AnsibleVaultFormatError,
self.assertRaisesRegex(vault.AnsibleVaultFormatError,
'.*Vault format unhexlify error.*Non-hexadecimal digit found',
vault.parse_vaulttext,
b_vaulttext_envelope)
@ -133,7 +133,7 @@ class TestPromptVaultSecret(unittest.TestCase):
@patch('ansible.parsing.vault.display.prompt', side_effect=EOFError)
def test_prompt_eoferror(self, mock_display_prompt):
secret = vault.PromptVaultSecret(vault_id='test_id')
self.assertRaisesRegexp(vault.AnsibleVaultError,
self.assertRaisesRegex(vault.AnsibleVaultError,
'EOFError.*test_id',
secret.load)
@ -142,7 +142,7 @@ class TestPromptVaultSecret(unittest.TestCase):
secret = vault.PromptVaultSecret(vault_id='test_id',
prompt_formats=['Vault password: ',
'Confirm Vault password: '])
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'Passwords do not match',
secret.load)
@ -200,7 +200,7 @@ class TestFileVaultSecret(unittest.TestCase):
fake_loader = DictDataLoader({tmp_file.name: ''})
secret = vault.FileVaultSecret(loader=fake_loader, filename=tmp_file.name)
self.assertRaisesRegexp(vault.AnsibleVaultPasswordError,
self.assertRaisesRegex(vault.AnsibleVaultPasswordError,
'Invalid vault password was provided from file.*%s' % tmp_file.name,
secret.load)
@ -241,7 +241,7 @@ class TestFileVaultSecret(unittest.TestCase):
fake_loader = DictDataLoader({filename: 'sdfadf'})
secret = vault.FileVaultSecret(loader=fake_loader, filename=filename)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'.*Could not read vault password file.*/dev/null/foobar.*Not a directory',
secret.load)
@ -253,7 +253,7 @@ class TestFileVaultSecret(unittest.TestCase):
fake_loader = DictDataLoader({filename: 'sdfadf'})
secret = vault.FileVaultSecret(loader=fake_loader, filename=filename)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'.*Could not read vault password file.*%s.*' % filename,
secret.load)
@ -285,7 +285,7 @@ class TestScriptVaultSecret(unittest.TestCase):
secret = vault.ScriptVaultSecret()
with patch.object(secret, 'loader') as mock_loader:
mock_loader.is_executable = MagicMock(return_value=True)
self.assertRaisesRegexp(vault.AnsibleVaultPasswordError,
self.assertRaisesRegex(vault.AnsibleVaultPasswordError,
'Invalid vault password was provided from script',
secret.load)
@ -296,7 +296,7 @@ class TestScriptVaultSecret(unittest.TestCase):
secret = vault.ScriptVaultSecret()
with patch.object(secret, 'loader') as mock_loader:
mock_loader.is_executable = MagicMock(return_value=True)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'Problem running vault password script.*',
secret.load)
@ -306,7 +306,7 @@ class TestScriptVaultSecret(unittest.TestCase):
secret = vault.ScriptVaultSecret()
with patch.object(secret, 'loader') as mock_loader:
mock_loader.is_executable = MagicMock(return_value=False)
self.assertRaisesRegexp(vault.AnsibleVaultError,
self.assertRaisesRegex(vault.AnsibleVaultError,
'The vault password script .* was not executable',
secret.load)
@ -319,7 +319,7 @@ class TestScriptVaultSecret(unittest.TestCase):
secret = vault.ScriptVaultSecret(filename='/dev/null/some_vault_secret')
with patch.object(secret, 'loader') as mock_loader:
mock_loader.is_executable = MagicMock(return_value=True)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
r'Vault password script.*returned non-zero \(%s\): %s' % (rc, stderr),
secret.load)
@ -382,7 +382,7 @@ class TestGetFileVaultSecret(unittest.TestCase):
filename = '/dev/null/foobar'
fake_loader = DictDataLoader({filename: 'sdfadf'})
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'.*The vault password file %s was not found.*' % filename,
vault.get_file_vault_secret,
filename=filename,
@ -395,7 +395,7 @@ class TestGetFileVaultSecret(unittest.TestCase):
fake_loader = DictDataLoader({filename: 'sdfadf'})
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'.*The vault password file %s was not found.*' % filename,
vault.get_file_vault_secret,
filename=filename,
@ -645,7 +645,7 @@ class TestVaultLib(unittest.TestCase):
v = vault.VaultLib(vault_secrets)
plaintext = u'Some text to encrypt in a café'
self.assertRaisesRegexp(vault.AnsibleVaultError,
self.assertRaisesRegex(vault.AnsibleVaultError,
'.*A vault password must be specified to encrypt data.*',
v.encrypt,
plaintext)
@ -712,7 +712,7 @@ class TestVaultLib(unittest.TestCase):
v_none = vault.VaultLib(None)
# so set secrets None explicitly
v_none.secrets = None
self.assertRaisesRegexp(vault.AnsibleVaultError,
self.assertRaisesRegex(vault.AnsibleVaultError,
'.*A vault password must be specified to decrypt data.*',
v_none.decrypt,
b_vaulttext)
@ -727,7 +727,7 @@ class TestVaultLib(unittest.TestCase):
vault_secrets_empty = []
v_none = vault.VaultLib(vault_secrets_empty)
self.assertRaisesRegexp(vault.AnsibleVaultError,
self.assertRaisesRegex(vault.AnsibleVaultError,
'.*Attempting to decrypt but no vault secrets found.*',
v_none.decrypt,
b_vaulttext)
@ -740,7 +740,7 @@ class TestVaultLib(unittest.TestCase):
('wrong-password', TextVaultSecret('wrong-password'))]
v_multi = vault.VaultLib(vault_secrets)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'.*Decryption failed.*',
v_multi.decrypt,
b_vaulttext,

@ -142,7 +142,7 @@ class TestVaultEditor(unittest.TestCase):
ve = self._vault_editor()
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
error_txt,
ve._edit_file_helper,
src_file_path,
@ -249,7 +249,7 @@ class TestVaultEditor(unittest.TestCase):
ve = self._vault_editor()
ve.encrypt_file(src_file_path, self.vault_secret)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'The value for the new_password to rekey',
ve.rekey_file,
src_file_path,
@ -264,7 +264,7 @@ class TestVaultEditor(unittest.TestCase):
ve = self._vault_editor()
new_password = 'password2:electricbugaloo'
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'input is not vault encrypted data',
ve.rekey_file,
src_file_path, new_password)
@ -288,7 +288,7 @@ class TestVaultEditor(unittest.TestCase):
src_file_path = self._create_file(self._test_dir, 'src_file', content=src_file_contents)
ve = self._vault_editor()
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'input is not vault encrypted data',
ve.plaintext,
src_file_path)
@ -426,7 +426,7 @@ class TestVaultEditor(unittest.TestCase):
mock_sp_call.side_effect = faux_editor
ve = self._vault_editor()
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'input is not vault encrypted data',
ve.edit_file,
src_file_path)
@ -437,7 +437,7 @@ class TestVaultEditor(unittest.TestCase):
src_file_path = self._create_file(self._test_dir, 'src_file', content=src_contents)
ve = self._vault_editor()
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'please use .edit. instead',
ve.create_file,
src_file_path,
@ -449,7 +449,7 @@ class TestVaultEditor(unittest.TestCase):
src_file_path = self._create_file(self._test_dir, 'src_file', content=src_contents)
ve = self._vault_editor()
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
'input is not vault encrypted data',
ve.decrypt_file,
src_file_path)

@ -284,11 +284,11 @@ class TestAnsibleLoaderVault(unittest.TestCase, YamlTestUtils):
different_vault_string = data_from_yaml['different_secret']
self.assertEqual(vault_string, another_vault_string)
self.assertNotEquals(vault_string, different_vault_string)
self.assertNotEqual(vault_string, different_vault_string)
# More testing of __eq__/__ne__
self.assertTrue('some string' != vault_string)
self.assertNotEquals('some string', vault_string)
self.assertNotEqual('some string', vault_string)
# Note this is a compare of the str/unicode of these, they are different types
# so we want to test self == other, and other == self etc

@ -52,7 +52,7 @@ class TestAnsibleVaultUnicodeNoVault(unittest.TestCase, YamlTestUtils):
self.assertIsInstance(avu, objects.AnsibleVaultEncryptedUnicode)
self.assertTrue(avu.vault is None)
# AnsibleVaultEncryptedUnicode without a vault should never == any string
self.assertNotEquals(avu, seq)
self.assertNotEqual(avu, seq)
def assert_values(self, seq):
avu = objects.AnsibleVaultEncryptedUnicode(seq)

@ -480,7 +480,7 @@ class TestBaseSubClass(TestBase):
def test_attr_dict_string(self):
test_value = 'just_some_random_string'
ds = {'test_attr_dict': test_value}
self.assertRaisesRegexp(AnsibleParserError, 'is not a dictionary', self._base_validate, ds)
self.assertRaisesRegex(AnsibleParserError, 'is not a dictionary', self._base_validate, ds)
def test_attr_class(self):
esc = ExampleSubClass()
@ -503,13 +503,13 @@ class TestBaseSubClass(TestBase):
def test_attr_class_post_validate_class_not_instance(self):
not_a_esc = ExampleSubClass
ds = {'test_attr_class_post_validate': not_a_esc}
self.assertRaisesRegexp(AnsibleParserError, 'is not a valid.*got a.*Meta.*instead',
self.assertRaisesRegex(AnsibleParserError, 'is not a valid.*got a.*Meta.*instead',
self._base_validate, ds)
def test_attr_class_post_validate_wrong_class(self):
not_a_esc = 37
ds = {'test_attr_class_post_validate': not_a_esc}
self.assertRaisesRegexp(AnsibleParserError, 'is not a valid.*got a.*int.*instead',
self.assertRaisesRegex(AnsibleParserError, 'is not a valid.*got a.*int.*instead',
self._base_validate, ds)
def test_attr_remote_user(self):
@ -599,7 +599,7 @@ class TestBaseSubClass(TestBase):
bsc.load_data(ds)
fake_loader = DictDataLoader({})
templar = Templar(loader=fake_loader)
self.assertRaisesRegexp(AnsibleParserError, 'cannot have empty values',
self.assertRaisesRegex(AnsibleParserError, 'cannot have empty values',
bsc.post_validate, templar)
def test_attr_unknown(self):

@ -50,7 +50,7 @@ class TestConditional(unittest.TestCase):
def test_undefined(self):
when = [u"{{ some_undefined_thing }}"]
self.assertRaisesRegexp(errors.AnsibleError, "The conditional check '{{ some_undefined_thing }}' failed",
self.assertRaisesRegex(errors.AnsibleError, "The conditional check '{{ some_undefined_thing }}' failed",
self._eval_con, when, {})
def test_defined(self):
@ -100,7 +100,7 @@ class TestConditional(unittest.TestCase):
when = [u"some_dict.some_dict_key1 == hostvars['host3']"]
# self._eval_con(when, variables)
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
r"The conditional check 'some_dict.some_dict_key1 == hostvars\['host3'\]' failed",
# "The conditional check 'some_dict.some_dict_key1 == hostvars['host3']' failed",
# "The conditional check 'some_dict.some_dict_key1 == hostvars['host3']' failed.",
@ -116,7 +116,7 @@ class TestConditional(unittest.TestCase):
# raises an exception when a non-string conditional is passed to extract_defined_undefined()
when = [u"some_defined_dict_with_undefined_values"]
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
"The conditional check 'some_defined_dict_with_undefined_values' failed.",
self._eval_con,
when, variables)
@ -129,7 +129,7 @@ class TestConditional(unittest.TestCase):
}}
when = [u"some_defined_dict_with_undefined_values is defined"]
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
"The conditional check 'some_defined_dict_with_undefined_values is defined' failed.",
self._eval_con,
when, variables)
@ -195,7 +195,7 @@ class TestConditional(unittest.TestCase):
u'hostvars["some_host"] is defined',
u"{{ compare_targets.triple }} is defined",
u"{{ compare_targets.quadruple }} is defined"]
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
"The conditional check '{{ compare_targets.triple }} is defined' failed",
self._eval_con,
when, variables)

@ -107,7 +107,7 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks):
def test_empty_task(self):
ds = [{}]
self.assertRaisesRegexp(errors.AnsibleParserError,
self.assertRaisesRegex(errors.AnsibleParserError,
"no module/action detected in task",
helpers.load_list_of_tasks,
ds, play=self.mock_play,
@ -115,7 +115,7 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks):
def test_empty_task_use_handlers(self):
ds = [{}]
self.assertRaisesRegexp(errors.AnsibleParserError,
self.assertRaisesRegex(errors.AnsibleParserError,
"no module/action detected in task.",
helpers.load_list_of_tasks,
ds,
@ -126,7 +126,7 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks):
def test_one_bogus_block(self):
ds = [{'block': None}]
self.assertRaisesRegexp(errors.AnsibleParserError,
self.assertRaisesRegex(errors.AnsibleParserError,
"A malformed block was encountered",
helpers.load_list_of_tasks,
ds, play=self.mock_play,
@ -172,7 +172,7 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks):
def test_one_bogus_block_use_handlers(self):
ds = [{'block': True}]
self.assertRaisesRegexp(errors.AnsibleParserError,
self.assertRaisesRegex(errors.AnsibleParserError,
"A malformed block was encountered",
helpers.load_list_of_tasks,
ds, play=self.mock_play, use_handlers=True,
@ -320,7 +320,7 @@ class TestLoadListOfRoles(unittest.TestCase, MixinForMocks):
def test_empty_role(self):
ds = [{}]
self.assertRaisesRegexp(errors.AnsibleError,
self.assertRaisesRegex(errors.AnsibleError,
"role definitions must contain a role name",
helpers.load_list_of_roles,
ds, self.mock_play,
@ -359,7 +359,7 @@ class TestLoadListOfBlocks(unittest.TestCase, MixinForMocks):
def test_empty_block(self):
ds = [{}]
mock_play = MagicMock(name='MockPlay')
self.assertRaisesRegexp(errors.AnsibleParserError,
self.assertRaisesRegex(errors.AnsibleParserError,
"no module/action detected in task",
helpers.load_list_of_blocks,
ds, mock_play,

@ -346,7 +346,7 @@ class TestActionBase(unittest.TestCase):
self.assertEqual(runWithNoExpectation(execute), remote_paths)
def assertThrowRegex(regex, execute=False):
self.assertRaisesRegexp(
self.assertRaisesRegex(
AnsibleError,
regex,
action_base._fixup_perms2,

@ -185,7 +185,7 @@ class TestFactCache(unittest.TestCase):
# See https://github.com/ansible/ansible/issues/18751
# Note no fact_connection config set, so this will fail
with mock.patch('ansible.constants.CACHE_PLUGIN', 'json'):
self.assertRaisesRegexp(AnsibleError,
self.assertRaisesRegex(AnsibleError,
"Unable to load the facts cache plugin.*json.*",
FactCache)

@ -56,7 +56,7 @@ class TestCallback(unittest.TestCase):
def test_host_label(self):
result = TaskResult(host=Host('host1'), task=mock_task, return_data={})
self.assertEquals(CallbackBase.host_label(result), 'host1')
self.assertEqual(CallbackBase.host_label(result), 'host1')
def test_host_label_delegated(self):
mock_task.delegate_to = 'host2'
@ -65,7 +65,7 @@ class TestCallback(unittest.TestCase):
task=mock_task,
return_data={'_ansible_delegated_vars': {'ansible_host': 'host2'}},
)
self.assertEquals(CallbackBase.host_label(result), 'host1 -> host2')
self.assertEqual(CallbackBase.host_label(result), 'host1 -> host2')
# TODO: import callback module so we can patch callback.cli/callback.C

@ -219,7 +219,7 @@ class TestTemplarTemplate(BaseTemplar, unittest.TestCase):
def test_weird(self):
data = u'''1 2 #}huh{# %}ddfg{% }}dfdfg{{ {%what%} {{#foo#}} {%{bar}%} {#%blip%#} {{asdfsd%} 3 4 {{foo}} 5 6 7'''
self.assertRaisesRegexp(AnsibleError,
self.assertRaisesRegex(AnsibleError,
'template error while templating string',
self.templar.template,
data)
@ -297,7 +297,7 @@ class TestTemplarMisc(BaseTemplar, unittest.TestCase):
class TestTemplarLookup(BaseTemplar, unittest.TestCase):
def test_lookup_missing_plugin(self):
self.assertRaisesRegexp(AnsibleError,
self.assertRaisesRegex(AnsibleError,
r'lookup plugin \(not_a_real_lookup_plugin\) not found',
self.templar._lookup,
'not_a_real_lookup_plugin',
@ -308,7 +308,7 @@ class TestTemplarLookup(BaseTemplar, unittest.TestCase):
self.assertEqual(res, 'an_arg,another_arg')
def test_lookup_jinja_undefined(self):
self.assertRaisesRegexp(AnsibleUndefinedVariable,
self.assertRaisesRegex(AnsibleUndefinedVariable,
"'an_undefined_jinja_var' is undefined",
self.templar._lookup,
'list', '{{ an_undefined_jinja_var }}')
@ -319,14 +319,14 @@ class TestTemplarLookup(BaseTemplar, unittest.TestCase):
# self.assertIsInstance(res, AnsibleUnsafe)
def test_lookup_jinja_dict_string_passed(self):
self.assertRaisesRegexp(AnsibleError,
self.assertRaisesRegex(AnsibleError,
"with_dict expects a dict",
self.templar._lookup,
'dict',
'{{ some_var }}')
def test_lookup_jinja_dict_list_passed(self):
self.assertRaisesRegexp(AnsibleError,
self.assertRaisesRegex(AnsibleError,
"with_dict expects a dict",
self.templar._lookup,
'dict',
@ -342,7 +342,7 @@ class TestTemplarLookup(BaseTemplar, unittest.TestCase):
self.assertEqual(res, ["blip"])
def test_lookup_jinja_list_wantlist_undefined(self):
self.assertRaisesRegexp(AnsibleUndefinedVariable,
self.assertRaisesRegex(AnsibleUndefinedVariable,
"'some_undefined_var' is undefined",
self.templar._lookup,
'list',

Loading…
Cancel
Save