Exemple #1
0
    def test_stores_exception(self):
        exception_raised = Exception('intentional')

        def boom():
            raise exception_raised

        sut = TimeController(target=boom, daemon=True)
        sut.start()
        sut.join()
        expect(sut.exception_caught).to(equal(exception_raised))
 def test_expires_after_timeout(self):
     timeout = 1
     self.context.set_env(browserstack_tunnel_timeout=timeout)
     e = WebDriverException(ERROR_MESSAGE)
     self.fake_webdriver.init_exception = e
     clock = TimeController(target=Browser, parent_context=self.context)
     clock.start()
     sleep(0.05)  # Give the SUT a chance to start
     clock.advance(seconds=timeout + 0.01)
     clock.join()
     expect(clock.exception_caught).to(equal(e))
 def test_waits_up_to_configured_limit(self):
     self.webdriver.Remote = func_that_raises(AllBrowsersBusy())
     ctl = TimeController(target=Browser, parent_context=self.context)
     ctl.start()
     sleep(0.05)
     ctl.advance(seconds=self.timeout - 0.01)
     sleep(0.05)
     try:
         expect(ctl.exception_caught).to(equal(None))
     finally:
         ctl.advance(days=180)
         ctl.join()
 def test_re_raises_after_timeout(self):
     raised = AllBrowsersBusy()
     self.webdriver.Remote = func_that_raises(raised)
     ctl = TimeController(target=Browser, parent_context=self.context)
     ctl.start()
     sleep(0.05)
     ctl.advance(seconds=self.timeout + 0.01)
     sleep(0.05)
     try:
         expect(ctl.exception_caught).to(equal(raised))
     finally:
         ctl.advance(days=180)
         ctl.join()
Exemple #5
0
    def test_waits_up_to_timeout_for_element_to_appear(self):
        timeout = 42

        def find():
            return self.sut.find_unique_element(id="whatever", timeout=timeout)

        clock = TimeController(target=find)
        clock.start()
        clock.advance(seconds=timeout - 0.001)
        element = object()
        self.fake.elements = [element]
        clock.join()
        expect(clock.exception_caught).to(equal(None))
        expect(clock.value_returned).to(equal(element))
Exemple #6
0
 def test_time_controller(self):
     real_spam = 'real SPAM'
     fake_spam = 'phoney balogna'
     parent = open_dependency_context()
     try:
         parent.inject(real_spam, fake_spam)
         tc = TimeController(target=lambda: dependency(real_spam),
                             parent_context=parent)
         tc.start()
         tc.join()
     finally:
         parent.close()
     if tc.exception_caught:
         raise tc.exception_caught
     expect(tc.value_returned).to(equal(fake_spam))
Exemple #7
0
 def test_stores_return_value(self):
     expected = 42
     sut = TimeController(target=lambda: expected, daemon=True)
     sut.start()
     sut.join()
     expect(sut.value_returned).to(equal(expected))