test_decorators.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. from tests.support.case import ModuleCase
  5. @pytest.mark.windows_whitelisted
  6. class DecoratorTest(ModuleCase):
  7. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  8. def test_module(self):
  9. self.assertTrue(self.run_function("runtests_decorators.working_function"))
  10. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  11. def test_depends(self):
  12. ret = self.run_function("runtests_decorators.depends")
  13. self.assertTrue(isinstance(ret, dict))
  14. self.assertTrue(ret["ret"])
  15. self.assertTrue(isinstance(ret["time"], float))
  16. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  17. def test_missing_depends(self):
  18. self.assertEqual(
  19. {
  20. "runtests_decorators.missing_depends_will_fallback": None,
  21. "runtests_decorators.missing_depends": "'runtests_decorators.missing_depends' is not available.",
  22. },
  23. self.run_function("runtests_decorators.missing_depends"),
  24. )
  25. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  26. def test_bool_depends(self):
  27. # test True
  28. self.assertTrue(self.run_function("runtests_decorators.booldependsTrue"))
  29. # test False
  30. self.assertIn(
  31. "is not available",
  32. self.run_function("runtests_decorators.booldependsFalse"),
  33. )
  34. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  35. def test_depends_will_not_fallback(self):
  36. ret = self.run_function("runtests_decorators.depends_will_not_fallback")
  37. self.assertTrue(isinstance(ret, dict))
  38. self.assertTrue(ret["ret"])
  39. self.assertTrue(isinstance(ret["time"], float))
  40. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  41. def test_missing_depends_will_fallback(self):
  42. self.assertListEqual(
  43. [False, "fallback"],
  44. self.run_function("runtests_decorators.missing_depends_will_fallback"),
  45. )
  46. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  47. def test_command_success_retcode(self):
  48. ret = self.run_function("runtests_decorators.command_success_retcode")
  49. self.assertIs(ret, True)
  50. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  51. def test_command_failure_retcode(self):
  52. ret = self.run_function("runtests_decorators.command_failure_retcode")
  53. self.assertEqual(
  54. ret, "'runtests_decorators.command_failure_retcode' is not available."
  55. )
  56. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  57. def test_command_success_nonzero_retcode_true(self):
  58. ret = self.run_function(
  59. "runtests_decorators.command_success_nonzero_retcode_true"
  60. )
  61. self.assertIs(ret, True)
  62. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  63. def test_command_failure_nonzero_retcode_true(self):
  64. ret = self.run_function(
  65. "runtests_decorators.command_failure_nonzero_retcode_true"
  66. )
  67. self.assertEqual(
  68. ret,
  69. "'runtests_decorators.command_failure_nonzero_retcode_true' is not available.",
  70. )
  71. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  72. def test_command_success_nonzero_retcode_false(self):
  73. ret = self.run_function(
  74. "runtests_decorators.command_success_nonzero_retcode_false"
  75. )
  76. self.assertIs(ret, True)
  77. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  78. def test_command_failure_nonzero_retcode_false(self):
  79. ret = self.run_function(
  80. "runtests_decorators.command_failure_nonzero_retcode_false"
  81. )
  82. self.assertEqual(
  83. ret,
  84. "'runtests_decorators.command_failure_nonzero_retcode_false' is not available.",
  85. )
  86. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  87. def test_versioned_depend_insufficient(self):
  88. self.assertIn(
  89. "is not available",
  90. self.run_function("runtests_decorators.version_depends_false"),
  91. )
  92. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  93. def test_versioned_depend_sufficient(self):
  94. self.assertTrue(self.run_function("runtests_decorators.version_depends_true"))
  95. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  96. def test_versioned_depend_versionless(self):
  97. self.assertTrue(
  98. self.run_function("runtests_decorators.version_depends_versionless_true")
  99. )