mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9838)
Make set_module_args() a context manager, and remove copies of set_module_args(). Prepares for Data Tagging.
This commit is contained in:
parent
402f725424
commit
a1781d09dd
84 changed files with 4043 additions and 4302 deletions
|
@ -55,14 +55,13 @@ class TestGem(ModuleTestCase):
|
|||
return self.mocker.patch(target)
|
||||
|
||||
def test_fails_when_user_install_and_install_dir_are_combined(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'name': 'dummy',
|
||||
'user_install': True,
|
||||
'install_dir': '/opt/dummy',
|
||||
})
|
||||
|
||||
with pytest.raises(AnsibleFailJson) as exc:
|
||||
gem.main()
|
||||
}):
|
||||
with pytest.raises(AnsibleFailJson) as exc:
|
||||
gem.main()
|
||||
|
||||
result = exc.value.args[0]
|
||||
assert result['failed']
|
||||
|
@ -75,18 +74,17 @@ class TestGem(ModuleTestCase):
|
|||
# test mocks. The only thing that matters is the assertion that this 'gem install' is
|
||||
# invoked with '--install-dir'.
|
||||
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'name': 'dummy',
|
||||
'user_install': False,
|
||||
'install_dir': '/opt/dummy',
|
||||
})
|
||||
}):
|
||||
self.patch_rubygems_version()
|
||||
self.patch_installed_versions([])
|
||||
run_command = self.patch_run_command()
|
||||
|
||||
self.patch_rubygems_version()
|
||||
self.patch_installed_versions([])
|
||||
run_command = self.patch_run_command()
|
||||
|
||||
with pytest.raises(AnsibleExitJson) as exc:
|
||||
gem.main()
|
||||
with pytest.raises(AnsibleExitJson) as exc:
|
||||
gem.main()
|
||||
|
||||
result = exc.value.args[0]
|
||||
assert result['changed']
|
||||
|
@ -98,20 +96,19 @@ class TestGem(ModuleTestCase):
|
|||
# XXX: This test is also extremely fragile because of mocking.
|
||||
# If this breaks, the only that matters is to check whether '--install-dir' is
|
||||
# in the run command, and that GEM_HOME is passed to the command.
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'name': 'dummy',
|
||||
'user_install': False,
|
||||
'install_dir': '/opt/dummy',
|
||||
'state': 'absent',
|
||||
})
|
||||
}):
|
||||
self.patch_rubygems_version()
|
||||
self.patch_installed_versions(['1.0.0'])
|
||||
|
||||
self.patch_rubygems_version()
|
||||
self.patch_installed_versions(['1.0.0'])
|
||||
run_command = self.patch_run_command()
|
||||
|
||||
run_command = self.patch_run_command()
|
||||
|
||||
with pytest.raises(AnsibleExitJson) as exc:
|
||||
gem.main()
|
||||
with pytest.raises(AnsibleExitJson) as exc:
|
||||
gem.main()
|
||||
|
||||
result = exc.value.args[0]
|
||||
|
||||
|
@ -124,17 +121,16 @@ class TestGem(ModuleTestCase):
|
|||
assert update_environ.get('GEM_HOME') == '/opt/dummy'
|
||||
|
||||
def test_passes_add_force_option(self):
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'name': 'dummy',
|
||||
'force': True,
|
||||
})
|
||||
}):
|
||||
self.patch_rubygems_version()
|
||||
self.patch_installed_versions([])
|
||||
run_command = self.patch_run_command()
|
||||
|
||||
self.patch_rubygems_version()
|
||||
self.patch_installed_versions([])
|
||||
run_command = self.patch_run_command()
|
||||
|
||||
with pytest.raises(AnsibleExitJson) as exc:
|
||||
gem.main()
|
||||
with pytest.raises(AnsibleExitJson) as exc:
|
||||
gem.main()
|
||||
|
||||
result = exc.value.args[0]
|
||||
assert result['changed']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue