test_decorators.py 3.8 KB

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