class WaitUntilTest(MarionetteTestCase): def setUp(self): super(WaitUntilTest, self).setUp() self.m = MockMarionette() self.clock = TickingClock() self.w = Wait(self.m, timeout=10, interval=1, clock=self.clock) def test_true(self): r = self.w.until(lambda x: x.true()) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_true_within_timeout(self): r = self.w.until(lambda x: x.true(wait=5)) self.assertTrue(r) self.assertEqual(self.clock.ticks, 4) def test_timeout(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.true(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_exception_raises_immediately(self): with self.assertRaises(TypeError): self.w.until(lambda x: x.exception(e=TypeError)) self.assertEqual(self.clock.ticks, 0) def test_ignored_exception(self): self.w.exceptions = (TypeError,) with self.assertRaises(errors.TimeoutException): self.w.until(lambda x: x.exception(e=TypeError)) def test_ignored_exception_wrapped_in_timeoutexception(self): self.w.exceptions = (TypeError,) exc = None try: self.w.until(lambda x: x.exception(e=TypeError)) except Exception as e: exc = e s = str(exc) self.assertIsNotNone(exc) self.assertIsInstance(exc, errors.TimeoutException) self.assertIn(", caused by %r" % TypeError, s) self.assertIn("self.w.until(lambda x: x.exception(e=TypeError))", s) def test_ignored_exception_after_timeout_is_not_raised(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.exception(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_keyboard_interrupt(self): with self.assertRaises(KeyboardInterrupt): self.w.until(lambda x: x.exception(e=KeyboardInterrupt)) def test_system_exit(self): with self.assertRaises(SystemExit): self.w.until(lambda x: x.exception(SystemExit)) def test_true_condition_returns_immediately(self): r = self.w.until(lambda x: x.true()) self.assertIsInstance(r, bool) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_value(self): r = self.w.until(lambda x: "foo") self.assertEqual(r, "foo") self.assertEqual(self.clock.ticks, 0) def test_custom_predicate(self): r = self.w.until(lambda x: x.true(wait=2), is_true=at_third_attempt) self.assertTrue(r) self.assertEqual(self.clock.ticks, 1) def test_custom_predicate_times_out(self): with self.assertRaises(errors.TimeoutException): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt) self.assertEqual(self.clock.ticks, 2) def test_timeout_elapsed_duration(self): with self.assertRaisesRegexp(errors.TimeoutException, "Timed out after 2 seconds"): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt) def test_message(self): self.w.exceptions = (TypeError,) exc = None try: self.w.until(lambda x: x.exception(e=TypeError), message="hooba") except errors.TimeoutException as e: exc = e result = str(exc) self.assertIn("seconds with message: hooba, caused by", result) def test_no_message(self): self.w.exceptions = (TypeError,) exc = None try: self.w.until(lambda x: x.exception(e=TypeError), message="") except errors.TimeoutException as e: exc = e result = str(exc) self.assertIn("seconds, caused by", result) def test_message_has_none_as_its_value(self): self.w.exceptions = (TypeError,) exc = None try: self.w.until(False, None, None) except errors.TimeoutException as e: exc = e result = str(exc) self.assertNotIn("with message:", result) self.assertNotIn("secondsNone", result)
class WaitUntilTest(MarionetteTestCase): def setUp(self): super(WaitUntilTest, self).setUp() self.m = MockMarionette() self.clock = TickingClock() self.w = Wait(self.m, timeout=10, interval=1, clock=self.clock) def test_true(self): r = self.w.until(lambda x: x.true()) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_true_within_timeout(self): r = self.w.until(lambda x: x.true(wait=5)) self.assertTrue(r) self.assertEqual(self.clock.ticks, 4) def test_timeout(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.true(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_exception_raises_immediately(self): with self.assertRaises(TypeError): self.w.until(lambda x: x.exception(e=TypeError)) self.assertEqual(self.clock.ticks, 0) def test_ignored_exception(self): self.w.exceptions = (TypeError, ) with self.assertRaises(errors.TimeoutException): self.w.until(lambda x: x.exception(e=TypeError)) def test_ignored_exception_wrapped_in_timeoutexception(self): self.w.exceptions = (TypeError, ) exc = None try: self.w.until(lambda x: x.exception(e=TypeError)) except Exception as e: exc = e s = str(exc) self.assertIsNotNone(exc) self.assertIsInstance(exc, errors.TimeoutException) self.assertIn(", caused by %r" % TypeError, s) self.assertIn("self.w.until(lambda x: x.exception(e=TypeError))", s) def test_ignored_exception_after_timeout_is_not_raised(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.exception(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_keyboard_interrupt(self): with self.assertRaises(KeyboardInterrupt): self.w.until(lambda x: x.exception(e=KeyboardInterrupt)) def test_system_exit(self): with self.assertRaises(SystemExit): self.w.until(lambda x: x.exception(SystemExit)) def test_true_condition_returns_immediately(self): r = self.w.until(lambda x: x.true()) self.assertIsInstance(r, bool) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_value(self): r = self.w.until(lambda x: "foo") self.assertEqual(r, "foo") self.assertEqual(self.clock.ticks, 0) def test_custom_predicate(self): r = self.w.until(lambda x: x.true(wait=2), is_true=at_third_attempt) self.assertTrue(r) self.assertEqual(self.clock.ticks, 1) def test_custom_predicate_times_out(self): with self.assertRaises(errors.TimeoutException): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt) self.assertEqual(self.clock.ticks, 2) def test_timeout_elapsed_duration(self): with self.assertRaisesRegexp(errors.TimeoutException, "Timed out after 2 seconds"): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt) def test_message(self): self.w.exceptions = (TypeError, ) exc = None try: self.w.until(lambda x: x.exception(e=TypeError), message="hooba") except errors.TimeoutException as e: exc = e result = str(exc) self.assertIn("seconds with message: hooba, caused by", result) def test_no_message(self): self.w.exceptions = (TypeError, ) exc = None try: self.w.until(lambda x: x.exception(e=TypeError), message="") except errors.TimeoutException as e: exc = e result = str(exc) self.assertIn("seconds, caused by", result) def test_message_has_none_as_its_value(self): self.w.exceptions = (TypeError, ) exc = None try: self.w.until(False, None, None) except errors.TimeoutException as e: exc = e result = str(exc) self.assertNotIn("with message:", result) self.assertNotIn("secondsNone", result)
class WaitUntilTest(MarionetteTestCase): def setUp(self): super(WaitUntilTest, self).setUp() self.m = MockMarionette() self.clock = TickingClock() self.w = Wait(self.m, timeout=10, interval=1, clock=self.clock) def test_true(self): r = self.w.until(lambda x: x.true()) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_true_within_timeout(self): r = self.w.until(lambda x: x.true(wait=5)) self.assertTrue(r) self.assertEqual(self.clock.ticks, 4) def test_timeout(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.true(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_exception_raises_immediately(self): with self.assertRaises(Exception): self.w.until(lambda x: x.exception()) self.assertEqual(self.clock.ticks, 0) def test_custom_ignored_exception(self): self.w.exceptions = self.w.exceptions + (Exception, ) with self.assertRaises(Exception): self.w.until(lambda x: x.exception(e=Exception)) def test_ignored_exception_after_timeout_is_not_raised(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.exception(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_keyboard_interrupt(self): with self.assertRaises(KeyboardInterrupt): self.w.until(lambda x: x.exception(e=KeyboardInterrupt)) def test_system_exit(self): with self.assertRaises(SystemExit): self.w.until(lambda x: x.exception(SystemExit)) def test_true_condition_returns_immediately(self): r = self.w.until(lambda x: x.true()) self.assertIsInstance(r, bool) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_value(self): r = self.w.until(lambda x: "foo") self.assertEqual(r, "foo") self.assertEqual(self.clock.ticks, 0) def test_custom_predicate(self): r = self.w.until(lambda x: x.true(wait=2), is_true=at_third_attempt) self.assertTrue(r) self.assertEqual(self.clock.ticks, 1) def test_custom_predicate_times_out(self): with self.assertRaises(errors.TimeoutException): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt) self.assertEqual(self.clock.ticks, 2) def test_timeout_elapsed_duration(self): with self.assertRaisesRegexp(errors.TimeoutException, "Timed out after 2 seconds"): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt)
class WaitUntilTest(MarionetteTestCase): def setUp(self): super(WaitUntilTest, self).setUp() self.m = MockMarionette() self.clock = TickingClock() self.w = Wait(self.m, timeout=10, interval=1, clock=self.clock) def test_true(self): r = self.w.until(lambda x: x.true()) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_true_within_timeout(self): r = self.w.until(lambda x: x.true(wait=5)) self.assertTrue(r) self.assertEqual(self.clock.ticks, 4) def test_timeout(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.true(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_exception_raises_immediately(self): with self.assertRaises(Exception): self.w.until(lambda x: x.exception()) self.assertEqual(self.clock.ticks, 0) def test_custom_ignored_exception(self): self.w.exceptions = self.w.exceptions + (Exception,) with self.assertRaises(Exception): self.w.until(lambda x: x.exception(e=Exception)) def test_ignored_exception_after_timeout_is_not_raised(self): with self.assertRaises(errors.TimeoutException): r = self.w.until(lambda x: x.exception(wait=15)) self.assertEqual(self.clock.ticks, 10) def test_keyboard_interrupt(self): with self.assertRaises(KeyboardInterrupt): self.w.until(lambda x: x.exception(e=KeyboardInterrupt)) def test_system_exit(self): with self.assertRaises(SystemExit): self.w.until(lambda x: x.exception(SystemExit)) def test_true_condition_returns_immediately(self): r = self.w.until(lambda x: x.true()) self.assertIsInstance(r, bool) self.assertTrue(r) self.assertEqual(self.clock.ticks, 0) def test_value(self): r = self.w.until(lambda x: "foo") self.assertEqual(r, "foo") self.assertEqual(self.clock.ticks, 0) def test_custom_predicate(self): r = self.w.until(lambda x: x.true(wait=2), is_true=at_third_attempt) self.assertTrue(r) self.assertEqual(self.clock.ticks, 1) def test_custom_predicate_times_out(self): with self.assertRaises(errors.TimeoutException): self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt) self.assertEqual(self.clock.ticks, 2)
def test_timeout_elapsed_rounding(self): wt = Wait(self.m, clock=SequenceClock([1, 0.01, 1]), timeout=0) with self.assertRaisesRegexp(errors.TimeoutException, "Timed out after 1.0 seconds"): wt.until(lambda x: x.true(), is_true=now)