test_waiter.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import unittest.mock as mock
  7. import unittest
  8. import time
  9. import pytest
  10. import ly_test_tools.environment.waiter
  11. pytestmark = pytest.mark.SUITE_smoke
  12. @mock.patch('time.sleep', mock.MagicMock)
  13. class TestWaitFor(unittest.TestCase):
  14. def test_WaitForFunctionCall_GivenExceptionTimeoutExceeded_RaiseException(self):
  15. input_func = mock.MagicMock()
  16. input_func.return_value = False
  17. with self.assertRaises(Exception):
  18. ly_test_tools.environment.waiter.wait_for(input_func, .001, Exception, 0)
  19. def test_WaitForFunctionCall_TimeoutExceeded_RaiseAssertionError(self):
  20. input_func = mock.MagicMock()
  21. input_func.return_value = False
  22. with self.assertRaises(Exception):
  23. ly_test_tools.environment.waiter.wait_for(input_func, .001, interval=0)
  24. def test_WaitForFunctionCall_TimeoutExceeded_EnoughTime(self):
  25. input_func = mock.MagicMock()
  26. input_func.return_value = False
  27. timeout_end = time.time() + 0.1
  28. try:
  29. ly_test_tools.environment.waiter.wait_for(input_func, 0.1, Exception, interval=0.01)
  30. except Exception:
  31. pass
  32. # It should have taken at least 1/10 second
  33. assert time.time() > timeout_end