Ejemplo n.º 1
0
 def test_wait_until_with_optional_message(self):
     try:
         wait_until(lambda: False, message="test custom message")
     except OperationTimeoutError as e:
         self.assertIn(
             "test custom message", e.message,
             "Custom message should be in raised exception's message text.")
Ejemplo n.º 2
0
    def test_wait_until_returnsAfterConditionsMet(self):
        "Test wait until condition=true works."
        # create a condition that returns true after 2 seconds.
        end_time = datetime.now() + timedelta(seconds=2)
        too_long = end_time + timedelta(seconds=2)
        condition = lambda: datetime.now() > end_time

        wait_until(condition, 4, 0.5)
        self.assertLess(datetime.now(), too_long)
Ejemplo n.º 3
0
    def test_wait_until_returnsAfterConditionsMet(self):
        "Test wait until condition=true works."
        # create a condition that returns true after 2 seconds.
        end_time = datetime.now() + timedelta(seconds=2)
        too_long = end_time + timedelta(seconds=2)
        condition = lambda: datetime.now() > end_time

        wait_until(condition, 4, 0.5)
        self.assertLess(datetime.now(), too_long)
Ejemplo n.º 4
0
 def test_wait_until_with_pass_exception_option(self):
     condition = lambda: 1 / 0
     try:
         wait_until(condition, pass_exceptions=True)
         raise Exception("Test Failed, exception should be thrown.")
     except ZeroDivisionError:
         # Means the error was passed through as expected.
         pass
     except Exception as e:
         # Means we got the wrong error.
         raise e
Ejemplo n.º 5
0
 def test_wait_until_with_pass_exception_option(self):
     condition = lambda: 1 / 0
     try:
         wait_until(condition, pass_exceptions=True)
         raise Exception("Test Failed, exception should be thrown.")
     except ZeroDivisionError:
         # Means the error was passed through as expected.
         pass
     except Exception as e:
         # Means we got the wrong error.
         raise e
Ejemplo n.º 6
0
 def test_wait_until_raisesErrorIfTimedOut(self):
     "Test that wait timeout throws error after timeout period."
     # create a condition that returns true after 2 seconds.
     not_long_enough = datetime.now() + timedelta(seconds=.2)
     too_long = not_long_enough + timedelta(seconds=2)
     condition = lambda: False
     try:
         wait_until(condition, 1, 0.5)
     except OperationTimeoutError:
         now = datetime.now()
         self.assertGreater(now, not_long_enough)
         self.assertLess(now, too_long)
     except:
         self.fail("OperationTimeoutError expected.")
Ejemplo n.º 7
0
 def test_wait_until_raisesErrorIfTimedOut(self):
     "Test that wait timeout throws error after timeout period."
     # create a condition that returns true after 2 seconds.
     not_long_enough = datetime.now() + timedelta(seconds=.2)
     too_long = not_long_enough + timedelta(seconds=2)
     condition = lambda: False
     try:
         wait_until(condition, 1, 0.5)
     except OperationTimeoutError:
         now = datetime.now()
         self.assertGreater(now, not_long_enough)
         self.assertLess(now, too_long)
     except:
         self.fail("OperationTimeoutError expected.")
Ejemplo n.º 8
0
 def test_wait_until_with_optional_message(self):
     try:
         wait_until(lambda: False, message="test custom message")
     except OperationTimeoutError as e:
         self.assertIn("test custom message", e.message,
                       "Custom message should be in raised exception's message text.")