test_decorators.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.case import ModuleCase
  6. class DecoratorTest(ModuleCase):
  7. def test_module(self):
  8. self.assertTrue(
  9. self.run_function(
  10. 'runtests_decorators.working_function'
  11. )
  12. )
  13. def test_depends(self):
  14. ret = self.run_function('runtests_decorators.depends')
  15. self.assertTrue(isinstance(ret, dict))
  16. self.assertTrue(ret['ret'])
  17. self.assertTrue(isinstance(ret['time'], float))
  18. def test_missing_depends(self):
  19. self.assertEqual(
  20. {'runtests_decorators.missing_depends_will_fallback': '\n CLI Example:\n\n ',
  21. 'runtests_decorators.missing_depends': "'runtests_decorators.missing_depends' is not available."},
  22. self.run_function('runtests_decorators.missing_depends'
  23. )
  24. )
  25. def test_bool_depends(self):
  26. # test True
  27. self.assertTrue(
  28. self.run_function(
  29. 'runtests_decorators.booldependsTrue'
  30. )
  31. )
  32. # test False
  33. self.assertIn(
  34. 'is not available',
  35. self.run_function('runtests_decorators.booldependsFalse'
  36. )
  37. )
  38. def test_depends_will_not_fallback(self):
  39. ret = self.run_function('runtests_decorators.depends_will_not_fallback')
  40. self.assertTrue(isinstance(ret, dict))
  41. self.assertTrue(ret['ret'])
  42. self.assertTrue(isinstance(ret['time'], float))
  43. def test_missing_depends_will_fallback(self):
  44. self.assertListEqual(
  45. [False, 'fallback'],
  46. self.run_function(
  47. 'runtests_decorators.missing_depends_will_fallback'
  48. )
  49. )