salt/tests/integration/modules/decorators.py
Thomas Jackson 3016999c04 Adding "Depends" decorator to salt.utils
The Depends decorator allows you to optionally remove functions if sepecific globals/modules don't exist. This is particuarly helpful in larger scale deployments where some functions of the module work everywhere, but others require (for example) a service to be installed. This way you can avoid having to try/except all over the module to only load certain functions etc.
2013-06-14 15:17:06 -07:00

24 lines
853 B
Python

import integration
class DecoratorTest(integration.ModuleCase):
def test_module(self):
self.assertTrue(self.run_function('runtests_decorators.working_function'))
def test_depends(self):
ret_val, time = self.run_function('runtests_decorators.depends')
self.assertTrue(ret_val)
self.assertTrue(type(time) == float)
def test_missing_depends(self):
self.assertTrue('is not available' in self.run_function('runtests_decorators.missing_depends'))
def test_depends_will_fallback(self):
ret_val, time = self.run_function('runtests_decorators.depends_will_fallback')
self.assertTrue(ret_val)
self.assertTrue(type(time) == float)
def test_missing_depends(self):
self.assertTrue('fallback' in self.run_function('runtests_decorators.missing_depends_will_fallback'))