mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
3016999c04
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.
24 lines
853 B
Python
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'))
|
|
|